function Argv(e,n){function t(e){a.showHelp();e&&console.error(e);process.exit(1)}function r(e){var n=minimist(e,i);n.$0=a.$0;c._&&n._.length<c._&&t("Not enough non-option arguments: got "+n._.length+", need at least "+c._);var r=[];Object.keys(c).forEach(function(e){n[e]||r.push(e)});r.length&&t("Missing required arguments: "+r.join(", "));u.forEach(function(e){try{e(n)===!1&&t("Argument check failed: "+e.toString())}catch(r){t(r)}});return n}function o(e){return Math.max.apply(null,e.map(function(e){return e.length}))}var a={};n||(n=process.cwd());a.$0=process.argv.slice(0,2).map(function(e){var t=rebase(n,e);return e.match(/^\//)&&t.length<e.length?t:e}).join(" ");void 0!=process.env._&&process.argv[1]==process.env._&&(a.$0=process.env._.replace(path.dirname(process.execPath)+"/",""));var i={"boolean":[],string:[],alias:{},"default":[]};a["boolean"]=function(e){i["boolean"].push.apply(i["boolean"],[].concat(e));return a};a.string=function(e){i.string.push.apply(i.string,[].concat(e));return a};a["default"]=function(e,n){"object"==typeof e?Object.keys(e).forEach(function(n){a["default"](n,e[n])}):i["default"][e]=n;return a};a.alias=function(e,n){"object"==typeof e?Object.keys(e).forEach(function(n){a.alias(n,e[n])}):i.alias[e]=(i.alias[e]||[]).concat(n);return a};var c={};a.demand=function(e){if("number"==typeof e){c._||(c._=0);c._+=e}else Array.isArray(e)?e.forEach(function(e){a.demand(e)}):c[e]=!0;return a};var s;a.usage=function(e,n){if(!n&&"object"==typeof e){n=e;e=null}s=e;n&&a.options(n);return a};var u=[];a.check=function(e){u.push(e);return a};var l={};a.describe=function(e,n){"object"==typeof e?Object.keys(e).forEach(function(n){a.describe(n,e[n])}):l[e]=n;return a};a.parse=function(e){return r(e)};a.option=a.options=function(e,n){if("object"==typeof e)Object.keys(e).forEach(function(n){a.options(n,e[n])});else{n.alias&&a.alias(e,n.alias);n.demand&&a.demand(e);"undefined"!=typeof n["default"]&&a["default"](e,n["default"]);(n["boolean"]||"boolean"===n.type)&&a["boolean"](e);(n.string||"string"===n.type)&&a.string(e);var t=n.describe||n.description||n.desc;t&&a.describe(e,t)}return a};var f=null;a.wrap=function(e){f=e;return a};a.showHelp=function(e){e||(e=console.error);e(a.help())};a.help=function(){var e=Object.keys(Object.keys(l).concat(Object.keys(c)).concat(Object.keys(i["default"])).reduce(function(e,n){"_"!==n&&(e[n]=!0);return e},{})),n=e.length?["Options:"]:[];s&&n.unshift(s.replace(/\$0/g,a.$0),"");var t=e.reduce(function(e,n){e[n]=[n].concat(i.alias[n]||[]).map(function(e){return(e.length>1?"--":"-")+e}).join(", ");return e},{}),r=o(Object.keys(t).map(function(e){return t[e]||""})),u=o(Object.keys(l).map(function(e){return l[e]||""}));e.forEach(function(e){var o=t[e],a=l[e]||"";f&&(a=wordwrap(r+4,f)(a).slice(r+4));var s=new Array(Math.max(r-o.length+3,0)).join(" "),p=new Array(Math.max(u-a.length+1,0)).join(" "),h=null;i["boolean"][e]&&(h="[boolean]");i.string[e]&&(h="[string]");!f&&p.length>0&&(a+=p);var g="  "+o+s,d=[h,c[e]?"[required]":null,void 0!==i["default"][e]?"[default: "+JSON.stringify(i["default"][e])+"]":null].filter(Boolean).join("  "),b=[a,d].filter(Boolean).join("  ");if(f){var v=a.split("\n"),y=v.slice(-1)[0].length+(1===v.length?g.length:0);b=a+(y+d.length>f-2?"\n"+new Array(f-d.length+1).join(" ")+d:new Array(f-d.length-y+1).join(" ")+d)}n.push(g+b)});n.push("");return n.join("\n")};Object.defineProperty(a,"argv",{get:function(){return r(e)},enumerable:!0});return a}function rebase(e,n){for(var t=path.normalize(n).split("/").slice(1),r=path.normalize(e).split("/").slice(1),o=0;t[o]&&t[o]==r[o];o++);t.splice(0,o);r.splice(0,o);var a=path.normalize(r.map(function(){return".."}).concat(t).join("/")).replace(/\/$/,"").replace(/^$/,".");return a.match(/^[.\/]/)?a:"./"+a}var path=require("path"),minimist=require("minimist"),wordwrap=require("wordwrap"),inst=Argv(process.argv.slice(2));Object.keys(inst).forEach(function(e){Argv[e]="function"==typeof inst[e]?inst[e].bind(inst):inst[e]});var exports=module.exports=Argv;exports.rebase=rebase;