gstatx 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.js +26 -26
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,40 +1,40 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as W1}from"node:module";var L1=Object.create;var{getPrototypeOf:M1,defineProperty:l,getOwnPropertyNames:U1}=Object;var S1=Object.prototype.hasOwnProperty;var K1=($,q,J)=>{J=$!=null?L1(M1($)):{};let z=q||!$||!$.__esModule?l(J,"default",{value:$,enumerable:!0}):J;for(let Q of U1($))if(!S1.call(z,Q))l(z,Q,{get:()=>$[Q],enumerable:!0});return z};var U=($,q)=>()=>(q||$((q={exports:{}}).exports,q),q.exports);var I=W1(import.meta.url);var E=U((j1)=>{class w extends Error{constructor($,q,J){super(J);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=q,this.exitCode=$,this.nestedError=void 0}}class c extends w{constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}j1.CommanderError=w;j1.InvalidArgumentError=c});var y=U((N1)=>{var{InvalidArgumentError:V1}=E();class m{constructor($,q){switch(this.description=q||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(q,J)=>{if(!this.argChoices.includes(q))throw new V1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,J);return q},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function D1($){let q=$.name()+($.variadic===!0?"...":"");return $.required?"<"+q+">":"["+q+"]"}N1.Argument=m;N1.humanReadableArgName=D1});var A=U((A1)=>{var{humanReadableArgName:w1}=y();class d{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let q=$.commands.filter((z)=>!z._hidden),J=$._getHelpCommand();if(J&&!J._hidden)q.push(J);if(this.sortSubcommands)q.sort((z,Q)=>{return z.name().localeCompare(Q.name())});return q}compareOptions($,q){let J=(z)=>{return z.short?z.short.replace(/^-/,""):z.long.replace(/^--/,"")};return J($).localeCompare(J(q))}visibleOptions($){let q=$.options.filter((z)=>!z.hidden),J=$._getHelpOption();if(J&&!J.hidden){let z=J.short&&$._findOption(J.short),Q=J.long&&$._findOption(J.long);if(!z&&!Q)q.push(J);else if(J.long&&!Q)q.push($.createOption(J.long,J.description));else if(J.short&&!z)q.push($.createOption(J.short,J.description))}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let q=[];for(let J=$.parent;J;J=J.parent){let z=J.options.filter((Q)=>!Q.hidden);q.push(...z)}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((q)=>{q.description=q.description||$._argsDescription[q.name()]||""});if($.registeredArguments.find((q)=>q.description))return $.registeredArguments;return[]}subcommandTerm($){let q=$.registeredArguments.map((J)=>w1(J)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(q?" "+q:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,q){return q.visibleCommands($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleSubcommandTerm(q.subcommandTerm(z))))},0)}longestOptionTermLength($,q){return q.visibleOptions($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleOptionTerm(q.optionTerm(z))))},0)}longestGlobalOptionTermLength($,q){return q.visibleGlobalOptions($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleOptionTerm(q.optionTerm(z))))},0)}longestArgumentTermLength($,q){return q.visibleArguments($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleArgumentTerm(q.argumentTerm(z))))},0)}commandUsage($){let q=$._name;if($._aliases[0])q=q+"|"+$._aliases[0];let J="";for(let z=$.parent;z;z=z.parent)J=z.name()+" "+J;return J+q+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((J)=>JSON.stringify(J)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)q.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)q.push(`env: ${$.envVar}`);if(q.length>0){let J=`(${q.join(", ")})`;if($.description)return`${$.description} ${J}`;return J}return $.description}argumentDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((J)=>JSON.stringify(J)).join(", ")}`);if($.defaultValue!==void 0)q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(q.length>0){let J=`(${q.join(", ")})`;if($.description)return`${$.description} ${J}`;return J}return $.description}formatItemList($,q,J){if(q.length===0)return[];return[J.styleTitle($),...q,""]}groupItems($,q,J){let z=new Map;return $.forEach((Q)=>{let X=J(Q);if(!z.has(X))z.set(X,[])}),q.forEach((Q)=>{let X=J(Q);if(!z.has(X))z.set(X,[]);z.get(X).push(Q)}),z}formatHelp($,q){let J=q.padWidth($,q),z=q.helpWidth??80;function Q(H,T){return q.formatItem(H,J,T,q)}let X=[`${q.styleTitle("Usage:")} ${q.styleUsage(q.commandUsage($))}`,""],Y=q.commandDescription($);if(Y.length>0)X=X.concat([q.boxWrap(q.styleCommandDescription(Y),z),""]);let Z=q.visibleArguments($).map((H)=>{return Q(q.styleArgumentTerm(q.argumentTerm(H)),q.styleArgumentDescription(q.argumentDescription(H)))});if(X=X.concat(this.formatItemList("Arguments:",Z,q)),this.groupItems($.options,q.visibleOptions($),(H)=>H.helpGroupHeading??"Options:").forEach((H,T)=>{let G=H.map((L)=>{return Q(q.styleOptionTerm(q.optionTerm(L)),q.styleOptionDescription(q.optionDescription(L)))});X=X.concat(this.formatItemList(T,G,q))}),q.showGlobalOptions){let H=q.visibleGlobalOptions($).map((T)=>{return Q(q.styleOptionTerm(q.optionTerm(T)),q.styleOptionDescription(q.optionDescription(T)))});X=X.concat(this.formatItemList("Global Options:",H,q))}return this.groupItems($.commands,q.visibleCommands($),(H)=>H.helpGroup()||"Commands:").forEach((H,T)=>{let G=H.map((L)=>{return Q(q.styleSubcommandTerm(q.subcommandTerm(L)),q.styleSubcommandDescription(q.subcommandDescription(L)))});X=X.concat(this.formatItemList(T,G,q))}),X.join(`
3
- `)}displayWidth($){return p($).length}styleTitle($){return $}styleUsage($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q==="[command]")return this.styleSubcommandText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleCommandText(q)}).join(" ")}styleCommandDescription($){return this.styleDescriptionText($)}styleOptionDescription($){return this.styleDescriptionText($)}styleSubcommandDescription($){return this.styleDescriptionText($)}styleArgumentDescription($){return this.styleDescriptionText($)}styleDescriptionText($){return $}styleOptionTerm($){return this.styleOptionText($)}styleSubcommandTerm($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleSubcommandText(q)}).join(" ")}styleArgumentTerm($){return this.styleArgumentText($)}styleOptionText($){return $}styleArgumentText($){return $}styleSubcommandText($){return $}styleCommandText($){return $}padWidth($,q){return Math.max(q.longestOptionTermLength($,q),q.longestGlobalOptionTermLength($,q),q.longestSubcommandTermLength($,q),q.longestArgumentTermLength($,q))}preformatted($){return/\n[^\S\r\n]/.test($)}formatItem($,q,J,z){let X=" ".repeat(2);if(!J)return X+$;let Y=$.padEnd(q+$.length-z.displayWidth($)),Z=2,R=(this.helpWidth??80)-q-Z-2,H;if(R<this.minWidthToWrap||z.preformatted(J))H=J;else H=z.boxWrap(J,R).replace(/\n/g,`
4
- `+" ".repeat(q+Z));return X+Y+" ".repeat(Z)+H.replace(/\n/g,`
5
- ${X}`)}boxWrap($,q){if(q<this.minWidthToWrap)return $;let J=$.split(/\r\n|\n/),z=/[\s]*[^\s]+/g,Q=[];return J.forEach((X)=>{let Y=X.match(z);if(Y===null){Q.push("");return}let Z=[Y.shift()],_=this.displayWidth(Z[0]);Y.forEach((R)=>{let H=this.displayWidth(R);if(_+H<=q){Z.push(R),_+=H;return}Q.push(Z.join(""));let T=R.trimStart();Z=[T],_=this.displayWidth(T)}),Q.push(Z.join(""))}),Q.join(`
6
- `)}}function p($){let q=/\x1b\[\d*(;\d*)*m/g;return $.replace(q,"")}A1.Help=d;A1.stripColor=p});var P=U((b1)=>{var{InvalidArgumentError:O1}=E();class i{constructor($,q){this.flags=$,this.description=q||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let J=x1($);if(this.short=J.shortFlag,this.long=J.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,this.helpGroupHeading=void 0}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let q=$;if(typeof $==="string")q={[$]:!0};return this.implied=Object.assign(this.implied||{},q),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}choices($){return this.argChoices=$.slice(),this.parseArg=(q,J)=>{if(!this.argChoices.includes(q))throw new O1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,J);return q},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return s(this.name().replace(/^no-/,""));return s(this.name())}helpGroup($){return this.helpGroupHeading=$,this}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class t{constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((q)=>{if(q.negate)this.negativeOptions.set(q.attributeName(),q);else this.positiveOptions.set(q.attributeName(),q)}),this.negativeOptions.forEach((q,J)=>{if(this.positiveOptions.has(J))this.dualOptions.add(J)})}valueFromOption($,q){let J=q.attributeName();if(!this.dualOptions.has(J))return!0;let z=this.negativeOptions.get(J).presetArg,Q=z!==void 0?z:!1;return q.negate===(Q===$)}}function s($){return $.split("-").reduce((q,J)=>{return q+J[0].toUpperCase()+J.slice(1)})}function x1($){let q,J,z=/^-[^-]$/,Q=/^--[^-]/,X=$.split(/[ |,]+/).concat("guard");if(z.test(X[0]))q=X.shift();if(Q.test(X[0]))J=X.shift();if(!q&&z.test(X[0]))q=X.shift();if(!q&&Q.test(X[0]))q=J,J=X.shift();if(X[0].startsWith("-")){let Y=X[0],Z=`option creation failed due to '${Y}' in option flags '${$}'`;if(/^-[^-][^-]/.test(Y))throw new Error(`${Z}
2
+ import{createRequire as W1}from"node:module";var M1=Object.create;var{getPrototypeOf:L1,defineProperty:l,getOwnPropertyNames:U1}=Object;var S1=Object.prototype.hasOwnProperty;var K1=($,q,z)=>{z=$!=null?M1(L1($)):{};let J=q||!$||!$.__esModule?l(z,"default",{value:$,enumerable:!0}):z;for(let Q of U1($))if(!S1.call(J,Q))l(J,Q,{get:()=>$[Q],enumerable:!0});return J};var U=($,q)=>()=>(q||$((q={exports:{}}).exports,q),q.exports);var I=W1(import.meta.url);var E=U((j1)=>{class w extends Error{constructor($,q,z){super(z);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=q,this.exitCode=$,this.nestedError=void 0}}class c extends w{constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}j1.CommanderError=w;j1.InvalidArgumentError=c});var y=U((N1)=>{var{InvalidArgumentError:V1}=E();class m{constructor($,q){switch(this.description=q||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(q,z)=>{if(!this.argChoices.includes(q))throw new V1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,z);return q},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function D1($){let q=$.name()+($.variadic===!0?"...":"");return $.required?"<"+q+">":"["+q+"]"}N1.Argument=m;N1.humanReadableArgName=D1});var A=U((A1)=>{var{humanReadableArgName:w1}=y();class d{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let q=$.commands.filter((J)=>!J._hidden),z=$._getHelpCommand();if(z&&!z._hidden)q.push(z);if(this.sortSubcommands)q.sort((J,Q)=>{return J.name().localeCompare(Q.name())});return q}compareOptions($,q){let z=(J)=>{return J.short?J.short.replace(/^-/,""):J.long.replace(/^--/,"")};return z($).localeCompare(z(q))}visibleOptions($){let q=$.options.filter((J)=>!J.hidden),z=$._getHelpOption();if(z&&!z.hidden){let J=z.short&&$._findOption(z.short),Q=z.long&&$._findOption(z.long);if(!J&&!Q)q.push(z);else if(z.long&&!Q)q.push($.createOption(z.long,z.description));else if(z.short&&!J)q.push($.createOption(z.short,z.description))}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let q=[];for(let z=$.parent;z;z=z.parent){let J=z.options.filter((Q)=>!Q.hidden);q.push(...J)}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((q)=>{q.description=q.description||$._argsDescription[q.name()]||""});if($.registeredArguments.find((q)=>q.description))return $.registeredArguments;return[]}subcommandTerm($){let q=$.registeredArguments.map((z)=>w1(z)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(q?" "+q:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,q){return q.visibleCommands($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleSubcommandTerm(q.subcommandTerm(J))))},0)}longestOptionTermLength($,q){return q.visibleOptions($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestGlobalOptionTermLength($,q){return q.visibleGlobalOptions($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestArgumentTermLength($,q){return q.visibleArguments($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleArgumentTerm(q.argumentTerm(J))))},0)}commandUsage($){let q=$._name;if($._aliases[0])q=q+"|"+$._aliases[0];let z="";for(let J=$.parent;J;J=J.parent)z=J.name()+" "+z;return z+q+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)q.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)q.push(`env: ${$.envVar}`);if(q.length>0){let z=`(${q.join(", ")})`;if($.description)return`${$.description} ${z}`;return z}return $.description}argumentDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if($.defaultValue!==void 0)q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(q.length>0){let z=`(${q.join(", ")})`;if($.description)return`${$.description} ${z}`;return z}return $.description}formatItemList($,q,z){if(q.length===0)return[];return[z.styleTitle($),...q,""]}groupItems($,q,z){let J=new Map;return $.forEach((Q)=>{let X=z(Q);if(!J.has(X))J.set(X,[])}),q.forEach((Q)=>{let X=z(Q);if(!J.has(X))J.set(X,[]);J.get(X).push(Q)}),J}formatHelp($,q){let z=q.padWidth($,q),J=q.helpWidth??80;function Q(R,B){return q.formatItem(R,z,B,q)}let X=[`${q.styleTitle("Usage:")} ${q.styleUsage(q.commandUsage($))}`,""],Y=q.commandDescription($);if(Y.length>0)X=X.concat([q.boxWrap(q.styleCommandDescription(Y),J),""]);let Z=q.visibleArguments($).map((R)=>{return Q(q.styleArgumentTerm(q.argumentTerm(R)),q.styleArgumentDescription(q.argumentDescription(R)))});if(X=X.concat(this.formatItemList("Arguments:",Z,q)),this.groupItems($.options,q.visibleOptions($),(R)=>R.helpGroupHeading??"Options:").forEach((R,B)=>{let G=R.map((M)=>{return Q(q.styleOptionTerm(q.optionTerm(M)),q.styleOptionDescription(q.optionDescription(M)))});X=X.concat(this.formatItemList(B,G,q))}),q.showGlobalOptions){let R=q.visibleGlobalOptions($).map((B)=>{return Q(q.styleOptionTerm(q.optionTerm(B)),q.styleOptionDescription(q.optionDescription(B)))});X=X.concat(this.formatItemList("Global Options:",R,q))}return this.groupItems($.commands,q.visibleCommands($),(R)=>R.helpGroup()||"Commands:").forEach((R,B)=>{let G=R.map((M)=>{return Q(q.styleSubcommandTerm(q.subcommandTerm(M)),q.styleSubcommandDescription(q.subcommandDescription(M)))});X=X.concat(this.formatItemList(B,G,q))}),X.join(`
3
+ `)}displayWidth($){return p($).length}styleTitle($){return $}styleUsage($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q==="[command]")return this.styleSubcommandText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleCommandText(q)}).join(" ")}styleCommandDescription($){return this.styleDescriptionText($)}styleOptionDescription($){return this.styleDescriptionText($)}styleSubcommandDescription($){return this.styleDescriptionText($)}styleArgumentDescription($){return this.styleDescriptionText($)}styleDescriptionText($){return $}styleOptionTerm($){return this.styleOptionText($)}styleSubcommandTerm($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleSubcommandText(q)}).join(" ")}styleArgumentTerm($){return this.styleArgumentText($)}styleOptionText($){return $}styleArgumentText($){return $}styleSubcommandText($){return $}styleCommandText($){return $}padWidth($,q){return Math.max(q.longestOptionTermLength($,q),q.longestGlobalOptionTermLength($,q),q.longestSubcommandTermLength($,q),q.longestArgumentTermLength($,q))}preformatted($){return/\n[^\S\r\n]/.test($)}formatItem($,q,z,J){let X=" ".repeat(2);if(!z)return X+$;let Y=$.padEnd(q+$.length-J.displayWidth($)),Z=2,H=(this.helpWidth??80)-q-Z-2,R;if(H<this.minWidthToWrap||J.preformatted(z))R=z;else R=J.boxWrap(z,H).replace(/\n/g,`
4
+ `+" ".repeat(q+Z));return X+Y+" ".repeat(Z)+R.replace(/\n/g,`
5
+ ${X}`)}boxWrap($,q){if(q<this.minWidthToWrap)return $;let z=$.split(/\r\n|\n/),J=/[\s]*[^\s]+/g,Q=[];return z.forEach((X)=>{let Y=X.match(J);if(Y===null){Q.push("");return}let Z=[Y.shift()],T=this.displayWidth(Z[0]);Y.forEach((H)=>{let R=this.displayWidth(H);if(T+R<=q){Z.push(H),T+=R;return}Q.push(Z.join(""));let B=H.trimStart();Z=[B],T=this.displayWidth(B)}),Q.push(Z.join(""))}),Q.join(`
6
+ `)}}function p($){let q=/\x1b\[\d*(;\d*)*m/g;return $.replace(q,"")}A1.Help=d;A1.stripColor=p});var P=U((b1)=>{var{InvalidArgumentError:O1}=E();class i{constructor($,q){this.flags=$,this.description=q||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let z=x1($);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,this.helpGroupHeading=void 0}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let q=$;if(typeof $==="string")q={[$]:!0};return this.implied=Object.assign(this.implied||{},q),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}choices($){return this.argChoices=$.slice(),this.parseArg=(q,z)=>{if(!this.argChoices.includes(q))throw new O1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,z);return q},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return s(this.name().replace(/^no-/,""));return s(this.name())}helpGroup($){return this.helpGroupHeading=$,this}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class t{constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((q)=>{if(q.negate)this.negativeOptions.set(q.attributeName(),q);else this.positiveOptions.set(q.attributeName(),q)}),this.negativeOptions.forEach((q,z)=>{if(this.positiveOptions.has(z))this.dualOptions.add(z)})}valueFromOption($,q){let z=q.attributeName();if(!this.dualOptions.has(z))return!0;let J=this.negativeOptions.get(z).presetArg,Q=J!==void 0?J:!1;return q.negate===(Q===$)}}function s($){return $.split("-").reduce((q,z)=>{return q+z[0].toUpperCase()+z.slice(1)})}function x1($){let q,z,J=/^-[^-]$/,Q=/^--[^-]/,X=$.split(/[ |,]+/).concat("guard");if(J.test(X[0]))q=X.shift();if(Q.test(X[0]))z=X.shift();if(!q&&J.test(X[0]))q=X.shift();if(!q&&Q.test(X[0]))q=z,z=X.shift();if(X[0].startsWith("-")){let Y=X[0],Z=`option creation failed due to '${Y}' in option flags '${$}'`;if(/^-[^-][^-]/.test(Y))throw new Error(`${Z}
7
7
  - a short flag is a single dash and a single character
8
8
  - either use a single dash and a single character (for a short flag)
9
- - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(z.test(Y))throw new Error(`${Z}
9
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(J.test(Y))throw new Error(`${Z}
10
10
  - too many short flags`);if(Q.test(Y))throw new Error(`${Z}
11
11
  - too many long flags`);throw new Error(`${Z}
12
- - unrecognised flag format`)}if(q===void 0&&J===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:q,longFlag:J}}b1.Option=i;b1.DualOptions=t});var n=U((u1)=>{function v1($,q){if(Math.abs($.length-q.length)>3)return Math.max($.length,q.length);let J=[];for(let z=0;z<=$.length;z++)J[z]=[z];for(let z=0;z<=q.length;z++)J[0][z]=z;for(let z=1;z<=q.length;z++)for(let Q=1;Q<=$.length;Q++){let X=1;if($[Q-1]===q[z-1])X=0;else X=1;if(J[Q][z]=Math.min(J[Q-1][z]+1,J[Q][z-1]+1,J[Q-1][z-1]+X),Q>1&&z>1&&$[Q-1]===q[z-2]&&$[Q-2]===q[z-1])J[Q][z]=Math.min(J[Q][z],J[Q-2][z-2]+1)}return J[$.length][q.length]}function h1($,q){if(!q||q.length===0)return"";q=Array.from(new Set(q));let J=$.startsWith("--");if(J)$=$.slice(2),q=q.map((Y)=>Y.slice(2));let z=[],Q=3,X=0.4;if(q.forEach((Y)=>{if(Y.length<=1)return;let Z=v1($,Y),_=Math.max($.length,Y.length);if((_-Z)/_>X){if(Z<Q)Q=Z,z=[Y];else if(Z===Q)z.push(Y)}}),z.sort((Y,Z)=>Y.localeCompare(Z)),J)z=z.map((Y)=>`--${Y}`);if(z.length>1)return`
13
- (Did you mean one of ${z.join(", ")}?)`;if(z.length===1)return`
14
- (Did you mean ${z[0]}?)`;return""}u1.suggestSimilar=h1});var e=U((i1)=>{var l1=I("node:events").EventEmitter,k=I("node:child_process"),M=I("node:path"),F=I("node:fs"),B=I("node:process"),{Argument:c1,humanReadableArgName:m1}=y(),{CommanderError:O}=E(),{Help:d1,stripColor:p1}=A(),{Option:a,DualOptions:s1}=P(),{suggestSimilar:r}=n();class b extends l1{constructor($){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=$||"",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:(q)=>B.stdout.write(q),writeErr:(q)=>B.stderr.write(q),outputError:(q,J)=>J(q),getOutHelpWidth:()=>B.stdout.isTTY?B.stdout.columns:void 0,getErrHelpWidth:()=>B.stderr.isTTY?B.stderr.columns:void 0,getOutHasColors:()=>x()??(B.stdout.isTTY&&B.stdout.hasColors?.()),getErrHasColors:()=>x()??(B.stderr.isTTY&&B.stderr.hasColors?.()),stripColor:(q)=>p1(q)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let q=this;q;q=q.parent)$.push(q);return $}command($,q,J){let z=q,Q=J;if(typeof z==="object"&&z!==null)Q=z,z=null;Q=Q||{};let[,X,Y]=$.match(/([^ ]+) *(.*)/),Z=this.createCommand(X);if(z)Z.description(z),Z._executableHandler=!0;if(Q.isDefault)this._defaultCommandName=Z._name;if(Z._hidden=!!(Q.noHelp||Q.hidden),Z._executableFile=Q.executableFile||null,Y)Z.arguments(Y);if(this._registerCommand(Z),Z.parent=this,Z.copyInheritedSettings(this),z)return this;return Z}createCommand($){return new b($)}createHelp(){return Object.assign(new d1,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...$},this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,q){if(!$._name)throw new Error(`Command passed to .addCommand() must have a name
15
- - specify the name in Command constructor or using .name()`);if(q=q||{},q.isDefault)this._defaultCommandName=$._name;if(q.noHelp||q.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,q){return new c1($,q)}argument($,q,J,z){let Q=this.createArgument($,q);if(typeof J==="function")Q.default(z).argParser(J);else Q.default(J);return this.addArgument(Q),this}arguments($){return $.trim().split(/ +/).forEach((q)=>{this.argument(q)}),this}addArgument($){let q=this.registeredArguments.slice(-1)[0];if(q?.variadic)throw new Error(`only the last argument can be variadic '${q.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,q){if(typeof $==="boolean"){if(this._addImplicitHelpCommand=$,$&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let J=$??"help [command]",[,z,Q]=J.match(/([^ ]+) *(.*)/),X=q??"display help for command",Y=this.createCommand(z);if(Y.helpOption(!1),Q)Y.arguments(Q);if(X)Y.description(X);if(this._addImplicitHelpCommand=!0,this._helpCommand=Y,$||q)this._initCommandGroup(Y);return this}addHelpCommand($,q){if(typeof $!=="object")return this.helpCommand($,q),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this._initCommandGroup($),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 J=["preSubcommand","preAction","postAction"];if(!J.includes($))throw new Error(`Unexpected value for event passed to hook : '${$}'.
16
- Expecting one of '${J.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(q);else this._lifeCycleHooks[$]=[q];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(q)=>{if(q.code!=="commander.executeSubCommandAsync")throw q};return this}_exit($,q,J){if(this._exitCallback)this._exitCallback(new O($,q,J));B.exit($)}action($){let q=(J)=>{let z=this.registeredArguments.length,Q=J.slice(0,z);if(this._storeOptionsAsProperties)Q[z]=this;else Q[z]=this.opts();return Q.push(this),$.apply(this,Q)};return this._actionHandler=q,this}createOption($,q){return new a($,q)}_callParseArg($,q,J,z){try{return $.parseArg(q,J)}catch(Q){if(Q.code==="commander.invalidArgument"){let X=`${z} ${Q.message}`;this.error(X,{exitCode:Q.exitCode,code:Q.code})}throw Q}}_registerOption($){let q=$.short&&this._findOption($.short)||$.long&&this._findOption($.long);if(q){let J=$.long&&this._findOption($.long)?$.long:$.short;throw new Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${J}'
17
- - already used by option '${q.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let q=(z)=>{return[z.name()].concat(z.aliases())},J=q($).find((z)=>this._findCommand(z));if(J){let z=q(this._findCommand(J)).join("|"),Q=q($).join("|");throw new Error(`cannot add command '${Q}' as already have command '${z}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let q=$.name(),J=$.attributeName();if($.negate){let Q=$.long.replace(/^--no-/,"--");if(!this._findOption(Q))this.setOptionValueWithSource(J,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(J,$.defaultValue,"default");let z=(Q,X,Y)=>{if(Q==null&&$.presetArg!==void 0)Q=$.presetArg;let Z=this.getOptionValue(J);if(Q!==null&&$.parseArg)Q=this._callParseArg($,Q,Z,X);else if(Q!==null&&$.variadic)Q=$._collectValue(Q,Z);if(Q==null)if($.negate)Q=!1;else if($.isBoolean()||$.optional)Q=!0;else Q="";this.setOptionValueWithSource(J,Q,Y)};if(this.on("option:"+q,(Q)=>{let X=`error: option '${$.flags}' argument '${Q}' is invalid.`;z(Q,X,"cli")}),$.envVar)this.on("optionEnv:"+q,(Q)=>{let X=`error: option '${$.flags}' value '${Q}' from env '${$.envVar}' is invalid.`;z(Q,X,"env")});return this}_optionEx($,q,J,z,Q){if(typeof q==="object"&&q instanceof a)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let X=this.createOption(q,J);if(X.makeOptionMandatory(!!$.mandatory),typeof z==="function")X.default(Q).argParser(z);else if(z instanceof RegExp){let Y=z;z=(Z,_)=>{let R=Y.exec(Z);return R?R[0]:_},X.default(Q).argParser(z)}else X.default(z);return this.addOption(X)}option($,q,J,z){return this._optionEx({},$,q,J,z)}requiredOption($,q,J,z){return this._optionEx({mandatory:!0},$,q,J,z)}combineFlagAndOptionalValue($=!0){return this._combineFlagAndOptionalValue=!!$,this}allowUnknownOption($=!0){return this._allowUnknownOption=!!$,this}allowExcessArguments($=!0){return this._allowExcessArguments=!!$,this}enablePositionalOptions($=!0){return this._enablePositionalOptions=!!$,this}passThroughOptions($=!0){return this._passThroughOptions=!!$,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($=!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=!!$,this}getOptionValue($){if(this._storeOptionsAsProperties)return this[$];return this._optionValues[$]}setOptionValue($,q){return this.setOptionValueWithSource($,q,void 0)}setOptionValueWithSource($,q,J){if(this._storeOptionsAsProperties)this[$]=q;else this._optionValues[$]=q;return this._optionValueSources[$]=J,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let q;return this._getCommandAndAncestors().forEach((J)=>{if(J.getOptionValueSource($)!==void 0)q=J.getOptionValueSource($)}),q}_prepareUserArgs($,q){if($!==void 0&&!Array.isArray($))throw new Error("first parameter to parse must be array or undefined");if(q=q||{},$===void 0&&q.from===void 0){if(B.versions?.electron)q.from="electron";let z=B.execArgv??[];if(z.includes("-e")||z.includes("--eval")||z.includes("-p")||z.includes("--print"))q.from="eval"}if($===void 0)$=B.argv;this.rawArgs=$.slice();let J;switch(q.from){case void 0:case"node":this._scriptPath=$[1],J=$.slice(2);break;case"electron":if(B.defaultApp)this._scriptPath=$[1],J=$.slice(2);else J=$.slice(1);break;case"user":J=$.slice(0);break;case"eval":J=$.slice(1);break;default:throw new Error(`unexpected parse option { from: '${q.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",J}parse($,q){this._prepareForParse();let J=this._prepareUserArgs($,q);return this._parseCommand([],J),this}async parseAsync($,q){this._prepareForParse();let J=this._prepareUserArgs($,q);return await this._parseCommand([],J),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.
18
- - 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,J){if(F.existsSync($))return;let z=q?`searched for local subcommand relative to directory '${q}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",Q=`'${$}' does not exist
19
- - if '${J}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
12
+ - unrecognised flag format`)}if(q===void 0&&z===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:q,longFlag:z}}b1.Option=i;b1.DualOptions=t});var n=U((u1)=>{function v1($,q){if(Math.abs($.length-q.length)>3)return Math.max($.length,q.length);let z=[];for(let J=0;J<=$.length;J++)z[J]=[J];for(let J=0;J<=q.length;J++)z[0][J]=J;for(let J=1;J<=q.length;J++)for(let Q=1;Q<=$.length;Q++){let X=1;if($[Q-1]===q[J-1])X=0;else X=1;if(z[Q][J]=Math.min(z[Q-1][J]+1,z[Q][J-1]+1,z[Q-1][J-1]+X),Q>1&&J>1&&$[Q-1]===q[J-2]&&$[Q-2]===q[J-1])z[Q][J]=Math.min(z[Q][J],z[Q-2][J-2]+1)}return z[$.length][q.length]}function h1($,q){if(!q||q.length===0)return"";q=Array.from(new Set(q));let z=$.startsWith("--");if(z)$=$.slice(2),q=q.map((Y)=>Y.slice(2));let J=[],Q=3,X=0.4;if(q.forEach((Y)=>{if(Y.length<=1)return;let Z=v1($,Y),T=Math.max($.length,Y.length);if((T-Z)/T>X){if(Z<Q)Q=Z,J=[Y];else if(Z===Q)J.push(Y)}}),J.sort((Y,Z)=>Y.localeCompare(Z)),z)J=J.map((Y)=>`--${Y}`);if(J.length>1)return`
13
+ (Did you mean one of ${J.join(", ")}?)`;if(J.length===1)return`
14
+ (Did you mean ${J[0]}?)`;return""}u1.suggestSimilar=h1});var e=U((i1)=>{var l1=I("node:events").EventEmitter,k=I("node:child_process"),L=I("node:path"),F=I("node:fs"),_=I("node:process"),{Argument:c1,humanReadableArgName:m1}=y(),{CommanderError:O}=E(),{Help:d1,stripColor:p1}=A(),{Option:r,DualOptions:s1}=P(),{suggestSimilar:a}=n();class b extends l1{constructor($){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=$||"",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:(q)=>_.stdout.write(q),writeErr:(q)=>_.stderr.write(q),outputError:(q,z)=>z(q),getOutHelpWidth:()=>_.stdout.isTTY?_.stdout.columns:void 0,getErrHelpWidth:()=>_.stderr.isTTY?_.stderr.columns:void 0,getOutHasColors:()=>x()??(_.stdout.isTTY&&_.stdout.hasColors?.()),getErrHasColors:()=>x()??(_.stderr.isTTY&&_.stderr.hasColors?.()),stripColor:(q)=>p1(q)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let q=this;q;q=q.parent)$.push(q);return $}command($,q,z){let J=q,Q=z;if(typeof J==="object"&&J!==null)Q=J,J=null;Q=Q||{};let[,X,Y]=$.match(/([^ ]+) *(.*)/),Z=this.createCommand(X);if(J)Z.description(J),Z._executableHandler=!0;if(Q.isDefault)this._defaultCommandName=Z._name;if(Z._hidden=!!(Q.noHelp||Q.hidden),Z._executableFile=Q.executableFile||null,Y)Z.arguments(Y);if(this._registerCommand(Z),Z.parent=this,Z.copyInheritedSettings(this),J)return this;return Z}createCommand($){return new b($)}createHelp(){return Object.assign(new d1,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...$},this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,q){if(!$._name)throw new Error(`Command passed to .addCommand() must have a name
15
+ - specify the name in Command constructor or using .name()`);if(q=q||{},q.isDefault)this._defaultCommandName=$._name;if(q.noHelp||q.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,q){return new c1($,q)}argument($,q,z,J){let Q=this.createArgument($,q);if(typeof z==="function")Q.default(J).argParser(z);else Q.default(z);return this.addArgument(Q),this}arguments($){return $.trim().split(/ +/).forEach((q)=>{this.argument(q)}),this}addArgument($){let q=this.registeredArguments.slice(-1)[0];if(q?.variadic)throw new Error(`only the last argument can be variadic '${q.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,q){if(typeof $==="boolean"){if(this._addImplicitHelpCommand=$,$&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let z=$??"help [command]",[,J,Q]=z.match(/([^ ]+) *(.*)/),X=q??"display help for command",Y=this.createCommand(J);if(Y.helpOption(!1),Q)Y.arguments(Q);if(X)Y.description(X);if(this._addImplicitHelpCommand=!0,this._helpCommand=Y,$||q)this._initCommandGroup(Y);return this}addHelpCommand($,q){if(typeof $!=="object")return this.helpCommand($,q),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this._initCommandGroup($),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($))throw new Error(`Unexpected value for event passed to hook : '${$}'.
16
+ Expecting one of '${z.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(q);else this._lifeCycleHooks[$]=[q];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(q)=>{if(q.code!=="commander.executeSubCommandAsync")throw q};return this}_exit($,q,z){if(this._exitCallback)this._exitCallback(new O($,q,z));_.exit($)}action($){let q=(z)=>{let J=this.registeredArguments.length,Q=z.slice(0,J);if(this._storeOptionsAsProperties)Q[J]=this;else Q[J]=this.opts();return Q.push(this),$.apply(this,Q)};return this._actionHandler=q,this}createOption($,q){return new r($,q)}_callParseArg($,q,z,J){try{return $.parseArg(q,z)}catch(Q){if(Q.code==="commander.invalidArgument"){let X=`${J} ${Q.message}`;this.error(X,{exitCode:Q.exitCode,code:Q.code})}throw Q}}_registerOption($){let q=$.short&&this._findOption($.short)||$.long&&this._findOption($.long);if(q){let z=$.long&&this._findOption($.long)?$.long:$.short;throw new Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${z}'
17
+ - already used by option '${q.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let q=(J)=>{return[J.name()].concat(J.aliases())},z=q($).find((J)=>this._findCommand(J));if(z){let J=q(this._findCommand(z)).join("|"),Q=q($).join("|");throw new Error(`cannot add command '${Q}' as already have command '${J}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let q=$.name(),z=$.attributeName();if($.negate){let Q=$.long.replace(/^--no-/,"--");if(!this._findOption(Q))this.setOptionValueWithSource(z,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(z,$.defaultValue,"default");let J=(Q,X,Y)=>{if(Q==null&&$.presetArg!==void 0)Q=$.presetArg;let Z=this.getOptionValue(z);if(Q!==null&&$.parseArg)Q=this._callParseArg($,Q,Z,X);else if(Q!==null&&$.variadic)Q=$._collectValue(Q,Z);if(Q==null)if($.negate)Q=!1;else if($.isBoolean()||$.optional)Q=!0;else Q="";this.setOptionValueWithSource(z,Q,Y)};if(this.on("option:"+q,(Q)=>{let X=`error: option '${$.flags}' argument '${Q}' is invalid.`;J(Q,X,"cli")}),$.envVar)this.on("optionEnv:"+q,(Q)=>{let X=`error: option '${$.flags}' value '${Q}' from env '${$.envVar}' is invalid.`;J(Q,X,"env")});return this}_optionEx($,q,z,J,Q){if(typeof q==="object"&&q instanceof r)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let X=this.createOption(q,z);if(X.makeOptionMandatory(!!$.mandatory),typeof J==="function")X.default(Q).argParser(J);else if(J instanceof RegExp){let Y=J;J=(Z,T)=>{let H=Y.exec(Z);return H?H[0]:T},X.default(Q).argParser(J)}else X.default(J);return this.addOption(X)}option($,q,z,J){return this._optionEx({},$,q,z,J)}requiredOption($,q,z,J){return this._optionEx({mandatory:!0},$,q,z,J)}combineFlagAndOptionalValue($=!0){return this._combineFlagAndOptionalValue=!!$,this}allowUnknownOption($=!0){return this._allowUnknownOption=!!$,this}allowExcessArguments($=!0){return this._allowExcessArguments=!!$,this}enablePositionalOptions($=!0){return this._enablePositionalOptions=!!$,this}passThroughOptions($=!0){return this._passThroughOptions=!!$,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($=!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=!!$,this}getOptionValue($){if(this._storeOptionsAsProperties)return this[$];return this._optionValues[$]}setOptionValue($,q){return this.setOptionValueWithSource($,q,void 0)}setOptionValueWithSource($,q,z){if(this._storeOptionsAsProperties)this[$]=q;else this._optionValues[$]=q;return this._optionValueSources[$]=z,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let q;return this._getCommandAndAncestors().forEach((z)=>{if(z.getOptionValueSource($)!==void 0)q=z.getOptionValueSource($)}),q}_prepareUserArgs($,q){if($!==void 0&&!Array.isArray($))throw new Error("first parameter to parse must be array or undefined");if(q=q||{},$===void 0&&q.from===void 0){if(_.versions?.electron)q.from="electron";let J=_.execArgv??[];if(J.includes("-e")||J.includes("--eval")||J.includes("-p")||J.includes("--print"))q.from="eval"}if($===void 0)$=_.argv;this.rawArgs=$.slice();let z;switch(q.from){case void 0:case"node":this._scriptPath=$[1],z=$.slice(2);break;case"electron":if(_.defaultApp)this._scriptPath=$[1],z=$.slice(2);else z=$.slice(1);break;case"user":z=$.slice(0);break;case"eval":z=$.slice(1);break;default:throw new Error(`unexpected parse option { from: '${q.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.
18
+ - 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(F.existsSync($))return;let J=q?`searched for local subcommand relative to directory '${q}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",Q=`'${$}' does not exist
19
+ - if '${z}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
20
20
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
21
- - ${z}`;throw new Error(Q)}_executeSubCommand($,q){q=q.slice();let J=!1,z=[".js",".ts",".tsx",".mjs",".cjs"];function Q(R,H){let T=M.resolve(R,H);if(F.existsSync(T))return T;if(z.includes(M.extname(H)))return;let G=z.find((L)=>F.existsSync(`${T}${L}`));if(G)return`${T}${G}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let X=$._executableFile||`${this._name}-${$._name}`,Y=this._executableDir||"";if(this._scriptPath){let R;try{R=F.realpathSync(this._scriptPath)}catch{R=this._scriptPath}Y=M.resolve(M.dirname(R),Y)}if(Y){let R=Q(Y,X);if(!R&&!$._executableFile&&this._scriptPath){let H=M.basename(this._scriptPath,M.extname(this._scriptPath));if(H!==this._name)R=Q(Y,`${H}-${$._name}`)}X=R||X}J=z.includes(M.extname(X));let Z;if(B.platform!=="win32")if(J)q.unshift(X),q=o(B.execArgv).concat(q),Z=k.spawn(B.argv[0],q,{stdio:"inherit"});else Z=k.spawn(X,q,{stdio:"inherit"});else this._checkForMissingExecutable(X,Y,$._name),q.unshift(X),q=o(B.execArgv).concat(q),Z=k.spawn(B.execPath,q,{stdio:"inherit"});if(!Z.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((H)=>{B.on(H,()=>{if(Z.killed===!1&&Z.exitCode===null)Z.kill(H)})});let _=this._exitCallback;Z.on("close",(R)=>{if(R=R??1,!_)B.exit(R);else _(new O(R,"commander.executeSubCommandAsync","(close)"))}),Z.on("error",(R)=>{if(R.code==="ENOENT")this._checkForMissingExecutable(X,Y,$._name);else if(R.code==="EACCES")throw new Error(`'${X}' not executable`);if(!_)B.exit(1);else{let H=new O(1,"commander.executeSubCommandAsync","(error)");H.nestedError=R,_(H)}}),this.runningCommand=Z}_dispatchSubcommand($,q,J){let z=this._findCommand($);if(!z)this.help({error:!0});z._prepareForParse();let Q;return Q=this._chainOrCallSubCommandHook(Q,z,"preSubcommand"),Q=this._chainOrCall(Q,()=>{if(z._executableHandler)this._executeSubCommand(z,q.concat(J));else return z._parseCommand(q,J)}),Q}_dispatchHelpCommand($){if(!$)this.help();let q=this._findCommand($);if(q&&!q._executableHandler)q.help();return this._dispatchSubcommand($,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach(($,q)=>{if($.required&&this.args[q]==null)this.missingArgument($.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 $=(J,z,Q)=>{let X=z;if(z!==null&&J.parseArg){let Y=`error: command-argument value '${z}' is invalid for argument '${J.name()}'.`;X=this._callParseArg(J,z,Q,Y)}return X};this._checkNumberOfArguments();let q=[];this.registeredArguments.forEach((J,z)=>{let Q=J.defaultValue;if(J.variadic){if(z<this.args.length){if(Q=this.args.slice(z),J.parseArg)Q=Q.reduce((X,Y)=>{return $(J,Y,X)},J.defaultValue)}else if(Q===void 0)Q=[]}else if(z<this.args.length){if(Q=this.args[z],J.parseArg)Q=$(J,Q,J.defaultValue)}q[z]=Q}),this.processedArgs=q}_chainOrCall($,q){if($?.then&&typeof $.then==="function")return $.then(()=>q());return q()}_chainOrCallHooks($,q){let J=$,z=[];if(this._getCommandAndAncestors().reverse().filter((Q)=>Q._lifeCycleHooks[q]!==void 0).forEach((Q)=>{Q._lifeCycleHooks[q].forEach((X)=>{z.push({hookedCommand:Q,callback:X})})}),q==="postAction")z.reverse();return z.forEach((Q)=>{J=this._chainOrCall(J,()=>{return Q.callback(Q.hookedCommand,this)})}),J}_chainOrCallSubCommandHook($,q,J){let z=$;if(this._lifeCycleHooks[J]!==void 0)this._lifeCycleHooks[J].forEach((Q)=>{z=this._chainOrCall(z,()=>{return Q(this,q)})});return z}_parseCommand($,q){let J=this.parseOptions(q);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(J.operands),q=J.unknown,this.args=$.concat(q),$&&this._findCommand($[0]))return this._dispatchSubcommand($[0],$.slice(1),q);if(this._getHelpCommand()&&$[0]===this._getHelpCommand().name())return this._dispatchHelpCommand($[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(q),this._dispatchSubcommand(this._defaultCommandName,$,q);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(J.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let z=()=>{if(J.unknown.length>0)this.unknownOption(J.unknown[0])},Q=`command:${this.name()}`;if(this._actionHandler){z(),this._processArguments();let X;if(X=this._chainOrCallHooks(X,"preAction"),X=this._chainOrCall(X,()=>this._actionHandler(this.processedArgs)),this.parent)X=this._chainOrCall(X,()=>{this.parent.emit(Q,$,q)});return X=this._chainOrCallHooks(X,"postAction"),X}if(this.parent?.listenerCount(Q))z(),this._processArguments(),this.parent.emit(Q,$,q);else if($.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",$,q);if(this.listenerCount("command:*"))this.emit("command:*",$,q);else if(this.commands.length)this.unknownCommand();else z(),this._processArguments()}else if(this.commands.length)z(),this.help({error:!0});else z(),this._processArguments()}_findCommand($){if(!$)return;return this.commands.find((q)=>q._name===$||q._aliases.includes($))}_findOption($){return this.options.find((q)=>q.is($))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(($)=>{$.options.forEach((q)=>{if(q.mandatory&&$.getOptionValue(q.attributeName())===void 0)$.missingMandatoryOptionValue(q)})})}_checkForConflictingLocalOptions(){let $=this.options.filter((J)=>{let z=J.attributeName();if(this.getOptionValue(z)===void 0)return!1;return this.getOptionValueSource(z)!=="default"});$.filter((J)=>J.conflictsWith.length>0).forEach((J)=>{let z=$.find((Q)=>J.conflictsWith.includes(Q.attributeName()));if(z)this._conflictingOption(J,z)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let q=[],J=[],z=q;function Q(R){return R.length>1&&R[0]==="-"}let X=(R)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(R))return!1;return!this._getCommandAndAncestors().some((H)=>H.options.map((T)=>T.short).some((T)=>/^-\d$/.test(T)))},Y=null,Z=null,_=0;while(_<$.length||Z){let R=Z??$[_++];if(Z=null,R==="--"){if(z===J)z.push(R);z.push(...$.slice(_));break}if(Y&&(!Q(R)||X(R))){this.emit(`option:${Y.name()}`,R);continue}if(Y=null,Q(R)){let H=this._findOption(R);if(H){if(H.required){let T=$[_++];if(T===void 0)this.optionMissingArgument(H);this.emit(`option:${H.name()}`,T)}else if(H.optional){let T=null;if(_<$.length&&(!Q($[_])||X($[_])))T=$[_++];this.emit(`option:${H.name()}`,T)}else this.emit(`option:${H.name()}`);Y=H.variadic?H:null;continue}}if(R.length>2&&R[0]==="-"&&R[1]!=="-"){let H=this._findOption(`-${R[1]}`);if(H){if(H.required||H.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${H.name()}`,R.slice(2));else this.emit(`option:${H.name()}`),Z=`-${R.slice(2)}`;continue}}if(/^--[^=]+=/.test(R)){let H=R.indexOf("="),T=this._findOption(R.slice(0,H));if(T&&(T.required||T.optional)){this.emit(`option:${T.name()}`,R.slice(H+1));continue}}if(z===q&&Q(R)&&!(this.commands.length===0&&X(R)))z=J;if((this._enablePositionalOptions||this._passThroughOptions)&&q.length===0&&J.length===0){if(this._findCommand(R)){q.push(R),J.push(...$.slice(_));break}else if(this._getHelpCommand()&&R===this._getHelpCommand().name()){q.push(R,...$.slice(_));break}else if(this._defaultCommandName){J.push(R,...$.slice(_));break}}if(this._passThroughOptions){z.push(R,...$.slice(_));break}z.push(R)}return{operands:q,unknown:J}}opts(){if(this._storeOptionsAsProperties){let $={},q=this.options.length;for(let J=0;J<q;J++){let z=this.options[J].attributeName();$[z]=z===this._versionOptionName?this._version:this[z]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,q)=>Object.assign($,q.opts()),{})}error($,q){if(this._outputConfiguration.outputError(`${$}
21
+ - ${J}`;throw new Error(Q)}_executeSubCommand($,q){q=q.slice();let z=!1,J=[".js",".ts",".tsx",".mjs",".cjs"];function Q(H,R){let B=L.resolve(H,R);if(F.existsSync(B))return B;if(J.includes(L.extname(R)))return;let G=J.find((M)=>F.existsSync(`${B}${M}`));if(G)return`${B}${G}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let X=$._executableFile||`${this._name}-${$._name}`,Y=this._executableDir||"";if(this._scriptPath){let H;try{H=F.realpathSync(this._scriptPath)}catch{H=this._scriptPath}Y=L.resolve(L.dirname(H),Y)}if(Y){let H=Q(Y,X);if(!H&&!$._executableFile&&this._scriptPath){let R=L.basename(this._scriptPath,L.extname(this._scriptPath));if(R!==this._name)H=Q(Y,`${R}-${$._name}`)}X=H||X}z=J.includes(L.extname(X));let Z;if(_.platform!=="win32")if(z)q.unshift(X),q=o(_.execArgv).concat(q),Z=k.spawn(_.argv[0],q,{stdio:"inherit"});else Z=k.spawn(X,q,{stdio:"inherit"});else this._checkForMissingExecutable(X,Y,$._name),q.unshift(X),q=o(_.execArgv).concat(q),Z=k.spawn(_.execPath,q,{stdio:"inherit"});if(!Z.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((R)=>{_.on(R,()=>{if(Z.killed===!1&&Z.exitCode===null)Z.kill(R)})});let T=this._exitCallback;Z.on("close",(H)=>{if(H=H??1,!T)_.exit(H);else T(new O(H,"commander.executeSubCommandAsync","(close)"))}),Z.on("error",(H)=>{if(H.code==="ENOENT")this._checkForMissingExecutable(X,Y,$._name);else if(H.code==="EACCES")throw new Error(`'${X}' not executable`);if(!T)_.exit(1);else{let R=new O(1,"commander.executeSubCommandAsync","(error)");R.nestedError=H,T(R)}}),this.runningCommand=Z}_dispatchSubcommand($,q,z){let J=this._findCommand($);if(!J)this.help({error:!0});J._prepareForParse();let Q;return Q=this._chainOrCallSubCommandHook(Q,J,"preSubcommand"),Q=this._chainOrCall(Q,()=>{if(J._executableHandler)this._executeSubCommand(J,q.concat(z));else return J._parseCommand(q,z)}),Q}_dispatchHelpCommand($){if(!$)this.help();let q=this._findCommand($);if(q&&!q._executableHandler)q.help();return this._dispatchSubcommand($,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach(($,q)=>{if($.required&&this.args[q]==null)this.missingArgument($.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 $=(z,J,Q)=>{let X=J;if(J!==null&&z.parseArg){let Y=`error: command-argument value '${J}' is invalid for argument '${z.name()}'.`;X=this._callParseArg(z,J,Q,Y)}return X};this._checkNumberOfArguments();let q=[];this.registeredArguments.forEach((z,J)=>{let Q=z.defaultValue;if(z.variadic){if(J<this.args.length){if(Q=this.args.slice(J),z.parseArg)Q=Q.reduce((X,Y)=>{return $(z,Y,X)},z.defaultValue)}else if(Q===void 0)Q=[]}else if(J<this.args.length){if(Q=this.args[J],z.parseArg)Q=$(z,Q,z.defaultValue)}q[J]=Q}),this.processedArgs=q}_chainOrCall($,q){if($?.then&&typeof $.then==="function")return $.then(()=>q());return q()}_chainOrCallHooks($,q){let z=$,J=[];if(this._getCommandAndAncestors().reverse().filter((Q)=>Q._lifeCycleHooks[q]!==void 0).forEach((Q)=>{Q._lifeCycleHooks[q].forEach((X)=>{J.push({hookedCommand:Q,callback:X})})}),q==="postAction")J.reverse();return J.forEach((Q)=>{z=this._chainOrCall(z,()=>{return Q.callback(Q.hookedCommand,this)})}),z}_chainOrCallSubCommandHook($,q,z){let J=$;if(this._lifeCycleHooks[z]!==void 0)this._lifeCycleHooks[z].forEach((Q)=>{J=this._chainOrCall(J,()=>{return Q(this,q)})});return J}_parseCommand($,q){let z=this.parseOptions(q);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(z.operands),q=z.unknown,this.args=$.concat(q),$&&this._findCommand($[0]))return this._dispatchSubcommand($[0],$.slice(1),q);if(this._getHelpCommand()&&$[0]===this._getHelpCommand().name())return this._dispatchHelpCommand($[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(q),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 J=()=>{if(z.unknown.length>0)this.unknownOption(z.unknown[0])},Q=`command:${this.name()}`;if(this._actionHandler){J(),this._processArguments();let X;if(X=this._chainOrCallHooks(X,"preAction"),X=this._chainOrCall(X,()=>this._actionHandler(this.processedArgs)),this.parent)X=this._chainOrCall(X,()=>{this.parent.emit(Q,$,q)});return X=this._chainOrCallHooks(X,"postAction"),X}if(this.parent?.listenerCount(Q))J(),this._processArguments(),this.parent.emit(Q,$,q);else if($.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",$,q);if(this.listenerCount("command:*"))this.emit("command:*",$,q);else if(this.commands.length)this.unknownCommand();else J(),this._processArguments()}else if(this.commands.length)J(),this.help({error:!0});else J(),this._processArguments()}_findCommand($){if(!$)return;return this.commands.find((q)=>q._name===$||q._aliases.includes($))}_findOption($){return this.options.find((q)=>q.is($))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(($)=>{$.options.forEach((q)=>{if(q.mandatory&&$.getOptionValue(q.attributeName())===void 0)$.missingMandatoryOptionValue(q)})})}_checkForConflictingLocalOptions(){let $=this.options.filter((z)=>{let J=z.attributeName();if(this.getOptionValue(J)===void 0)return!1;return this.getOptionValueSource(J)!=="default"});$.filter((z)=>z.conflictsWith.length>0).forEach((z)=>{let J=$.find((Q)=>z.conflictsWith.includes(Q.attributeName()));if(J)this._conflictingOption(z,J)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let q=[],z=[],J=q;function Q(H){return H.length>1&&H[0]==="-"}let X=(H)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(H))return!1;return!this._getCommandAndAncestors().some((R)=>R.options.map((B)=>B.short).some((B)=>/^-\d$/.test(B)))},Y=null,Z=null,T=0;while(T<$.length||Z){let H=Z??$[T++];if(Z=null,H==="--"){if(J===z)J.push(H);J.push(...$.slice(T));break}if(Y&&(!Q(H)||X(H))){this.emit(`option:${Y.name()}`,H);continue}if(Y=null,Q(H)){let R=this._findOption(H);if(R){if(R.required){let B=$[T++];if(B===void 0)this.optionMissingArgument(R);this.emit(`option:${R.name()}`,B)}else if(R.optional){let B=null;if(T<$.length&&(!Q($[T])||X($[T])))B=$[T++];this.emit(`option:${R.name()}`,B)}else this.emit(`option:${R.name()}`);Y=R.variadic?R:null;continue}}if(H.length>2&&H[0]==="-"&&H[1]!=="-"){let R=this._findOption(`-${H[1]}`);if(R){if(R.required||R.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${R.name()}`,H.slice(2));else this.emit(`option:${R.name()}`),Z=`-${H.slice(2)}`;continue}}if(/^--[^=]+=/.test(H)){let R=H.indexOf("="),B=this._findOption(H.slice(0,R));if(B&&(B.required||B.optional)){this.emit(`option:${B.name()}`,H.slice(R+1));continue}}if(J===q&&Q(H)&&!(this.commands.length===0&&X(H)))J=z;if((this._enablePositionalOptions||this._passThroughOptions)&&q.length===0&&z.length===0){if(this._findCommand(H)){q.push(H),z.push(...$.slice(T));break}else if(this._getHelpCommand()&&H===this._getHelpCommand().name()){q.push(H,...$.slice(T));break}else if(this._defaultCommandName){z.push(H,...$.slice(T));break}}if(this._passThroughOptions){J.push(H,...$.slice(T));break}J.push(H)}return{operands:q,unknown:z}}opts(){if(this._storeOptionsAsProperties){let $={},q=this.options.length;for(let z=0;z<q;z++){let J=this.options[z].attributeName();$[J]=J===this._versionOptionName?this._version:this[J]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,q)=>Object.assign($,q.opts()),{})}error($,q){if(this._outputConfiguration.outputError(`${$}
22
22
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
23
23
  `);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
24
- `),this.outputHelp({error:!0});let J=q||{},z=J.exitCode||1,Q=J.code||"commander.error";this._exit(z,Q,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in B.env){let q=$.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,B.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new s1(this.options),q=(J)=>{return this.getOptionValue(J)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(J))};this.options.filter((J)=>J.implied!==void 0&&q(J.attributeName())&&$.valueFromOption(this.getOptionValue(J.attributeName()),J)).forEach((J)=>{Object.keys(J.implied).filter((z)=>!q(z)).forEach((z)=>{this.setOptionValueWithSource(z,J.implied[z],"implied")})})}missingArgument($){let q=`error: missing required argument '${$}'`;this.error(q,{code:"commander.missingArgument"})}optionMissingArgument($){let q=`error: option '${$.flags}' argument missing`;this.error(q,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let q=`error: required option '${$.flags}' not specified`;this.error(q,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,q){let J=(X)=>{let Y=X.attributeName(),Z=this.getOptionValue(Y),_=this.options.find((H)=>H.negate&&Y===H.attributeName()),R=this.options.find((H)=>!H.negate&&Y===H.attributeName());if(_&&(_.presetArg===void 0&&Z===!1||_.presetArg!==void 0&&Z===_.presetArg))return _;return R||X},z=(X)=>{let Y=J(X),Z=Y.attributeName();if(this.getOptionValueSource(Z)==="env")return`environment variable '${Y.envVar}'`;return`option '${Y.flags}'`},Q=`error: ${z($)} cannot be used with ${z(q)}`;this.error(Q,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let q="";if($.startsWith("--")&&this._showSuggestionAfterError){let z=[],Q=this;do{let X=Q.createHelp().visibleOptions(Q).filter((Y)=>Y.long).map((Y)=>Y.long);z=z.concat(X),Q=Q.parent}while(Q&&!Q._enablePositionalOptions);q=r($,z)}let J=`error: unknown option '${$}'${q}`;this.error(J,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let q=this.registeredArguments.length,J=q===1?"":"s",Q=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${q} argument${J} but got ${$.length}.`;this.error(Q,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],q="";if(this._showSuggestionAfterError){let z=[];this.createHelp().visibleCommands(this).forEach((Q)=>{if(z.push(Q.name()),Q.alias())z.push(Q.alias())}),q=r($,z)}let J=`error: unknown command '${$}'${q}`;this.error(J,{code:"commander.unknownCommand"})}version($,q,J){if($===void 0)return this._version;this._version=$,q=q||"-V, --version",J=J||"output the version number";let z=this.createOption(q,J);return this._versionOptionName=z.attributeName(),this._registerOption(z),this.on("option:"+z.name(),()=>{this._outputConfiguration.writeOut(`${$}
25
- `),this._exit(0,"commander.version",$)}),this}description($,q){if($===void 0&&q===void 0)return this._description;if(this._description=$,q)this._argsDescription=q;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let q=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)q=this.commands[this.commands.length-1];if($===q._name)throw new Error("Command alias can't be the same as its name");let J=this.parent?._findCommand($);if(J){let z=[J.name()].concat(J.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${z}'`)}return q._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((q)=>this.alias(q)),this}usage($){if($===void 0){if(this._usage)return this._usage;let q=this.registeredArguments.map((J)=>{return m1(J)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?q:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}helpGroup($){if($===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=$,this}commandsGroup($){if($===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=$,this}optionsGroup($){if($===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=$,this}_initOptionGroup($){if(this._defaultOptionGroup&&!$.helpGroupHeading)$.helpGroup(this._defaultOptionGroup)}_initCommandGroup($){if(this._defaultCommandGroup&&!$.helpGroup())$.helpGroup(this._defaultCommandGroup)}nameFromFilename($){return this._name=M.basename($,M.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let q=this.createHelp(),J=this._getOutputContext($);q.prepareContext({error:J.error,helpWidth:J.helpWidth,outputHasColors:J.hasColors});let z=q.formatHelp(this,q);if(J.hasColors)return z;return this._outputConfiguration.stripColor(z)}_getOutputContext($){$=$||{};let q=!!$.error,J,z,Q;if(q)J=(Y)=>this._outputConfiguration.writeErr(Y),z=this._outputConfiguration.getErrHasColors(),Q=this._outputConfiguration.getErrHelpWidth();else J=(Y)=>this._outputConfiguration.writeOut(Y),z=this._outputConfiguration.getOutHasColors(),Q=this._outputConfiguration.getOutHelpWidth();return{error:q,write:(Y)=>{if(!z)Y=this._outputConfiguration.stripColor(Y);return J(Y)},hasColors:z,helpWidth:Q}}outputHelp($){let q;if(typeof $==="function")q=$,$=void 0;let J=this._getOutputContext($),z={error:J.error,write:J.write,command:this};this._getCommandAndAncestors().reverse().forEach((X)=>X.emit("beforeAllHelp",z)),this.emit("beforeHelp",z);let Q=this.helpInformation({error:J.error});if(q){if(Q=q(Q),typeof Q!=="string"&&!Buffer.isBuffer(Q))throw new Error("outputHelp callback must return a string or a Buffer")}if(J.write(Q),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",z),this._getCommandAndAncestors().forEach((X)=>X.emit("afterAllHelp",z))}helpOption($,q){if(typeof $==="boolean"){if($){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption($??"-h, --help",q??"display help for command"),$||q)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this._initOptionGroup($),this}help($){this.outputHelp($);let q=Number(B.exitCode??0);if(q===0&&$&&typeof $!=="function"&&$.error)q=1;this._exit(q,"commander.help","(outputHelp)")}addHelpText($,q){let J=["beforeAll","before","after","afterAll"];if(!J.includes($))throw new Error(`Unexpected value for position to addHelpText.
26
- Expecting one of '${J.join("', '")}'`);let z=`${$}Help`;return this.on(z,(Q)=>{let X;if(typeof q==="function")X=q({error:Q.error,command:Q.command});else X=q;if(X)Q.write(`${X}
27
- `)}),this}_outputHelpIfRequested($){let q=this._getHelpOption();if(q&&$.find((z)=>q.is(z)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function o($){return $.map((q)=>{if(!q.startsWith("--inspect"))return q;let J,z="127.0.0.1",Q="9229",X;if((X=q.match(/^(--inspect(-brk)?)$/))!==null)J=X[1];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(J=X[1],/^\d+$/.test(X[3]))Q=X[3];else z=X[3];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)J=X[1],z=X[3],Q=X[4];if(J&&Q!=="0")return`${J}=${z}:${parseInt(Q)+1}`;return q})}function x(){if(B.env.NO_COLOR||B.env.FORCE_COLOR==="0"||B.env.FORCE_COLOR==="false")return!1;if(B.env.FORCE_COLOR||B.env.CLICOLOR_FORCE!==void 0)return!0;return}i1.Command=b;i1.useColor=x});var z1=U((o1)=>{var{Argument:$1}=y(),{Command:C}=e(),{CommanderError:a1,InvalidArgumentError:q1}=E(),{Help:r1}=A(),{Option:J1}=P();o1.program=new C;o1.createCommand=($)=>new C($);o1.createOption=($,q)=>new J1($,q);o1.createArgument=($,q)=>new $1($,q);o1.Command=C;o1.Option=J1;o1.Argument=$1;o1.Help=r1;o1.CommanderError=a1;o1.InvalidArgumentError=q1;o1.InvalidOptionArgumentError=q1});var Q1=K1(z1(),1),{program:C2,createCommand:f2,createArgument:v2,createOption:h2,CommanderError:u2,InvalidArgumentError:g2,InvalidOptionArgumentError:l2,Command:X1,Argument:c2,Option:m2,Help:d2}=Q1.default;import{join as V2}from"node:path";import{existsSync as Y1}from"node:fs";import{readFile as _2}from"node:fs/promises";import{dirname as Z1,join as R1,resolve as f}from"node:path";var T2=".gstatxrc.json";function v($){let J=$.replace(/\.git$/,"").split(/[/:]/);return J[J.length-1]||"repository"}function B2($){let q=f($),J=20,z=0;while(z<J){let Q=R1(q,T2);if(Y1(Q))return Q;let X=Z1(q);if(X===q)break;q=X,z++}return null}async function V($,q=process.cwd()){try{let J;if($){let Y=f($);if(!Y1(Y))return console.error(`Error: Config file not found: ${Y}`),null;J=Y}else if(J=B2(q),!J)return null;let z=await _2(J,"utf-8"),Q=JSON.parse(z),X=Z1(J);if(Q.repositories)Q.repositories=Q.repositories.map((Y)=>{if(!Y.path&&Y.url){let Z=v(Y.url);return{...Y,path:R1(X,Z),name:Y.name||Z}}if(Y.path)return{...Y,path:f(X,Y.path)};return Y});return{config:Q,configDir:X}}catch(J){if($)console.error(`Error: Failed to load config file: ${J}`);return null}}import{exec as G2,execSync as L2}from"node:child_process";import{access as M2}from"node:fs/promises";import{join as U2}from"node:path";import{promisify as S2}from"node:util";var H1=S2(G2);async function W($){try{return await M2(U2($,".git")),!0}catch{return!1}}async function h($){try{let{stdout:q}=await H1("git shortlog -sn --all",{cwd:$}),J=[],z=q.trim().split(`
28
- `);for(let Q of z){let X=Q.match(/^\s*(\d+)\s+(.+)$/);if(X){let Y=parseInt(X[1]||"0",10),Z=X[2]||"",{stdout:_}=await H1(`git log --format='%aE' --author="${Z.replace(/"/g,"\\\"")}" -1`,{cwd:$}),R=_.trim().split(`
29
- `)[0]||"";J.push({name:Z,email:R,commits:Y})}}return J.sort((Q,X)=>X.commits-Q.commits)}catch(q){throw new Error(`Failed to get contributors from ${$}: ${q}`)}}function u($,q,J){let z='git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat';if(q)z+=` --since="${q}"`;if(J)z+=` --until="${J}"`;let Q=L2(z,{encoding:"utf-8",cwd:$,maxBuffer:10485760}),X=[],Y=Q.split(`
30
- `).filter((G)=>G.trim()),Z=null,_=0,R=0,H=0,T=[];for(let G of Y)if(G.includes("|")){if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:_,insertions:R,deletions:H,files:T});let[L,S,K,j,...G1]=G.split("|");if(L&&S&&K&&j)Z={hash:L.trim(),author:S.trim(),email:K.trim(),date:j.trim(),message:G1.join("|").trim()},_=0,R=0,H=0,T=[]}else{let L=G.trim().split(/\s+/);if(L.length>=2&&L[0]&&L[1]){let S=parseInt(L[0],10)||0,K=parseInt(L[1],10)||0,j=L.slice(2).join(" ");if(j&&!Number.isNaN(S)&&!Number.isNaN(K))_++,R+=S,H+=K,T.push({path:j,insertions:S,deletions:K})}}if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:_,insertions:R,deletions:H,files:T});return X}import{exec as K2}from"node:child_process";import{existsSync as _1}from"node:fs";import{mkdir as W2}from"node:fs/promises";import{dirname as j2}from"node:path";import{promisify as I2}from"node:util";var E2=I2(K2);async function g($){if(!$.path)return console.error(`Error: Repository ${$.name||"unknown"} has no path specified`),null;if(_1($.path)&&await W($.path))return $.path;if(_1($.path))return console.error(`Error: Path exists but is not a git repository: ${$.path}`),null;if(!$.url)return console.error(`Error: Repository not found at ${$.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${$.url} to ${$.path}...`);let q=j2($.path),J=$.path.split("/").pop()||"repository";try{await W2(q,{recursive:!0})}catch(z){}return await E2(`git clone "${$.url}" "${$.path}"`),console.log(`✓ Successfully cloned ${$.name||J}`),$.path}catch(q){return console.error(`Error: Failed to clone repository: ${q}`),null}}class D{config;loadedConfig=null;constructor($={}){this.config=$}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await V(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map(($)=>{if(!$.path&&$.url){let q=this.loadedConfig?.configDir||process.cwd(),J=v($.url);return{...$,path:V2(q,J),name:$.name||J}}return $});if(this.config.cloneIfNotExists&&this.config.repositories){let $=[];for(let q of this.config.repositories){if(!q.path){console.error(`Error: Repository ${q.name||"unknown"} has no path and no URL`),$.push("");continue}let J=await g(q);if(J)$.push(J);else $.push(q.path)}this.config.repositories=this.config.repositories.map((q,J)=>({...q,path:$[J]||q.path}))}}getRepoPaths($){if($&&$.length>0)return $;if(this.config.repositories)return this.config.repositories.map((q)=>q.path).filter((q)=>q!==void 0);return[]}async listContributors($){await this.initialize();let q=this.getRepoPaths($);if(q.length===0)throw new Error("No repository paths specified");let J=[];for(let z of q){if(!await W(z))throw new Error(`${z} is not a git repository`);try{let X=await h(z);J.push({path:z,contributors:X})}catch(X){throw new Error(`Failed to get contributors from ${z}: ${X}`)}}return J}async getHistory($,q,J){await this.initialize();let z=this.getRepoPaths($);if(z.length===0)throw new Error("No repository paths specified");let Q=[];for(let X of z){if(!await W(X))throw new Error(`${X} is not a git repository`);try{let Z=u(X,q,J);Q.push({path:X,commits:Z})}catch(Z){throw new Error(`Failed to get commit history from ${X}: ${Z}`)}}return Q}}async function T1($,q=!0,J){let z=new D({configPath:J});try{let Q=await z.listContributors($);for(let X of Q)if(console.log(`
31
- \uD83D\uDCCA Contributors for ${X.path}:`),console.log("─".repeat(60)),X.contributors.length===0)console.log(" No contributors found");else for(let Y of X.contributors)if(q)console.log(` ${Y.name} <${Y.email}> (${Y.commits} commits)`);else console.log(` ${Y.name} <${Y.email}>`)}catch(Q){console.error("Error processing repositories:",Q)}}import{writeFileSync as D2}from"node:fs";import{resolve as N2}from"node:path";async function B1($,q={},J){let z=new D({configPath:J});try{let Q=await z.getHistory($,q.since,q.until),X={generatedAt:new Date().toISOString(),period:{since:q.since,until:q.until},repositories:Q.map((Z)=>{let _=new Set(Z.commits.flatMap((T)=>T.files.map((G)=>G.path))).size,R=Z.commits.reduce((T,G)=>T+G.insertions,0),H=Z.commits.reduce((T,G)=>T+G.deletions,0);return{path:Z.path,commits:Z.commits,summary:{totalCommits:Z.commits.length,totalFilesChanged:_,totalInsertions:R,totalDeletions:H}}})},Y=JSON.stringify(X,null,2);if(q.out){let Z=N2(process.cwd(),q.out);D2(Z,Y,"utf-8"),console.log(`✅ Report saved to: ${Z}`),console.log(`
32
- \uD83D\uDCCA Summary:`);for(let _ of X.repositories)console.log(`
33
- Repository: ${_.path}`),console.log(` Commits: ${_.summary.totalCommits}`),console.log(` Files Changed: ${_.summary.totalFilesChanged}`),console.log(` Lines Added: ${_.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${_.summary.totalDeletions.toLocaleString()}`)}else console.log(Y)}catch(Q){throw console.error("Error generating history report:",Q),Q}}var N=new X1;N.name("gstatx").description("A CLI tool to export statistics from git repositories").version("0.1.1").option("-c, --config <path>","Specify custom config file path").configureHelp({helpWidth:100});N.command("contributors").description("List contributors for specified repositories").option("--no-commits","Hide commit counts in contributor list").argument("[repo-paths...]","Repository paths").action(async($,q,J)=>{let z=J.parent?.opts().config,X=(await V(z))?.config.contributors?.["no-commits"]??!1,Y=!(q.noCommits||X),Z=$.length===0?void 0:$;await T1(Z,Y,z)}).addHelpText("after",`
24
+ `),this.outputHelp({error:!0});let z=q||{},J=z.exitCode||1,Q=z.code||"commander.error";this._exit(J,Q,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in _.env){let q=$.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,_.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new s1(this.options),q=(z)=>{return this.getOptionValue(z)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(z))};this.options.filter((z)=>z.implied!==void 0&&q(z.attributeName())&&$.valueFromOption(this.getOptionValue(z.attributeName()),z)).forEach((z)=>{Object.keys(z.implied).filter((J)=>!q(J)).forEach((J)=>{this.setOptionValueWithSource(J,z.implied[J],"implied")})})}missingArgument($){let q=`error: missing required argument '${$}'`;this.error(q,{code:"commander.missingArgument"})}optionMissingArgument($){let q=`error: option '${$.flags}' argument missing`;this.error(q,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let q=`error: required option '${$.flags}' not specified`;this.error(q,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,q){let z=(X)=>{let Y=X.attributeName(),Z=this.getOptionValue(Y),T=this.options.find((R)=>R.negate&&Y===R.attributeName()),H=this.options.find((R)=>!R.negate&&Y===R.attributeName());if(T&&(T.presetArg===void 0&&Z===!1||T.presetArg!==void 0&&Z===T.presetArg))return T;return H||X},J=(X)=>{let Y=z(X),Z=Y.attributeName();if(this.getOptionValueSource(Z)==="env")return`environment variable '${Y.envVar}'`;return`option '${Y.flags}'`},Q=`error: ${J($)} cannot be used with ${J(q)}`;this.error(Q,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let q="";if($.startsWith("--")&&this._showSuggestionAfterError){let J=[],Q=this;do{let X=Q.createHelp().visibleOptions(Q).filter((Y)=>Y.long).map((Y)=>Y.long);J=J.concat(X),Q=Q.parent}while(Q&&!Q._enablePositionalOptions);q=a($,J)}let z=`error: unknown option '${$}'${q}`;this.error(z,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let q=this.registeredArguments.length,z=q===1?"":"s",Q=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${q} argument${z} but got ${$.length}.`;this.error(Q,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],q="";if(this._showSuggestionAfterError){let J=[];this.createHelp().visibleCommands(this).forEach((Q)=>{if(J.push(Q.name()),Q.alias())J.push(Q.alias())}),q=a($,J)}let z=`error: unknown command '${$}'${q}`;this.error(z,{code:"commander.unknownCommand"})}version($,q,z){if($===void 0)return this._version;this._version=$,q=q||"-V, --version",z=z||"output the version number";let J=this.createOption(q,z);return this._versionOptionName=J.attributeName(),this._registerOption(J),this.on("option:"+J.name(),()=>{this._outputConfiguration.writeOut(`${$}
25
+ `),this._exit(0,"commander.version",$)}),this}description($,q){if($===void 0&&q===void 0)return this._description;if(this._description=$,q)this._argsDescription=q;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let q=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)q=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($);if(z){let J=[z.name()].concat(z.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${J}'`)}return q._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((q)=>this.alias(q)),this}usage($){if($===void 0){if(this._usage)return this._usage;let q=this.registeredArguments.map((z)=>{return m1(z)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?q:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}helpGroup($){if($===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=$,this}commandsGroup($){if($===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=$,this}optionsGroup($){if($===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=$,this}_initOptionGroup($){if(this._defaultOptionGroup&&!$.helpGroupHeading)$.helpGroup(this._defaultOptionGroup)}_initCommandGroup($){if(this._defaultCommandGroup&&!$.helpGroup())$.helpGroup(this._defaultCommandGroup)}nameFromFilename($){return this._name=L.basename($,L.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let q=this.createHelp(),z=this._getOutputContext($);q.prepareContext({error:z.error,helpWidth:z.helpWidth,outputHasColors:z.hasColors});let J=q.formatHelp(this,q);if(z.hasColors)return J;return this._outputConfiguration.stripColor(J)}_getOutputContext($){$=$||{};let q=!!$.error,z,J,Q;if(q)z=(Y)=>this._outputConfiguration.writeErr(Y),J=this._outputConfiguration.getErrHasColors(),Q=this._outputConfiguration.getErrHelpWidth();else z=(Y)=>this._outputConfiguration.writeOut(Y),J=this._outputConfiguration.getOutHasColors(),Q=this._outputConfiguration.getOutHelpWidth();return{error:q,write:(Y)=>{if(!J)Y=this._outputConfiguration.stripColor(Y);return z(Y)},hasColors:J,helpWidth:Q}}outputHelp($){let q;if(typeof $==="function")q=$,$=void 0;let z=this._getOutputContext($),J={error:z.error,write:z.write,command:this};this._getCommandAndAncestors().reverse().forEach((X)=>X.emit("beforeAllHelp",J)),this.emit("beforeHelp",J);let Q=this.helpInformation({error:z.error});if(q){if(Q=q(Q),typeof Q!=="string"&&!Buffer.isBuffer(Q))throw new Error("outputHelp callback must return a string or a Buffer")}if(z.write(Q),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",J),this._getCommandAndAncestors().forEach((X)=>X.emit("afterAllHelp",J))}helpOption($,q){if(typeof $==="boolean"){if($){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption($??"-h, --help",q??"display help for command"),$||q)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this._initOptionGroup($),this}help($){this.outputHelp($);let q=Number(_.exitCode??0);if(q===0&&$&&typeof $!=="function"&&$.error)q=1;this._exit(q,"commander.help","(outputHelp)")}addHelpText($,q){let z=["beforeAll","before","after","afterAll"];if(!z.includes($))throw new Error(`Unexpected value for position to addHelpText.
26
+ Expecting one of '${z.join("', '")}'`);let J=`${$}Help`;return this.on(J,(Q)=>{let X;if(typeof q==="function")X=q({error:Q.error,command:Q.command});else X=q;if(X)Q.write(`${X}
27
+ `)}),this}_outputHelpIfRequested($){let q=this._getHelpOption();if(q&&$.find((J)=>q.is(J)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function o($){return $.map((q)=>{if(!q.startsWith("--inspect"))return q;let z,J="127.0.0.1",Q="9229",X;if((X=q.match(/^(--inspect(-brk)?)$/))!==null)z=X[1];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(z=X[1],/^\d+$/.test(X[3]))Q=X[3];else J=X[3];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)z=X[1],J=X[3],Q=X[4];if(z&&Q!=="0")return`${z}=${J}:${parseInt(Q)+1}`;return q})}function x(){if(_.env.NO_COLOR||_.env.FORCE_COLOR==="0"||_.env.FORCE_COLOR==="false")return!1;if(_.env.FORCE_COLOR||_.env.CLICOLOR_FORCE!==void 0)return!0;return}i1.Command=b;i1.useColor=x});var J1=U((o1)=>{var{Argument:$1}=y(),{Command:C}=e(),{CommanderError:r1,InvalidArgumentError:q1}=E(),{Help:a1}=A(),{Option:z1}=P();o1.program=new C;o1.createCommand=($)=>new C($);o1.createOption=($,q)=>new z1($,q);o1.createArgument=($,q)=>new $1($,q);o1.Command=C;o1.Option=z1;o1.Argument=$1;o1.Help=a1;o1.CommanderError=r1;o1.InvalidArgumentError=q1;o1.InvalidOptionArgumentError=q1});import{readFileSync as y2}from"node:fs";import{dirname as F2,join as w2}from"node:path";import{fileURLToPath as A2}from"node:url";var Q1=K1(J1(),1),{program:d2,createCommand:p2,createArgument:s2,createOption:i2,CommanderError:t2,InvalidArgumentError:n2,InvalidOptionArgumentError:r2,Command:X1,Argument:a2,Option:o2,Help:e2}=Q1.default;import{join as V2}from"node:path";import{existsSync as Y1}from"node:fs";import{readFile as T2}from"node:fs/promises";import{dirname as Z1,join as H1,resolve as f}from"node:path";var B2=".gstatxrc.json";function v($){let z=$.replace(/\.git$/,"").split(/[/:]/);return z[z.length-1]||"repository"}function _2($){let q=f($),z=20,J=0;while(J<z){let Q=H1(q,B2);if(Y1(Q))return Q;let X=Z1(q);if(X===q)break;q=X,J++}return null}async function V($,q=process.cwd()){try{let z;if($){let Y=f($);if(!Y1(Y))return console.error(`Error: Config file not found: ${Y}`),null;z=Y}else if(z=_2(q),!z)return null;let J=await T2(z,"utf-8"),Q=JSON.parse(J),X=Z1(z);if(Q.repositories)Q.repositories=Q.repositories.map((Y)=>{if(!Y.path&&Y.url){let Z=v(Y.url);return{...Y,path:H1(X,Z),name:Y.name||Z}}if(Y.path)return{...Y,path:f(X,Y.path)};return Y});return{config:Q,configDir:X}}catch(z){if($)console.error(`Error: Failed to load config file: ${z}`);return null}}import{exec as G2,execSync as M2}from"node:child_process";import{access as L2}from"node:fs/promises";import{join as U2}from"node:path";import{promisify as S2}from"node:util";var R1=S2(G2);async function W($){try{return await L2(U2($,".git")),!0}catch{return!1}}async function h($){try{let{stdout:q}=await R1("git shortlog -sn --all",{cwd:$}),z=[],J=q.trim().split(`
28
+ `);for(let Q of J){let X=Q.match(/^\s*(\d+)\s+(.+)$/);if(X){let Y=parseInt(X[1]||"0",10),Z=X[2]||"",{stdout:T}=await R1(`git log --format='%aE' --author="${Z.replace(/"/g,"\\\"")}" -1`,{cwd:$}),H=T.trim().split(`
29
+ `)[0]||"";z.push({name:Z,email:H,commits:Y})}}return z.sort((Q,X)=>X.commits-Q.commits)}catch(q){throw new Error(`Failed to get contributors from ${$}: ${q}`)}}function u($,q,z){let J='git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat';if(q)J+=` --since="${q}"`;if(z)J+=` --until="${z}"`;let Q=M2(J,{encoding:"utf-8",cwd:$,maxBuffer:10485760}),X=[],Y=Q.split(`
30
+ `).filter((G)=>G.trim()),Z=null,T=0,H=0,R=0,B=[];for(let G of Y)if(G.includes("|")){if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:T,insertions:H,deletions:R,files:B});let[M,S,K,j,...G1]=G.split("|");if(M&&S&&K&&j)Z={hash:M.trim(),author:S.trim(),email:K.trim(),date:j.trim(),message:G1.join("|").trim()},T=0,H=0,R=0,B=[]}else{let M=G.trim().split(/\s+/);if(M.length>=2&&M[0]&&M[1]){let S=parseInt(M[0],10)||0,K=parseInt(M[1],10)||0,j=M.slice(2).join(" ");if(j&&!Number.isNaN(S)&&!Number.isNaN(K))T++,H+=S,R+=K,B.push({path:j,insertions:S,deletions:K})}}if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:T,insertions:H,deletions:R,files:B});return X}import{exec as K2}from"node:child_process";import{existsSync as T1}from"node:fs";import{mkdir as W2}from"node:fs/promises";import{dirname as j2}from"node:path";import{promisify as I2}from"node:util";var E2=I2(K2);async function g($){if(!$.path)return console.error(`Error: Repository ${$.name||"unknown"} has no path specified`),null;if(T1($.path)&&await W($.path))return $.path;if(T1($.path))return console.error(`Error: Path exists but is not a git repository: ${$.path}`),null;if(!$.url)return console.error(`Error: Repository not found at ${$.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${$.url} to ${$.path}...`);let q=j2($.path),z=$.path.split("/").pop()||"repository";try{await W2(q,{recursive:!0})}catch(J){}return await E2(`git clone "${$.url}" "${$.path}"`),console.log(`✓ Successfully cloned ${$.name||z}`),$.path}catch(q){return console.error(`Error: Failed to clone repository: ${q}`),null}}class D{config;loadedConfig=null;constructor($={}){this.config=$}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await V(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map(($)=>{if(!$.path&&$.url){let q=this.loadedConfig?.configDir||process.cwd(),z=v($.url);return{...$,path:V2(q,z),name:$.name||z}}return $});if(this.config.cloneIfNotExists&&this.config.repositories){let $=[];for(let q of this.config.repositories){if(!q.path){console.error(`Error: Repository ${q.name||"unknown"} has no path and no URL`),$.push("");continue}let z=await g(q);if(z)$.push(z);else $.push(q.path)}this.config.repositories=this.config.repositories.map((q,z)=>({...q,path:$[z]||q.path}))}}getRepoPaths($){if($&&$.length>0)return $;if(this.config.repositories)return this.config.repositories.map((q)=>q.path).filter((q)=>q!==void 0);return[]}async listContributors($){await this.initialize();let q=this.getRepoPaths($);if(q.length===0)throw new Error("No repository paths specified");let z=[];for(let J of q){if(!await W(J))throw new Error(`${J} is not a git repository`);try{let X=await h(J);z.push({path:J,contributors:X})}catch(X){throw new Error(`Failed to get contributors from ${J}: ${X}`)}}return z}async getHistory($,q,z){await this.initialize();let J=this.getRepoPaths($);if(J.length===0)throw new Error("No repository paths specified");let Q=[];for(let X of J){if(!await W(X))throw new Error(`${X} is not a git repository`);try{let Z=u(X,q,z);Q.push({path:X,commits:Z})}catch(Z){throw new Error(`Failed to get commit history from ${X}: ${Z}`)}}return Q}}async function B1($,q=!0,z){let J=new D({configPath:z});try{let Q=await J.listContributors($);for(let X of Q)if(console.log(`
31
+ \uD83D\uDCCA Contributors for ${X.path}:`),console.log("─".repeat(60)),X.contributors.length===0)console.log(" No contributors found");else for(let Y of X.contributors)if(q)console.log(` ${Y.name} <${Y.email}> (${Y.commits} commits)`);else console.log(` ${Y.name} <${Y.email}>`)}catch(Q){console.error("Error processing repositories:",Q)}}import{writeFileSync as D2}from"node:fs";import{resolve as N2}from"node:path";async function _1($,q={},z){let J=new D({configPath:z});try{let Q=await J.getHistory($,q.since,q.until),X={generatedAt:new Date().toISOString(),period:{since:q.since,until:q.until},repositories:Q.map((Z)=>{let T=new Set(Z.commits.flatMap((B)=>B.files.map((G)=>G.path))).size,H=Z.commits.reduce((B,G)=>B+G.insertions,0),R=Z.commits.reduce((B,G)=>B+G.deletions,0);return{path:Z.path,commits:Z.commits,summary:{totalCommits:Z.commits.length,totalFilesChanged:T,totalInsertions:H,totalDeletions:R}}})},Y=JSON.stringify(X,null,2);if(q.out){let Z=N2(process.cwd(),q.out);D2(Z,Y,"utf-8"),console.log(`✅ Report saved to: ${Z}`),console.log(`
32
+ \uD83D\uDCCA Summary:`);for(let T of X.repositories)console.log(`
33
+ Repository: ${T.path}`),console.log(` Commits: ${T.summary.totalCommits}`),console.log(` Files Changed: ${T.summary.totalFilesChanged}`),console.log(` Lines Added: ${T.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${T.summary.totalDeletions.toLocaleString()}`)}else console.log(Y)}catch(Q){throw console.error("Error generating history report:",Q),Q}}var P2=A2(import.meta.url),k2=F2(P2),O2=w2(k2,"..","package.json"),x2=JSON.parse(y2(O2,"utf-8")),b2=x2.version,N=new X1;N.name("gstatx").description("A CLI tool to export statistics from git repositories").version(b2).option("-c, --config <path>","Specify custom config file path").configureHelp({helpWidth:100});N.command("contributors").description("List contributors for specified repositories").option("--no-commits","Hide commit counts in contributor list").argument("[repo-paths...]","Repository paths").action(async($,q,z)=>{let J=z.parent?.opts().config,X=(await V(J))?.config.contributors?.["no-commits"]??!1,Y=!(q.noCommits||X),Z=$.length===0?void 0:$;await B1(Z,Y,J)}).addHelpText("after",`
34
34
  Examples:
35
35
  gstatx contributors ./my-repo
36
36
  gstatx contributors ./repo1 ./repo2
37
- gstatx contributors --no-commits ./my-repo`);N.command("hist").description("Generate commit history report").option("-s, --since <date>",'Start date for the report (e.g., "2024-01-01", "1 month ago")').option("-u, --until <date>",'End date for the report (e.g., "2024-12-31", "now")').option("-o, --out <file>","Output file path (defaults to stdout)").argument("[repo-paths...]","Repository paths").action(async($,q,J)=>{let z=J.parent?.opts().config,Q={since:q.since,until:q.until,out:q.out},X=$.length===0?void 0:$;await B1(X,Q,z)}).addHelpText("after",`
37
+ gstatx contributors --no-commits ./my-repo`);N.command("hist").description("Generate commit history report").option("-s, --since <date>",'Start date for the report (e.g., "2024-01-01", "1 month ago")').option("-u, --until <date>",'End date for the report (e.g., "2024-12-31", "now")').option("-o, --out <file>","Output file path (defaults to stdout)").argument("[repo-paths...]","Repository paths").action(async($,q,z)=>{let J=z.parent?.opts().config,Q={since:q.since,until:q.until,out:q.out},X=$.length===0?void 0:$;await _1(X,Q,J)}).addHelpText("after",`
38
38
  Examples:
39
39
  gstatx hist ./my-repo
40
40
  gstatx hist --since "1 month ago" ./my-repo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gstatx",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Export stats of a repo or list of repos",
5
5
  "type": "module",
6
6
  "engines": {
@@ -24,7 +24,7 @@
24
24
  "scripts": {
25
25
  "build": "bun build src/index.ts --outdir dist --target node --minify && bun build src/lib.ts --outdir dist --target node --minify && tsc -p tsconfig.build.json",
26
26
  "prepack": "bun run build",
27
- "postinstall": "./scripts/setup-git-hooks.sh",
27
+ "postinstall": "test -f ./scripts/setup-git-hooks.sh && ./scripts/setup-git-hooks.sh || exit 0",
28
28
  "setup:hooks": "./scripts/setup-git-hooks.sh",
29
29
  "start": "bun run src/index.ts",
30
30
  "lint": "biome lint .",