@chneau/x 0.0.155 → 0.0.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/xx +27 -1
package/package.json
CHANGED
package/xx
CHANGED
|
@@ -1,2 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
1
2
|
// @bun
|
|
2
|
-
|
|
3
|
+
var t=Object.create;var{getPrototypeOf:n,defineProperty:A,getOwnPropertyNames:a}=Object;var o=Object.prototype.hasOwnProperty;var e=(q,$,z)=>{z=q!=null?t(n(q)):{};let G=$||!q||!q.__esModule?A(z,"default",{value:q,enumerable:!0}):z;for(let J of a(q))if(!o.call(G,J))A(G,J,{get:()=>q[J],enumerable:!0});return G};var M=(q,$)=>()=>($||q(($={exports:{}}).exports,$),$.exports);var H=import.meta.require;var L=M((qq)=>{class W extends Error{constructor(q,$,z){super(z);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=$,this.exitCode=q,this.nestedError=void 0}}class w extends W{constructor(q){super(1,"commander.invalidArgument",q);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}qq.CommanderError=W;qq.InvalidArgumentError=w});var K=M((Qq)=>{var{InvalidArgumentError:Gq}=L();class k{constructor(q,$){switch(this.description=$||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,q[0]){case"<":this.required=!0,this._name=q.slice(1,-1);break;case"[":this.required=!1,this._name=q.slice(1,-1);break;default:this.required=!0,this._name=q;break}if(this._name.length>3&&this._name.slice(-3)==="...")this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_concatValue(q,$){if($===this.defaultValue||!Array.isArray($))return[q];return $.concat(q)}default(q,$){return this.defaultValue=q,this.defaultValueDescription=$,this}argParser(q){return this.parseArg=q,this}choices(q){return this.argChoices=q.slice(),this.parseArg=($,z)=>{if(!this.argChoices.includes($))throw new Gq(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue($,z);return $},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function Jq(q){let $=q.name()+(q.variadic===!0?"...":"");return q.required?"<"+$+">":"["+$+"]"}Qq.Argument=k;Qq.humanReadableArgName=Jq});var j=M((_q)=>{var{humanReadableArgName:Zq}=K();class C{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(q){this.helpWidth=this.helpWidth??q.helpWidth??80}visibleCommands(q){let $=q.commands.filter((G)=>!G._hidden),z=q._getHelpCommand();if(z&&!z._hidden)$.push(z);if(this.sortSubcommands)$.sort((G,J)=>{return G.name().localeCompare(J.name())});return $}compareOptions(q,$){let z=(G)=>{return G.short?G.short.replace(/^-/,""):G.long.replace(/^--/,"")};return z(q).localeCompare(z($))}visibleOptions(q){let $=q.options.filter((G)=>!G.hidden),z=q._getHelpOption();if(z&&!z.hidden){let G=z.short&&q._findOption(z.short),J=z.long&&q._findOption(z.long);if(!G&&!J)$.push(z);else if(z.long&&!J)$.push(q.createOption(z.long,z.description));else if(z.short&&!G)$.push(q.createOption(z.short,z.description))}if(this.sortOptions)$.sort(this.compareOptions);return $}visibleGlobalOptions(q){if(!this.showGlobalOptions)return[];let $=[];for(let z=q.parent;z;z=z.parent){let G=z.options.filter((J)=>!J.hidden);$.push(...G)}if(this.sortOptions)$.sort(this.compareOptions);return $}visibleArguments(q){if(q._argsDescription)q.registeredArguments.forEach(($)=>{$.description=$.description||q._argsDescription[$.name()]||""});if(q.registeredArguments.find(($)=>$.description))return q.registeredArguments;return[]}subcommandTerm(q){let $=q.registeredArguments.map((z)=>Zq(z)).join(" ");return q._name+(q._aliases[0]?"|"+q._aliases[0]:"")+(q.options.length?" [options]":"")+($?" "+$:"")}optionTerm(q){return q.flags}argumentTerm(q){return q.name()}longestSubcommandTermLength(q,$){return $.visibleCommands(q).reduce((z,G)=>{return Math.max(z,this.displayWidth($.styleSubcommandTerm($.subcommandTerm(G))))},0)}longestOptionTermLength(q,$){return $.visibleOptions(q).reduce((z,G)=>{return Math.max(z,this.displayWidth($.styleOptionTerm($.optionTerm(G))))},0)}longestGlobalOptionTermLength(q,$){return $.visibleGlobalOptions(q).reduce((z,G)=>{return Math.max(z,this.displayWidth($.styleOptionTerm($.optionTerm(G))))},0)}longestArgumentTermLength(q,$){return $.visibleArguments(q).reduce((z,G)=>{return Math.max(z,this.displayWidth($.styleArgumentTerm($.argumentTerm(G))))},0)}commandUsage(q){let $=q._name;if(q._aliases[0])$=$+"|"+q._aliases[0];let z="";for(let G=q.parent;G;G=G.parent)z=G.name()+" "+z;return z+$+" "+q.usage()}commandDescription(q){return q.description()}subcommandDescription(q){return q.summary()||q.description()}optionDescription(q){let $=[];if(q.argChoices)$.push(`choices: ${q.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if(q.defaultValue!==void 0){if(q.required||q.optional||q.isBoolean()&&typeof q.defaultValue==="boolean")$.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`)}if(q.presetArg!==void 0&&q.optional)$.push(`preset: ${JSON.stringify(q.presetArg)}`);if(q.envVar!==void 0)$.push(`env: ${q.envVar}`);if($.length>0)return`${q.description} (${$.join(", ")})`;return q.description}argumentDescription(q){let $=[];if(q.argChoices)$.push(`choices: ${q.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if(q.defaultValue!==void 0)$.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`);if($.length>0){let z=`(${$.join(", ")})`;if(q.description)return`${q.description} ${z}`;return z}return q.description}formatHelp(q,$){let z=$.padWidth(q,$),G=$.helpWidth??80;function J(R,B){return $.formatItem(R,z,B,$)}let Q=[`${$.styleTitle("Usage:")} ${$.styleUsage($.commandUsage(q))}`,""],Y=$.commandDescription(q);if(Y.length>0)Q=Q.concat([$.boxWrap($.styleCommandDescription(Y),G),""]);let X=$.visibleArguments(q).map((R)=>{return J($.styleArgumentTerm($.argumentTerm(R)),$.styleArgumentDescription($.argumentDescription(R)))});if(X.length>0)Q=Q.concat([$.styleTitle("Arguments:"),...X,""]);let _=$.visibleOptions(q).map((R)=>{return J($.styleOptionTerm($.optionTerm(R)),$.styleOptionDescription($.optionDescription(R)))});if(_.length>0)Q=Q.concat([$.styleTitle("Options:"),..._,""]);if($.showGlobalOptions){let R=$.visibleGlobalOptions(q).map((B)=>{return J($.styleOptionTerm($.optionTerm(B)),$.styleOptionDescription($.optionDescription(B)))});if(R.length>0)Q=Q.concat([$.styleTitle("Global Options:"),...R,""])}let Z=$.visibleCommands(q).map((R)=>{return J($.styleSubcommandTerm($.subcommandTerm(R)),$.styleSubcommandDescription($.subcommandDescription(R)))});if(Z.length>0)Q=Q.concat([$.styleTitle("Commands:"),...Z,""]);return Q.join(`
|
|
4
|
+
`)}displayWidth(q){return x(q).length}styleTitle(q){return q}styleUsage(q){return q.split(" ").map(($)=>{if($==="[options]")return this.styleOptionText($);if($==="[command]")return this.styleSubcommandText($);if($[0]==="["||$[0]==="<")return this.styleArgumentText($);return this.styleCommandText($)}).join(" ")}styleCommandDescription(q){return this.styleDescriptionText(q)}styleOptionDescription(q){return this.styleDescriptionText(q)}styleSubcommandDescription(q){return this.styleDescriptionText(q)}styleArgumentDescription(q){return this.styleDescriptionText(q)}styleDescriptionText(q){return q}styleOptionTerm(q){return this.styleOptionText(q)}styleSubcommandTerm(q){return q.split(" ").map(($)=>{if($==="[options]")return this.styleOptionText($);if($[0]==="["||$[0]==="<")return this.styleArgumentText($);return this.styleSubcommandText($)}).join(" ")}styleArgumentTerm(q){return this.styleArgumentText(q)}styleOptionText(q){return q}styleArgumentText(q){return q}styleSubcommandText(q){return q}styleCommandText(q){return q}padWidth(q,$){return Math.max($.longestOptionTermLength(q,$),$.longestGlobalOptionTermLength(q,$),$.longestSubcommandTermLength(q,$),$.longestArgumentTermLength(q,$))}preformatted(q){return/\n[^\S\r\n]/.test(q)}formatItem(q,$,z,G){let Q=" ".repeat(2);if(!z)return Q+q;let Y=q.padEnd($+q.length-G.displayWidth(q)),X=2,Z=(this.helpWidth??80)-$-X-2,R;if(Z<this.minWidthToWrap||G.preformatted(z))R=z;else R=G.boxWrap(z,Z).replace(/\n/g,`
|
|
5
|
+
`+" ".repeat($+X));return Q+Y+" ".repeat(X)+R.replace(/\n/g,`
|
|
6
|
+
${Q}`)}boxWrap(q,$){if($<this.minWidthToWrap)return q;let z=q.split(/\r\n|\n/),G=/[\s]*[^\s]+/g,J=[];return z.forEach((Q)=>{let Y=Q.match(G);if(Y===null){J.push("");return}let X=[Y.shift()],_=this.displayWidth(X[0]);Y.forEach((Z)=>{let R=this.displayWidth(Z);if(_+R<=$){X.push(Z),_+=R;return}J.push(X.join(""));let B=Z.trimStart();X=[B],_=this.displayWidth(B)}),J.push(X.join(""))}),J.join(`
|
|
7
|
+
`)}}function x(q){let $=/\x1b\[\d*(;\d*)*m/g;return q.replace($,"")}_q.Help=C;_q.stripColor=x});var I=M((Mq)=>{var{InvalidArgumentError:Bq}=L();class b{constructor(q,$){this.flags=q,this.description=$||"",this.required=q.includes("<"),this.optional=q.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(q),this.mandatory=!1;let z=Uq(q);if(this.short=z.shortFlag,this.long=z.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(q,$){return this.defaultValue=q,this.defaultValueDescription=$,this}preset(q){return this.presetArg=q,this}conflicts(q){return this.conflictsWith=this.conflictsWith.concat(q),this}implies(q){let $=q;if(typeof q==="string")$={[q]:!0};return this.implied=Object.assign(this.implied||{},$),this}env(q){return this.envVar=q,this}argParser(q){return this.parseArg=q,this}makeOptionMandatory(q=!0){return this.mandatory=!!q,this}hideHelp(q=!0){return this.hidden=!!q,this}_concatValue(q,$){if($===this.defaultValue||!Array.isArray($))return[q];return $.concat(q)}choices(q){return this.argChoices=q.slice(),this.parseArg=($,z)=>{if(!this.argChoices.includes($))throw new Bq(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue($,z);return $},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return O(this.name().replace(/^no-/,""));return O(this.name())}is(q){return this.short===q||this.long===q}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class f{constructor(q){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,q.forEach(($)=>{if($.negate)this.negativeOptions.set($.attributeName(),$);else this.positiveOptions.set($.attributeName(),$)}),this.negativeOptions.forEach(($,z)=>{if(this.positiveOptions.has(z))this.dualOptions.add(z)})}valueFromOption(q,$){let z=$.attributeName();if(!this.dualOptions.has(z))return!0;let G=this.negativeOptions.get(z).presetArg,J=G!==void 0?G:!1;return $.negate===(J===q)}}function O(q){return q.split("-").reduce(($,z)=>{return $+z[0].toUpperCase()+z.slice(1)})}function Uq(q){let $,z,G=/^-[^-]$/,J=/^--[^-]/,Q=q.split(/[ |,]+/).concat("guard");if(G.test(Q[0]))$=Q.shift();if(J.test(Q[0]))z=Q.shift();if(!$&&G.test(Q[0]))$=Q.shift();if(!$&&J.test(Q[0]))$=z,z=Q.shift();if(Q[0].startsWith("-")){let Y=Q[0],X=`option creation failed due to '${Y}' in option flags '${q}'`;if(/^-[^-][^-]/.test(Y))throw new Error(`${X}
|
|
8
|
+
- a short flag is a single dash and a single character
|
|
9
|
+
- either use a single dash and a single character (for a short flag)
|
|
10
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(G.test(Y))throw new Error(`${X}
|
|
11
|
+
- too many short flags`);if(J.test(Y))throw new Error(`${X}
|
|
12
|
+
- too many long flags`);throw new Error(`${X}
|
|
13
|
+
- unrecognised flag format`)}if($===void 0&&z===void 0)throw new Error(`option creation failed due to no flags found in '${q}'.`);return{shortFlag:$,longFlag:z}}Mq.Option=b;Mq.DualOptions=f});var v=M((Wq)=>{function Kq(q,$){if(Math.abs(q.length-$.length)>3)return Math.max(q.length,$.length);let z=[];for(let G=0;G<=q.length;G++)z[G]=[G];for(let G=0;G<=$.length;G++)z[0][G]=G;for(let G=1;G<=$.length;G++)for(let J=1;J<=q.length;J++){let Q=1;if(q[J-1]===$[G-1])Q=0;else Q=1;if(z[J][G]=Math.min(z[J-1][G]+1,z[J][G-1]+1,z[J-1][G-1]+Q),J>1&&G>1&&q[J-1]===$[G-2]&&q[J-2]===$[G-1])z[J][G]=Math.min(z[J][G],z[J-2][G-2]+1)}return z[q.length][$.length]}function Sq(q,$){if(!$||$.length===0)return"";$=Array.from(new Set($));let z=q.startsWith("--");if(z)q=q.slice(2),$=$.map((Y)=>Y.slice(2));let G=[],J=3,Q=0.4;if($.forEach((Y)=>{if(Y.length<=1)return;let X=Kq(q,Y),_=Math.max(q.length,Y.length);if((_-X)/_>Q){if(X<J)J=X,G=[Y];else if(X===J)G.push(Y)}}),G.sort((Y,X)=>Y.localeCompare(X)),z)G=G.map((Y)=>`--${Y}`);if(G.length>1)return`
|
|
14
|
+
(Did you mean one of ${G.join(", ")}?)`;if(G.length===1)return`
|
|
15
|
+
(Did you mean ${G[0]}?)`;return""}Wq.suggestSimilar=Sq});var c=M((Fq)=>{var Iq=H("events").EventEmitter,P=H("child_process"),U=H("path"),S=H("fs"),T=H("process"),{Argument:Pq,humanReadableArgName:Eq}=K(),{CommanderError:E}=L(),{Help:Vq,stripColor:Nq}=j(),{Option:h,DualOptions:Dq}=I(),{suggestSimilar:u}=v();class N extends Iq{constructor(q){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=q||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:($)=>T.stdout.write($),writeErr:($)=>T.stderr.write($),outputError:($,z)=>z($),getOutHelpWidth:()=>T.stdout.isTTY?T.stdout.columns:void 0,getErrHelpWidth:()=>T.stderr.isTTY?T.stderr.columns:void 0,getOutHasColors:()=>V()??(T.stdout.isTTY&&T.stdout.hasColors?.()),getErrHasColors:()=>V()??(T.stderr.isTTY&&T.stderr.hasColors?.()),stripColor:($)=>Nq($)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(q){return this._outputConfiguration=q._outputConfiguration,this._helpOption=q._helpOption,this._helpCommand=q._helpCommand,this._helpConfiguration=q._helpConfiguration,this._exitCallback=q._exitCallback,this._storeOptionsAsProperties=q._storeOptionsAsProperties,this._combineFlagAndOptionalValue=q._combineFlagAndOptionalValue,this._allowExcessArguments=q._allowExcessArguments,this._enablePositionalOptions=q._enablePositionalOptions,this._showHelpAfterError=q._showHelpAfterError,this._showSuggestionAfterError=q._showSuggestionAfterError,this}_getCommandAndAncestors(){let q=[];for(let $=this;$;$=$.parent)q.push($);return q}command(q,$,z){let G=$,J=z;if(typeof G==="object"&&G!==null)J=G,G=null;J=J||{};let[,Q,Y]=q.match(/([^ ]+) *(.*)/),X=this.createCommand(Q);if(G)X.description(G),X._executableHandler=!0;if(J.isDefault)this._defaultCommandName=X._name;if(X._hidden=!!(J.noHelp||J.hidden),X._executableFile=J.executableFile||null,Y)X.arguments(Y);if(this._registerCommand(X),X.parent=this,X.copyInheritedSettings(this),G)return this;return X}createCommand(q){return new N(q)}createHelp(){return Object.assign(new Vq,this.configureHelp())}configureHelp(q){if(q===void 0)return this._helpConfiguration;return this._helpConfiguration=q,this}configureOutput(q){if(q===void 0)return this._outputConfiguration;return Object.assign(this._outputConfiguration,q),this}showHelpAfterError(q=!0){if(typeof q!=="string")q=!!q;return this._showHelpAfterError=q,this}showSuggestionAfterError(q=!0){return this._showSuggestionAfterError=!!q,this}addCommand(q,$){if(!q._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
16
|
+
- specify the name in Command constructor or using .name()`);if($=$||{},$.isDefault)this._defaultCommandName=q._name;if($.noHelp||$.hidden)q._hidden=!0;return this._registerCommand(q),q.parent=this,q._checkForBrokenPassThrough(),this}createArgument(q,$){return new Pq(q,$)}argument(q,$,z,G){let J=this.createArgument(q,$);if(typeof z==="function")J.default(G).argParser(z);else J.default(z);return this.addArgument(J),this}arguments(q){return q.trim().split(/ +/).forEach(($)=>{this.argument($)}),this}addArgument(q){let $=this.registeredArguments.slice(-1)[0];if($&&$.variadic)throw new Error(`only the last argument can be variadic '${$.name()}'`);if(q.required&&q.defaultValue!==void 0&&q.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${q.name()}'`);return this.registeredArguments.push(q),this}helpCommand(q,$){if(typeof q==="boolean")return this._addImplicitHelpCommand=q,this;q=q??"help [command]";let[,z,G]=q.match(/([^ ]+) *(.*)/),J=$??"display help for command",Q=this.createCommand(z);if(Q.helpOption(!1),G)Q.arguments(G);if(J)Q.description(J);return this._addImplicitHelpCommand=!0,this._helpCommand=Q,this}addHelpCommand(q,$){if(typeof q!=="object")return this.helpCommand(q,$),this;return this._addImplicitHelpCommand=!0,this._helpCommand=q,this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(q,$){let z=["preSubcommand","preAction","postAction"];if(!z.includes(q))throw new Error(`Unexpected value for event passed to hook : '${q}'.
|
|
17
|
+
Expecting one of '${z.join("', '")}'`);if(this._lifeCycleHooks[q])this._lifeCycleHooks[q].push($);else this._lifeCycleHooks[q]=[$];return this}exitOverride(q){if(q)this._exitCallback=q;else this._exitCallback=($)=>{if($.code!=="commander.executeSubCommandAsync")throw $};return this}_exit(q,$,z){if(this._exitCallback)this._exitCallback(new E(q,$,z));T.exit(q)}action(q){let $=(z)=>{let G=this.registeredArguments.length,J=z.slice(0,G);if(this._storeOptionsAsProperties)J[G]=this;else J[G]=this.opts();return J.push(this),q.apply(this,J)};return this._actionHandler=$,this}createOption(q,$){return new h(q,$)}_callParseArg(q,$,z,G){try{return q.parseArg($,z)}catch(J){if(J.code==="commander.invalidArgument"){let Q=`${G} ${J.message}`;this.error(Q,{exitCode:J.exitCode,code:J.code})}throw J}}_registerOption(q){let $=q.short&&this._findOption(q.short)||q.long&&this._findOption(q.long);if($){let z=q.long&&this._findOption(q.long)?q.long:q.short;throw new Error(`Cannot add option '${q.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${z}'
|
|
18
|
+
- already used by option '${$.flags}'`)}this.options.push(q)}_registerCommand(q){let $=(G)=>{return[G.name()].concat(G.aliases())},z=$(q).find((G)=>this._findCommand(G));if(z){let G=$(this._findCommand(z)).join("|"),J=$(q).join("|");throw new Error(`cannot add command '${J}' as already have command '${G}'`)}this.commands.push(q)}addOption(q){this._registerOption(q);let $=q.name(),z=q.attributeName();if(q.negate){let J=q.long.replace(/^--no-/,"--");if(!this._findOption(J))this.setOptionValueWithSource(z,q.defaultValue===void 0?!0:q.defaultValue,"default")}else if(q.defaultValue!==void 0)this.setOptionValueWithSource(z,q.defaultValue,"default");let G=(J,Q,Y)=>{if(J==null&&q.presetArg!==void 0)J=q.presetArg;let X=this.getOptionValue(z);if(J!==null&&q.parseArg)J=this._callParseArg(q,J,X,Q);else if(J!==null&&q.variadic)J=q._concatValue(J,X);if(J==null)if(q.negate)J=!1;else if(q.isBoolean()||q.optional)J=!0;else J="";this.setOptionValueWithSource(z,J,Y)};if(this.on("option:"+$,(J)=>{let Q=`error: option '${q.flags}' argument '${J}' is invalid.`;G(J,Q,"cli")}),q.envVar)this.on("optionEnv:"+$,(J)=>{let Q=`error: option '${q.flags}' value '${J}' from env '${q.envVar}' is invalid.`;G(J,Q,"env")});return this}_optionEx(q,$,z,G,J){if(typeof $==="object"&&$ instanceof h)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let Q=this.createOption($,z);if(Q.makeOptionMandatory(!!q.mandatory),typeof G==="function")Q.default(J).argParser(G);else if(G instanceof RegExp){let Y=G;G=(X,_)=>{let Z=Y.exec(X);return Z?Z[0]:_},Q.default(J).argParser(G)}else Q.default(G);return this.addOption(Q)}option(q,$,z,G){return this._optionEx({},q,$,z,G)}requiredOption(q,$,z,G){return this._optionEx({mandatory:!0},q,$,z,G)}combineFlagAndOptionalValue(q=!0){return this._combineFlagAndOptionalValue=!!q,this}allowUnknownOption(q=!0){return this._allowUnknownOption=!!q,this}allowExcessArguments(q=!0){return this._allowExcessArguments=!!q,this}enablePositionalOptions(q=!0){return this._enablePositionalOptions=!!q,this}passThroughOptions(q=!0){return this._passThroughOptions=!!q,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(q=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!q,this}getOptionValue(q){if(this._storeOptionsAsProperties)return this[q];return this._optionValues[q]}setOptionValue(q,$){return this.setOptionValueWithSource(q,$,void 0)}setOptionValueWithSource(q,$,z){if(this._storeOptionsAsProperties)this[q]=$;else this._optionValues[q]=$;return this._optionValueSources[q]=z,this}getOptionValueSource(q){return this._optionValueSources[q]}getOptionValueSourceWithGlobals(q){let $;return this._getCommandAndAncestors().forEach((z)=>{if(z.getOptionValueSource(q)!==void 0)$=z.getOptionValueSource(q)}),$}_prepareUserArgs(q,$){if(q!==void 0&&!Array.isArray(q))throw new Error("first parameter to parse must be array or undefined");if($=$||{},q===void 0&&$.from===void 0){if(T.versions?.electron)$.from="electron";let G=T.execArgv??[];if(G.includes("-e")||G.includes("--eval")||G.includes("-p")||G.includes("--print"))$.from="eval"}if(q===void 0)q=T.argv;this.rawArgs=q.slice();let z;switch($.from){case void 0:case"node":this._scriptPath=q[1],z=q.slice(2);break;case"electron":if(T.defaultApp)this._scriptPath=q[1],z=q.slice(2);else z=q.slice(1);break;case"user":z=q.slice(0);break;case"eval":z=q.slice(1);break;default:throw new Error(`unexpected parse option { from: '${$.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",z}parse(q,$){this._prepareForParse();let z=this._prepareUserArgs(q,$);return this._parseCommand([],z),this}async parseAsync(q,$){this._prepareForParse();let z=this._prepareUserArgs(q,$);return await this._parseCommand([],z),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
19
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(q,$,z){if(S.existsSync(q))return;let G=$?`searched for local subcommand relative to directory '${$}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",J=`'${q}' does not exist
|
|
20
|
+
- if '${z}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
21
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
22
|
+
- ${G}`;throw new Error(J)}_executeSubCommand(q,$){$=$.slice();let z=!1,G=[".js",".ts",".tsx",".mjs",".cjs"];function J(Z,R){let B=U.resolve(Z,R);if(S.existsSync(B))return B;if(G.includes(U.extname(R)))return;let y=G.find((r)=>S.existsSync(`${B}${r}`));if(y)return`${B}${y}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Q=q._executableFile||`${this._name}-${q._name}`,Y=this._executableDir||"";if(this._scriptPath){let Z;try{Z=S.realpathSync(this._scriptPath)}catch{Z=this._scriptPath}Y=U.resolve(U.dirname(Z),Y)}if(Y){let Z=J(Y,Q);if(!Z&&!q._executableFile&&this._scriptPath){let R=U.basename(this._scriptPath,U.extname(this._scriptPath));if(R!==this._name)Z=J(Y,`${R}-${q._name}`)}Q=Z||Q}z=G.includes(U.extname(Q));let X;if(T.platform!=="win32")if(z)$.unshift(Q),$=g(T.execArgv).concat($),X=P.spawn(T.argv[0],$,{stdio:"inherit"});else X=P.spawn(Q,$,{stdio:"inherit"});else this._checkForMissingExecutable(Q,Y,q._name),$.unshift(Q),$=g(T.execArgv).concat($),X=P.spawn(T.execPath,$,{stdio:"inherit"});if(!X.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((R)=>{T.on(R,()=>{if(X.killed===!1&&X.exitCode===null)X.kill(R)})});let _=this._exitCallback;X.on("close",(Z)=>{if(Z=Z??1,!_)T.exit(Z);else _(new E(Z,"commander.executeSubCommandAsync","(close)"))}),X.on("error",(Z)=>{if(Z.code==="ENOENT")this._checkForMissingExecutable(Q,Y,q._name);else if(Z.code==="EACCES")throw new Error(`'${Q}' not executable`);if(!_)T.exit(1);else{let R=new E(1,"commander.executeSubCommandAsync","(error)");R.nestedError=Z,_(R)}}),this.runningCommand=X}_dispatchSubcommand(q,$,z){let G=this._findCommand(q);if(!G)this.help({error:!0});G._prepareForParse();let J;return J=this._chainOrCallSubCommandHook(J,G,"preSubcommand"),J=this._chainOrCall(J,()=>{if(G._executableHandler)this._executeSubCommand(G,$.concat(z));else return G._parseCommand($,z)}),J}_dispatchHelpCommand(q){if(!q)this.help();let $=this._findCommand(q);if($&&!$._executableHandler)$.help();return this._dispatchSubcommand(q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((q,$)=>{if(q.required&&this.args[$]==null)this.missingArgument(q.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let q=(z,G,J)=>{let Q=G;if(G!==null&&z.parseArg){let Y=`error: command-argument value '${G}' is invalid for argument '${z.name()}'.`;Q=this._callParseArg(z,G,J,Y)}return Q};this._checkNumberOfArguments();let $=[];this.registeredArguments.forEach((z,G)=>{let J=z.defaultValue;if(z.variadic){if(G<this.args.length){if(J=this.args.slice(G),z.parseArg)J=J.reduce((Q,Y)=>{return q(z,Y,Q)},z.defaultValue)}else if(J===void 0)J=[]}else if(G<this.args.length){if(J=this.args[G],z.parseArg)J=q(z,J,z.defaultValue)}$[G]=J}),this.processedArgs=$}_chainOrCall(q,$){if(q&&q.then&&typeof q.then==="function")return q.then(()=>$());return $()}_chainOrCallHooks(q,$){let z=q,G=[];if(this._getCommandAndAncestors().reverse().filter((J)=>J._lifeCycleHooks[$]!==void 0).forEach((J)=>{J._lifeCycleHooks[$].forEach((Q)=>{G.push({hookedCommand:J,callback:Q})})}),$==="postAction")G.reverse();return G.forEach((J)=>{z=this._chainOrCall(z,()=>{return J.callback(J.hookedCommand,this)})}),z}_chainOrCallSubCommandHook(q,$,z){let G=q;if(this._lifeCycleHooks[z]!==void 0)this._lifeCycleHooks[z].forEach((J)=>{G=this._chainOrCall(G,()=>{return J(this,$)})});return G}_parseCommand(q,$){let z=this.parseOptions($);if(this._parseOptionsEnv(),this._parseOptionsImplied(),q=q.concat(z.operands),$=z.unknown,this.args=q.concat($),q&&this._findCommand(q[0]))return this._dispatchSubcommand(q[0],q.slice(1),$);if(this._getHelpCommand()&&q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested($),this._dispatchSubcommand(this._defaultCommandName,q,$);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(z.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let G=()=>{if(z.unknown.length>0)this.unknownOption(z.unknown[0])},J=`command:${this.name()}`;if(this._actionHandler){G(),this._processArguments();let Q;if(Q=this._chainOrCallHooks(Q,"preAction"),Q=this._chainOrCall(Q,()=>this._actionHandler(this.processedArgs)),this.parent)Q=this._chainOrCall(Q,()=>{this.parent.emit(J,q,$)});return Q=this._chainOrCallHooks(Q,"postAction"),Q}if(this.parent&&this.parent.listenerCount(J))G(),this._processArguments(),this.parent.emit(J,q,$);else if(q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",q,$);if(this.listenerCount("command:*"))this.emit("command:*",q,$);else if(this.commands.length)this.unknownCommand();else G(),this._processArguments()}else if(this.commands.length)G(),this.help({error:!0});else G(),this._processArguments()}_findCommand(q){if(!q)return;return this.commands.find(($)=>$._name===q||$._aliases.includes(q))}_findOption(q){return this.options.find(($)=>$.is(q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((q)=>{q.options.forEach(($)=>{if($.mandatory&&q.getOptionValue($.attributeName())===void 0)q.missingMandatoryOptionValue($)})})}_checkForConflictingLocalOptions(){let q=this.options.filter((z)=>{let G=z.attributeName();if(this.getOptionValue(G)===void 0)return!1;return this.getOptionValueSource(G)!=="default"});q.filter((z)=>z.conflictsWith.length>0).forEach((z)=>{let G=q.find((J)=>z.conflictsWith.includes(J.attributeName()));if(G)this._conflictingOption(z,G)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((q)=>{q._checkForConflictingLocalOptions()})}parseOptions(q){let $=[],z=[],G=$,J=q.slice();function Q(X){return X.length>1&&X[0]==="-"}let Y=null;while(J.length){let X=J.shift();if(X==="--"){if(G===z)G.push(X);G.push(...J);break}if(Y&&!Q(X)){this.emit(`option:${Y.name()}`,X);continue}if(Y=null,Q(X)){let _=this._findOption(X);if(_){if(_.required){let Z=J.shift();if(Z===void 0)this.optionMissingArgument(_);this.emit(`option:${_.name()}`,Z)}else if(_.optional){let Z=null;if(J.length>0&&!Q(J[0]))Z=J.shift();this.emit(`option:${_.name()}`,Z)}else this.emit(`option:${_.name()}`);Y=_.variadic?_:null;continue}}if(X.length>2&&X[0]==="-"&&X[1]!=="-"){let _=this._findOption(`-${X[1]}`);if(_){if(_.required||_.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${_.name()}`,X.slice(2));else this.emit(`option:${_.name()}`),J.unshift(`-${X.slice(2)}`);continue}}if(/^--[^=]+=/.test(X)){let _=X.indexOf("="),Z=this._findOption(X.slice(0,_));if(Z&&(Z.required||Z.optional)){this.emit(`option:${Z.name()}`,X.slice(_+1));continue}}if(Q(X))G=z;if((this._enablePositionalOptions||this._passThroughOptions)&&$.length===0&&z.length===0){if(this._findCommand(X)){if($.push(X),J.length>0)z.push(...J);break}else if(this._getHelpCommand()&&X===this._getHelpCommand().name()){if($.push(X),J.length>0)$.push(...J);break}else if(this._defaultCommandName){if(z.push(X),J.length>0)z.push(...J);break}}if(this._passThroughOptions){if(G.push(X),J.length>0)G.push(...J);break}G.push(X)}return{operands:$,unknown:z}}opts(){if(this._storeOptionsAsProperties){let q={},$=this.options.length;for(let z=0;z<$;z++){let G=this.options[z].attributeName();q[G]=G===this._versionOptionName?this._version:this[G]}return q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((q,$)=>Object.assign(q,$.opts()),{})}error(q,$){if(this._outputConfiguration.outputError(`${q}
|
|
23
|
+
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
24
|
+
`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
|
|
25
|
+
`),this.outputHelp({error:!0});let z=$||{},G=z.exitCode||1,J=z.code||"commander.error";this._exit(G,J,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in T.env){let $=q.attributeName();if(this.getOptionValue($)===void 0||["default","config","env"].includes(this.getOptionValueSource($)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,T.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new Dq(this.options),$=(z)=>{return this.getOptionValue(z)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(z))};this.options.filter((z)=>z.implied!==void 0&&$(z.attributeName())&&q.valueFromOption(this.getOptionValue(z.attributeName()),z)).forEach((z)=>{Object.keys(z.implied).filter((G)=>!$(G)).forEach((G)=>{this.setOptionValueWithSource(G,z.implied[G],"implied")})})}missingArgument(q){let $=`error: missing required argument '${q}'`;this.error($,{code:"commander.missingArgument"})}optionMissingArgument(q){let $=`error: option '${q.flags}' argument missing`;this.error($,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let $=`error: required option '${q.flags}' not specified`;this.error($,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,$){let z=(Q)=>{let Y=Q.attributeName(),X=this.getOptionValue(Y),_=this.options.find((R)=>R.negate&&Y===R.attributeName()),Z=this.options.find((R)=>!R.negate&&Y===R.attributeName());if(_&&(_.presetArg===void 0&&X===!1||_.presetArg!==void 0&&X===_.presetArg))return _;return Z||Q},G=(Q)=>{let Y=z(Q),X=Y.attributeName();if(this.getOptionValueSource(X)==="env")return`environment variable '${Y.envVar}'`;return`option '${Y.flags}'`},J=`error: ${G(q)} cannot be used with ${G($)}`;this.error(J,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let $="";if(q.startsWith("--")&&this._showSuggestionAfterError){let G=[],J=this;do{let Q=J.createHelp().visibleOptions(J).filter((Y)=>Y.long).map((Y)=>Y.long);G=G.concat(Q),J=J.parent}while(J&&!J._enablePositionalOptions);$=u(q,G)}let z=`error: unknown option '${q}'${$}`;this.error(z,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let $=this.registeredArguments.length,z=$===1?"":"s",J=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${$} argument${z} but got ${q.length}.`;this.error(J,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],$="";if(this._showSuggestionAfterError){let G=[];this.createHelp().visibleCommands(this).forEach((J)=>{if(G.push(J.name()),J.alias())G.push(J.alias())}),$=u(q,G)}let z=`error: unknown command '${q}'${$}`;this.error(z,{code:"commander.unknownCommand"})}version(q,$,z){if(q===void 0)return this._version;this._version=q,$=$||"-V, --version",z=z||"output the version number";let G=this.createOption($,z);return this._versionOptionName=G.attributeName(),this._registerOption(G),this.on("option:"+G.name(),()=>{this._outputConfiguration.writeOut(`${q}
|
|
26
|
+
`),this._exit(0,"commander.version",q)}),this}description(q,$){if(q===void 0&&$===void 0)return this._description;if(this._description=q,$)this._argsDescription=$;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let $=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)$=this.commands[this.commands.length-1];if(q===$._name)throw new Error("Command alias can't be the same as its name");let z=this.parent?._findCommand(q);if(z){let G=[z.name()].concat(z.aliases()).join("|");throw new Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${G}'`)}return $._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach(($)=>this.alias($)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let $=this.registeredArguments.map((z)=>{return Eq(z)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?$:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}nameFromFilename(q){return this._name=U.basename(q,U.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let $=this.createHelp(),z=this._getOutputContext(q);$.prepareContext({error:z.error,helpWidth:z.helpWidth,outputHasColors:z.hasColors});let G=$.formatHelp(this,$);if(z.hasColors)return G;return this._outputConfiguration.stripColor(G)}_getOutputContext(q){q=q||{};let $=!!q.error,z,G,J;if($)z=(Y)=>this._outputConfiguration.writeErr(Y),G=this._outputConfiguration.getErrHasColors(),J=this._outputConfiguration.getErrHelpWidth();else z=(Y)=>this._outputConfiguration.writeOut(Y),G=this._outputConfiguration.getOutHasColors(),J=this._outputConfiguration.getOutHelpWidth();return{error:$,write:(Y)=>{if(!G)Y=this._outputConfiguration.stripColor(Y);return z(Y)},hasColors:G,helpWidth:J}}outputHelp(q){let $;if(typeof q==="function")$=q,q=void 0;let z=this._getOutputContext(q),G={error:z.error,write:z.write,command:this};this._getCommandAndAncestors().reverse().forEach((Q)=>Q.emit("beforeAllHelp",G)),this.emit("beforeHelp",G);let J=this.helpInformation({error:z.error});if($){if(J=$(J),typeof J!=="string"&&!Buffer.isBuffer(J))throw new Error("outputHelp callback must return a string or a Buffer")}if(z.write(J),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",G),this._getCommandAndAncestors().forEach((Q)=>Q.emit("afterAllHelp",G))}helpOption(q,$){if(typeof q==="boolean"){if(q)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return q=q??"-h, --help",$=$??"display help for command",this._helpOption=this.createOption(q,$),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this}help(q){this.outputHelp(q);let $=Number(T.exitCode??0);if($===0&&q&&typeof q!=="function"&&q.error)$=1;this._exit($,"commander.help","(outputHelp)")}addHelpText(q,$){let z=["beforeAll","before","after","afterAll"];if(!z.includes(q))throw new Error(`Unexpected value for position to addHelpText.
|
|
27
|
+
Expecting one of '${z.join("', '")}'`);let G=`${q}Help`;return this.on(G,(J)=>{let Q;if(typeof $==="function")Q=$({error:J.error,command:J.command});else Q=$;if(Q)J.write(`${Q}
|
|
28
|
+
`)}),this}_outputHelpIfRequested(q){let $=this._getHelpOption();if($&&q.find((G)=>$.is(G)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function g(q){return q.map(($)=>{if(!$.startsWith("--inspect"))return $;let z,G="127.0.0.1",J="9229",Q;if((Q=$.match(/^(--inspect(-brk)?)$/))!==null)z=Q[1];else if((Q=$.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(z=Q[1],/^\d+$/.test(Q[3]))J=Q[3];else G=Q[3];else if((Q=$.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)z=Q[1],G=Q[3],J=Q[4];if(z&&J!=="0")return`${z}=${G}:${parseInt(J)+1}`;return $})}function V(){if(T.env.NO_COLOR||T.env.FORCE_COLOR==="0"||T.env.FORCE_COLOR==="false")return!1;if(T.env.FORCE_COLOR||T.env.CLICOLOR_FORCE!==void 0)return!0;return}Fq.Command=N;Fq.useColor=V});var p=M((Cq)=>{var{Argument:l}=K(),{Command:D}=c(),{CommanderError:wq,InvalidArgumentError:m}=L(),{Help:kq}=j(),{Option:d}=I();Cq.program=new D;Cq.createCommand=(q)=>new D(q);Cq.createOption=(q,$)=>new d(q,$);Cq.createArgument=(q,$)=>new l(q,$);Cq.Command=D;Cq.Option=d;Cq.Argument=l;Cq.Help=kq;Cq.CommanderError=wq;Cq.InvalidArgumentError=m;Cq.InvalidOptionArgumentError=m});var i=e(p(),1),{program:F,createCommand:eq,createArgument:q$,createOption:$$,CommanderError:z$,InvalidArgumentError:G$,InvalidOptionArgumentError:J$,Command:Q$,Argument:X$,Option:Y$,Help:Z$}=i.default;var s=async()=>await Bun.file(`${import.meta.dir}/package.json`).json().then((q)=>q.version).catch(()=>"UNKNOWN");var dq=await s();F.name("xx").description("chneau's utility CLI").version(dq);F.parse();
|