wilcocrypt 1.0.0 → 2.1.0

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var t=require("node:events"),e=require("node:child_process"),i=require("node:path"),s=require("node:fs"),r=require("node:process"),n=require("crypto"),o=require("zlib"),a=require("fs");function h(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u,l,c={},p={},f={};function d(){if(u)return f;u=1;class t extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}return f.CommanderError=t,f.InvalidArgumentError=class extends t{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},f}function m(){if(l)return p;l=1;const{InvalidArgumentError:t}=d();return p.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},p.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"},p}var g,_={},O={};function b(){if(g)return O;g=1;const{humanReadableArgName:t}=m();function e(t){return t.replace(/\x1b\[\d*(;\d*)*m/g,"")}return O.Help=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){const e=t.commands.filter(t=>!t._hidden),i=t._getHelpCommand();return i&&!i._hidden&&e.push(i),this.sortSubcommands&&e.sort((t,e)=>t.name().localeCompare(e.name())),e}compareOptions(t,e){const i=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){const e=t.options.filter(t=>!t.hidden),i=t._getHelpOption();if(i&&!i.hidden){const s=i.short&&t._findOption(i.short),r=i.long&&t._findOption(i.long);s||r?i.long&&!r?e.push(t.createOption(i.long,i.description)):i.short&&!s&&e.push(t.createOption(i.short,i.description)):e.push(i)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let i=t.parent;i;i=i.parent){const t=i.options.filter(t=>!t.hidden);e.push(...t)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t.registeredArguments.find(t=>t.description)?t.registeredArguments:[]}subcommandTerm(e){const i=e.registeredArguments.map(e=>t(e)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(i?" "+i:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(i)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(i)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let e=t.parent;e;e=e.parent)i=e.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue){(t.required||t.optional||t.isBoolean()&&"boolean"==typeof t.defaultValue)&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}if(void 0!==t.presetArg&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),void 0!==t.envVar&&e.push(`env: ${t.envVar}`),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatItemList(t,e,i){return 0===e.length?[]:[i.styleTitle(t),...e,""]}groupItems(t,e,i){const s=new Map;return t.forEach(t=>{const e=i(t);s.has(e)||s.set(e,[])}),e.forEach(t=>{const e=i(t);s.has(e)||s.set(e,[]),s.get(e).push(t)}),s}formatHelp(t,e){const i=e.padWidth(t,e),s=e.helpWidth??80;function r(t,s){return e.formatItem(t,i,s,e)}let n=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""];const o=e.commandDescription(t);o.length>0&&(n=n.concat([e.boxWrap(e.styleCommandDescription(o),s),""]));const a=e.visibleArguments(t).map(t=>r(e.styleArgumentTerm(e.argumentTerm(t)),e.styleArgumentDescription(e.argumentDescription(t))));n=n.concat(this.formatItemList("Arguments:",a,e));const h=this.groupItems(t.options,e.visibleOptions(t),t=>t.helpGroupHeading??"Options:");if(h.forEach((t,i)=>{const s=t.map(t=>r(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));n=n.concat(this.formatItemList(i,s,e))}),e.showGlobalOptions){const i=e.visibleGlobalOptions(t).map(t=>r(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));n=n.concat(this.formatItemList("Global Options:",i,e))}return this.groupItems(t.commands,e.visibleCommands(t),t=>t.helpGroup()||"Commands:").forEach((t,i)=>{const s=t.map(t=>r(e.styleSubcommandTerm(e.subcommandTerm(t)),e.styleSubcommandDescription(e.subcommandDescription(t))));n=n.concat(this.formatItemList(i,s,e))}),n.join("\n")}displayWidth(t){return e(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"[command]"===t?this.styleSubcommandText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,e,i,s){const r=" ".repeat(2);if(!i)return r+t;const n=t.padEnd(e+t.length-s.displayWidth(t)),o=(this.helpWidth??80)-e-2-2;let a;if(o<this.minWidthToWrap||s.preformatted(i))a=i;else{a=s.boxWrap(i,o).replace(/\n/g,"\n"+" ".repeat(e+2))}return r+n+" ".repeat(2)+a.replace(/\n/g,`\n${r}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;const i=t.split(/\r\n|\n/),s=/[\s]*[^\s]+/g,r=[];return i.forEach(t=>{const i=t.match(s);if(null===i)return void r.push("");let n=[i.shift()],o=this.displayWidth(n[0]);i.forEach(t=>{const i=this.displayWidth(t);if(o+i<=e)return n.push(t),void(o+=i);r.push(n.join(""));const s=t.trimStart();n=[s],o=this.displayWidth(s)}),r.push(n.join(""))}),r.join("\n")}},O.stripColor=e,O}var C,v={};function y(){if(C)return v;C=1;const{InvalidArgumentError:t}=d();function e(t){return t.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}return v.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const i=function(t){let e,i;const s=/^-[^-]$/,r=/^--[^-]/,n=t.split(/[ |,]+/).concat("guard");s.test(n[0])&&(e=n.shift());r.test(n[0])&&(i=n.shift());!e&&s.test(n[0])&&(e=n.shift());!e&&r.test(n[0])&&(e=i,i=n.shift());if(n[0].startsWith("-")){const e=n[0],i=`option creation failed due to '${e}' in option flags '${t}'`;if(/^-[^-][^-]/.test(e))throw new Error(`${i}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(s.test(e))throw new Error(`${i}\n- too many short flags`);if(r.test(e))throw new Error(`${i}\n- too many long flags`);throw new Error(`${i}\n- unrecognised flag format`)}if(void 0===e&&void 0===i)throw new Error(`option creation failed due to no flags found in '${t}'.`);return{shortFlag:e,longFlag:i}}(t);this.short=i.shortFlag,this.long=i.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(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return"string"==typeof t&&(e={[t]:!0}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?e(this.name().replace(/^no-/,"")):e(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},v.DualOptions=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,e)=>{this.positiveOptions.has(e)&&this.dualOptions.add(e)})}valueFromOption(t,e){const i=e.attributeName();if(!this.dualOptions.has(i))return!0;const s=this.negativeOptions.get(i).presetArg,r=void 0!==s&&s;return e.negate===(r===t)}},v}var w,A,E,x={};function S(){if(w)return x;w=1;return x.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const i=t.startsWith("--");i&&(t=t.slice(2),e=e.map(t=>t.slice(2)));let s=[],r=3;return e.forEach(e=>{if(e.length<=1)return;const i=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const i=[];for(let e=0;e<=t.length;e++)i[e]=[e];for(let t=0;t<=e.length;t++)i[0][t]=t;for(let s=1;s<=e.length;s++)for(let r=1;r<=t.length;r++){let n=1;n=t[r-1]===e[s-1]?0:1,i[r][s]=Math.min(i[r-1][s]+1,i[r][s-1]+1,i[r-1][s-1]+n),r>1&&s>1&&t[r-1]===e[s-2]&&t[r-2]===e[s-1]&&(i[r][s]=Math.min(i[r][s],i[r-2][s-2]+1))}return i[t.length][e.length]}(t,e),n=Math.max(t.length,e.length);(n-i)/n>.4&&(i<r?(r=i,s=[e]):i===r&&s.push(e))}),s.sort((t,e)=>t.localeCompare(e)),i&&(s=s.map(t=>`--${t}`)),s.length>1?`\n(Did you mean one of ${s.join(", ")}?)`:1===s.length?`\n(Did you mean ${s[0]}?)`:""},x}var $=function(){if(E)return c;E=1;const{Argument:n}=m(),{Command:o}=function(){if(A)return _;A=1;const n=t.EventEmitter,o=e,a=i,h=s,u=r,{Argument:l,humanReadableArgName:c}=m(),{CommanderError:p}=d(),{Help:f,stripColor:g}=b(),{Option:O,DualOptions:C}=y(),{suggestSimilar:v}=S();class w extends n{constructor(t){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=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>u.stdout.write(t),writeErr:t=>u.stderr.write(t),outputError:(t,e)=>e(t),getOutHelpWidth:()=>u.stdout.isTTY?u.stdout.columns:void 0,getErrHelpWidth:()=>u.stderr.isTTY?u.stderr.columns:void 0,getOutHasColors:()=>x()??(u.stdout.isTTY&&u.stdout.hasColors?.()),getErrHasColors:()=>x()??(u.stderr.isTTY&&u.stderr.hasColors?.()),stripColor:t=>g(t)},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(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,i){let s=e,r=i;"object"==typeof s&&null!==s&&(r=s,s=null),r=r||{};const[,n,o]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(n);return s&&(a.description(s),a._executableHandler=!0),r.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!r.noHelp&&!r.hidden),a._executableFile=r.executableFile||null,o&&a.arguments(o),this._registerCommand(a),a.parent=this,a.copyInheritedSettings(this),s?this:a}createCommand(t){return new w(t)}createHelp(){return Object.assign(new f,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new l(t,e)}argument(t,e,i,s){const r=this.createArgument(t,e);return"function"==typeof i?r.default(s).argParser(i):r.default(i),this.addArgument(r),this}arguments(t){return t.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&void 0!==t.defaultValue&&void 0===t.parseArg)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if("boolean"==typeof t)return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;const i=t??"help [command]",[,s,r]=i.match(/([^ ]+) *(.*)/),n=e??"display help for command",o=this.createCommand(s);return o.helpOption(!1),r&&o.arguments(r),n&&o.description(n),this._addImplicitHelpCommand=!0,this._helpCommand=o,(t||e)&&this._initCommandGroup(o),this}addHelpCommand(t,e){return"object"!=typeof t?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this._initCommandGroup(t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(void 0===this._helpCommand&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,e){const i=["preSubcommand","preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new p(t,e,i)),u.exit(t)}action(t){return this._actionHandler=e=>{const i=this.registeredArguments.length,s=e.slice(0,i);return this._storeOptionsAsProperties?s[i]=this:s[i]=this.opts(),s.push(this),t.apply(this,s)},this}createOption(t,e){return new O(t,e)}_callParseArg(t,e,i,s){try{return t.parseArg(e,i)}catch(t){if("commander.invalidArgument"===t.code){const e=`${s} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'\n- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t)}_registerCommand(t){const e=t=>[t.name()].concat(t.aliases()),i=e(t).find(t=>this._findCommand(t));if(i){const s=e(this._findCommand(i)).join("|"),r=e(t).join("|");throw new Error(`cannot add command '${r}' as already have command '${s}'`)}this._initCommandGroup(t),this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name(),i=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(i,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(i,t.defaultValue,"default");const s=(e,s,r)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const n=this.getOptionValue(i);null!==e&&t.parseArg?e=this._callParseArg(t,e,n,s):null!==e&&t.variadic&&(e=t._collectValue(e,n)),null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(i,e,r)};return this.on("option:"+e,e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;s(e,i,"cli")}),t.envVar&&this.on("optionEnv:"+e,e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;s(e,i,"env")}),this}_optionEx(t,e,i,s,r){if("object"==typeof e&&e instanceof O)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const n=this.createOption(e,i);if(n.makeOptionMandatory(!!t.mandatory),"function"==typeof s)n.default(r).argParser(s);else if(s instanceof RegExp){const t=s;s=(e,i)=>{const s=t.exec(e);return s?s[0]:i},n.default(r).argParser(s)}else n.default(s);return this.addOption(n)}option(t,e,i,s){return this._optionEx({},t,e,i,s)}requiredOption(t,e,i,s){return this._optionEx({mandatory:!0},t,e,i,s)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,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(t=!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=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,i){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(i=>{void 0!==i.getOptionValueSource(t)&&(e=i.getOptionValueSource(t))}),e}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},void 0===t&&void 0===e.from){u.versions?.electron&&(e.from="electron");const t=u.execArgv??[];(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print"))&&(e.from="eval")}let i;switch(void 0===t&&(t=u.argv),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],i=t.slice(2);break;case"electron":u.defaultApp?(this._scriptPath=t[1],i=t.slice(2)):i=t.slice(1);break;case"user":i=t.slice(0);break;case"eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_prepareForParse(){null===this._savedState?this.saveStateBeforeParse():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.\n- 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(t,e,i){if(!h.existsSync(t))throw new Error(`'${t}' does not exist\n - if '${i}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory"}`)}_executeSubCommand(t,e){e=e.slice();let i=!1;const s=[".js",".ts",".tsx",".mjs",".cjs"];function r(t,e){const i=a.resolve(t,e);if(h.existsSync(i))return i;if(s.includes(a.extname(e)))return;const r=s.find(t=>h.existsSync(`${i}${t}`));return r?`${i}${r}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let n,l=t._executableFile||`${this._name}-${t._name}`,c=this._executableDir||"";if(this._scriptPath){let t;try{t=h.realpathSync(this._scriptPath)}catch{t=this._scriptPath}c=a.resolve(a.dirname(t),c)}if(c){let e=r(c,l);if(!e&&!t._executableFile&&this._scriptPath){const i=a.basename(this._scriptPath,a.extname(this._scriptPath));i!==this._name&&(e=r(c,`${i}-${t._name}`))}l=e||l}i=s.includes(a.extname(l)),"win32"!==u.platform?i?(e.unshift(l),e=E(u.execArgv).concat(e),n=o.spawn(u.argv[0],e,{stdio:"inherit"})):n=o.spawn(l,e,{stdio:"inherit"}):(this._checkForMissingExecutable(l,c,t._name),e.unshift(l),e=E(u.execArgv).concat(e),n=o.spawn(u.execPath,e,{stdio:"inherit"})),n.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(t=>{u.on(t,()=>{!1===n.killed&&null===n.exitCode&&n.kill(t)})});const f=this._exitCallback;n.on("close",t=>{t=t??1,f?f(new p(t,"commander.executeSubCommandAsync","(close)")):u.exit(t)}),n.on("error",e=>{if("ENOENT"===e.code)this._checkForMissingExecutable(l,c,t._name);else if("EACCES"===e.code)throw new Error(`'${l}' not executable`);if(f){const t=new p(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,f(t)}else u.exit(1)}),this.runningCommand=n}_dispatchSubcommand(t,e,i){const s=this._findCommand(t);let r;return s||this.help({error:!0}),s._prepareForParse(),r=this._chainOrCallSubCommandHook(r,s,"preSubcommand"),r=this._chainOrCall(r,()=>{if(!s._executableHandler)return s._parseCommand(e,i);this._executeSubCommand(s,e.concat(i))}),r}_dispatchHelpCommand(t){t||this.help();const e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const t=(t,e,i)=>{let s=e;if(null!==e&&t.parseArg){const r=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;s=this._callParseArg(t,e,i,r)}return s};this._checkNumberOfArguments();const e=[];this.registeredArguments.forEach((i,s)=>{let r=i.defaultValue;i.variadic?s<this.args.length?(r=this.args.slice(s),i.parseArg&&(r=r.reduce((e,s)=>t(i,s,e),i.defaultValue))):void 0===r&&(r=[]):s<this.args.length&&(r=this.args[s],i.parseArg&&(r=t(i,r,i.defaultValue))),e[s]=r}),this.processedArgs=e}_chainOrCall(t,e){return t?.then&&"function"==typeof t.then?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let i=t;const s=[];return this._getCommandAndAncestors().reverse().filter(t=>void 0!==t._lifeCycleHooks[e]).forEach(t=>{t._lifeCycleHooks[e].forEach(e=>{s.push({hookedCommand:t,callback:e})})}),"postAction"===e&&s.reverse(),s.forEach(t=>{i=this._chainOrCall(i,()=>t.callback(t.hookedCommand,this))}),i}_chainOrCallSubCommandHook(t,e,i){let s=t;return void 0!==this._lifeCycleHooks[i]&&this._lifeCycleHooks[i].forEach(t=>{s=this._chainOrCall(s,()=>t(this,e))}),s}_parseCommand(t,e){const i=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),this._outputHelpIfRequested(i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const s=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){let i;return s(),this._processArguments(),i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,()=>this._actionHandler(this.processedArgs)),this.parent&&(i=this._chainOrCall(i,()=>{this.parent.emit(r,t,e)})),i=this._chainOrCallHooks(i,"postAction"),i}if(this.parent?.listenerCount(r))s(),this._processArguments(),this.parent.emit(r,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(s(),this._processArguments())}else this.commands.length?(s(),this.help({error:!0})):(s(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)})})}_checkForConflictingLocalOptions(){const t=this.options.filter(t=>{const e=t.attributeName();return void 0!==this.getOptionValue(e)&&"default"!==this.getOptionValueSource(e)}),e=t.filter(t=>t.conflictsWith.length>0);e.forEach(e=>{const i=t.find(t=>e.conflictsWith.includes(t.attributeName()));i&&this._conflictingOption(e,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){const e=[],i=[];let s=e;function r(t){return t.length>1&&"-"===t[0]}const n=t=>!!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(t)&&!this._getCommandAndAncestors().some(t=>t.options.map(t=>t.short).some(t=>/^-\d$/.test(t)));let o=null,a=null,h=0;for(;h<t.length||a;){const u=a??t[h++];if(a=null,"--"===u){s===i&&s.push(u),s.push(...t.slice(h));break}if(!o||r(u)&&!n(u)){if(o=null,r(u)){const e=this._findOption(u);if(e){if(e.required){const i=t[h++];void 0===i&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,i)}else if(e.optional){let i=null;h<t.length&&(!r(t[h])||n(t[h]))&&(i=t[h++]),this.emit(`option:${e.name()}`,i)}else this.emit(`option:${e.name()}`);o=e.variadic?e:null;continue}}if(u.length>2&&"-"===u[0]&&"-"!==u[1]){const t=this._findOption(`-${u[1]}`);if(t){t.required||t.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${t.name()}`,u.slice(2)):(this.emit(`option:${t.name()}`),a=`-${u.slice(2)}`);continue}}if(/^--[^=]+=/.test(u)){const t=u.indexOf("="),e=this._findOption(u.slice(0,t));if(e&&(e.required||e.optional)){this.emit(`option:${e.name()}`,u.slice(t+1));continue}}if(s!==e||!r(u)||0===this.commands.length&&n(u)||(s=i),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===i.length){if(this._findCommand(u)){e.push(u),i.push(...t.slice(h));break}if(this._getHelpCommand()&&u===this._getHelpCommand().name()){e.push(u,...t.slice(h));break}if(this._defaultCommandName){i.push(u,...t.slice(h));break}}if(this._passThroughOptions){s.push(u,...t.slice(h));break}s.push(u)}else this.emit(`option:${o.name()}`,u)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let i=0;i<e;i++){const e=this.options[i].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const i=e||{},s=i.exitCode||1,r=i.code||"commander.error";this._exit(s,r,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in u.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,u.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){const t=new C(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter(i=>void 0!==i.implied&&e(i.attributeName())&&t.valueFromOption(this.getOptionValue(i.attributeName()),i)).forEach(t=>{Object.keys(t.implied).filter(t=>!e(t)).forEach(e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")})})}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const i=t=>{const e=t.attributeName(),i=this.getOptionValue(e),s=this.options.find(t=>t.negate&&e===t.attributeName()),r=this.options.find(t=>!t.negate&&e===t.attributeName());return s&&(void 0===s.presetArg&&!1===i||void 0!==s.presetArg&&i===s.presetArg)?s:r||t},s=t=>{const e=i(t),s=e.attributeName();return"env"===this.getOptionValueSource(s)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},r=`error: ${s(t)} cannot be used with ${s(e)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[],s=this;do{const t=s.createHelp().visibleOptions(s).filter(t=>t.long).map(t=>t.long);i=i.concat(t),s=s.parent}while(s&&!s._enablePositionalOptions);e=v(t,i)}const i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length,i=1===e?"":"s",s=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach(t=>{i.push(t.name()),t.alias()&&i.push(t.alias())}),e=v(t,i)}const i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"})}version(t,e,i){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",i=i||"output the version number";const s=this.createOption(e,i);return this._versionOptionName=s.attributeName(),this._registerOption(s),this.on("option:"+s.name(),()=>{this._outputConfiguration.writeOut(`${t}\n`),this._exit(0,"commander.version",t)}),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return void 0===t?this._summary:(this._summary=t,this)}alias(t){if(void 0===t)return this._aliases[0];let e=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");const i=this.parent?._findCommand(t);if(i){const e=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach(t=>this.alias(t)),this)}usage(t){if(void 0===t){if(this._usage)return this._usage;const t=this.registeredArguments.map(t=>c(t));return[].concat(this.options.length||null!==this._helpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}helpGroup(t){return void 0===t?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return void 0===t?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return void 0===t?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup)}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup)}nameFromFilename(t){return this._name=a.basename(t,a.extname(t)),this}executableDir(t){return void 0===t?this._executableDir:(this._executableDir=t,this)}helpInformation(t){const e=this.createHelp(),i=this._getOutputContext(t);e.prepareContext({error:i.error,helpWidth:i.helpWidth,outputHasColors:i.hasColors});const s=e.formatHelp(this,e);return i.hasColors?s:this._outputConfiguration.stripColor(s)}_getOutputContext(t){const e=!!(t=t||{}).error;let i,s,r;return e?(i=t=>this._outputConfiguration.writeErr(t),s=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(i=t=>this._outputConfiguration.writeOut(t),s=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:e,write:t=>(s||(t=this._outputConfiguration.stripColor(t)),i(t)),hasColors:s,helpWidth:r}}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const i=this._getOutputContext(t),s={error:i.error,write:i.write,command:this};this._getCommandAndAncestors().reverse().forEach(t=>t.emit("beforeAllHelp",s)),this.emit("beforeHelp",s);let r=this.helpInformation({error:i.error});if(e&&(r=e(r),"string"!=typeof r&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",s),this._getCommandAndAncestors().forEach(t=>t.emit("afterAllHelp",s))}helpOption(t,e){return"boolean"==typeof t?(t?(null===this._helpOption&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return void 0===this._helpOption&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(u.exitCode??0);0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`);const s=`${t}Help`;return this.on(s,t=>{let i;i="function"==typeof e?e({error:t.error,command:t.command}):e,i&&t.write(`${i}\n`)}),this}_outputHelpIfRequested(t){const e=this._getHelpOption();e&&t.find(t=>e.is(t))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function E(t){return t.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i,s="127.0.0.1",r="9229";return null!==(i=t.match(/^(--inspect(-brk)?)$/))?e=i[1]:null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=i[1],/^\d+$/.test(i[3])?r=i[3]:s=i[3]):null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=i[1],s=i[3],r=i[4]),e&&"0"!==r?`${e}=${s}:${parseInt(r)+1}`:t})}function x(){return!u.env.NO_COLOR&&"0"!==u.env.FORCE_COLOR&&"false"!==u.env.FORCE_COLOR&&(!(!u.env.FORCE_COLOR&&void 0===u.env.CLICOLOR_FORCE)||void 0)}return _.Command=w,_.useColor=x,_}(),{CommanderError:a,InvalidArgumentError:h}=d(),{Help:u}=b(),{Option:l}=y();return c.program=new o,c.createCommand=t=>new o(t),c.createOption=(t,e)=>new l(t,e),c.createArgument=(t,e)=>new n(t,e),c.Command=o,c.Option=l,c.Argument=n,c.Help=u,c.CommanderError=a,c.InvalidArgumentError=h,c.InvalidOptionArgumentError=h,c}(),I=h($);const{program:H,createCommand:T,createArgument:V,createOption:k,CommanderError:D,InvalidArgumentError:P,InvalidOptionArgumentError:N,Command:B,Argument:W,Option:M,Help:F}=I;var G,U,L,R,j,q,K,Y={};function z(){if(q)return j;q=1;const t=new(function(){if(R)return L;R=1;const t=process.env.NOTEPACK_DECODE_KEY_CACHE_MAX_SIZE||1024,e=process.env.NOTEPACK_DECODE_KEY_CACHE_MAX_LENGTH||16;return L=class{constructor({maxSize:i=t,maxLength:s=e}={}){this.size=0,this.maxSize=i,this.maxLength=s,this.cache=new Map;for(let t=1;t<=this.maxLength;t++)this.cache.set(t,new Map)}get(t,e,i){if(i>this.maxLength)return!1;let s=this.cache.get(i);for(let r=0;r<i;r++){const i=t[e+r];if(!s.has(i))return!1;s=s.get(i)}return s}set(t,e,i,s){if(i>this.maxLength||this.size>=this.maxSize)return;this.size++;let r=this.cache.get(i);for(let n=0;n<i;n++){const o=t[e+n];if(n===i-1)r.set(o,s);else if(r.has(o))r=r.get(o);else{const t=new Map;r.set(o,t),r=t}}}}}());function e(t){this.offset=0,this.buffer=t,this.useKeyCache=!1}return e.prototype.array=function(t){const e=new Array(t);for(let i=0;i<t;i++)e[i]=this.parse();return e},e.prototype.map=function(t){let e="",i={};for(let s=0;s<t;s++)this.useKeyCache=!0,e=this.parse(),this.useKeyCache=!1,i[e]=this.parse();return i},e.prototype.str=function(e){if(this.useKeyCache){const i=t.get(this.buffer,this.offset,e);if(i)return this.offset+=e,i}const i=this.buffer.toString("utf8",this.offset,this.offset+e);return this.useKeyCache&&t.set(this.buffer,this.offset,e,i),this.offset+=e,i},e.prototype.bin=function(t){const e=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,e},e.prototype.arraybuffer=function(t){const e=new ArrayBuffer(t),i=new Uint8Array(e);for(let e=0;e<t;e++)i[e]=this.buffer[this.offset+e];return this.offset+=t,e},e.prototype.parse=function(){const t=this.buffer[this.offset++];let e,i=0,s=0,r=0,n=0;if(t<192)return t<128?t:t<144?this.map(15&t):t<160?this.array(15&t):this.str(31&t);if(t>223)return-1*(255-t+1);switch(t){case 192:return null;case 194:return!1;case 195:return!0;case 196:return i=this.buffer.readUInt8(this.offset),this.offset+=1,this.bin(i);case 197:return i=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.bin(i);case 198:return i=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.bin(i);case 199:if(i=this.buffer.readUInt8(this.offset),s=this.buffer.readInt8(this.offset+1),this.offset+=2,0===s)return this.arraybuffer(i);if(-1===s){const t=this.buffer.readUInt32BE(this.offset);return r=this.buffer.readInt32BE(this.offset+4),n=this.buffer.readUInt32BE(this.offset+8),this.offset+=12,new Date(1e3*(4294967296*r+n)+t/1e6)}return[s,this.bin(i)];case 200:return i=this.buffer.readUInt16BE(this.offset),s=this.buffer.readInt8(this.offset+2),this.offset+=3,0===s?this.arraybuffer(i):[s,this.bin(i)];case 201:return i=this.buffer.readUInt32BE(this.offset),s=this.buffer.readInt8(this.offset+4),this.offset+=5,0===s?this.arraybuffer(i):[s,this.bin(i)];case 202:return e=this.buffer.readFloatBE(this.offset),this.offset+=4,e;case 203:return e=this.buffer.readDoubleBE(this.offset),this.offset+=8,e;case 204:return e=this.buffer.readUInt8(this.offset),this.offset+=1,e;case 205:return e=this.buffer.readUInt16BE(this.offset),this.offset+=2,e;case 206:return e=this.buffer.readUInt32BE(this.offset),this.offset+=4,e;case 207:return r=this.buffer.readUInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,r+n;case 208:return e=this.buffer.readInt8(this.offset),this.offset+=1,e;case 209:return e=this.buffer.readInt16BE(this.offset),this.offset+=2,e;case 210:return e=this.buffer.readInt32BE(this.offset),this.offset+=4,e;case 211:return r=this.buffer.readInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,r+n;case 212:return s=this.buffer.readInt8(this.offset),this.offset+=1,0===s?void(this.offset+=1):[s,this.bin(1)];case 213:return s=this.buffer.readInt8(this.offset),this.offset+=1,[s,this.bin(2)];case 214:return s=this.buffer.readInt8(this.offset),this.offset+=1,-1===s?(e=this.buffer.readUInt32BE(this.offset),this.offset+=4,new Date(1e3*e)):[s,this.bin(4)];case 215:if(s=this.buffer.readInt8(this.offset),this.offset+=1,0===s)return r=this.buffer.readInt32BE(this.offset)*Math.pow(2,32),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8,new Date(r+n);if(-1===s){r=this.buffer.readUInt32BE(this.offset),n=this.buffer.readUInt32BE(this.offset+4),this.offset+=8;return new Date(1e3*(4294967296*(3&r)+n)+(r>>>2)/1e6)}return[s,this.bin(8)];case 216:return s=this.buffer.readInt8(this.offset),this.offset+=1,[s,this.bin(16)];case 217:return i=this.buffer.readUInt8(this.offset),this.offset+=1,this.str(i);case 218:return i=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.str(i);case 219:return i=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.str(i);case 220:return i=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.array(i);case 221:return i=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.array(i);case 222:return i=this.buffer.readUInt16BE(this.offset),this.offset+=2,this.map(i);case 223:return i=this.buffer.readUInt32BE(this.offset),this.offset+=4,this.map(i)}throw new Error("Could not parse")},j=function(t){const i=new e(t),s=i.parse();if(i.offset!==t.length)throw new Error(t.length-i.offset+" trailing bytes");return s}}var J=(K||(K=1,Y.encode=function(){if(U)return G;function t(t,e,i){let s=0;for(let r=0,n=i.length;r<n;r++)s=i.charCodeAt(r),s<128?t[e++]=s:s<2048?(t[e++]=192|s>>6,t[e++]=128|63&s):s<55296||s>=57344?(t[e++]=224|s>>12,t[e++]=128|s>>6&63,t[e++]=128|63&s):(r++,s=65536+((1023&s)<<10|1023&i.charCodeAt(r)),t[e++]=240|s>>18,t[e++]=128|s>>12&63,t[e++]=128|s>>6&63,t[e++]=128|63&s)}U=1;const e=new Map,i=process.env.NOTEPACK_ENCODE_CACHE_MAX_SIZE||1024;function s(s,n,o){if(e.has(o)){const t=e.get(o);return n.push({bin:t,length:t.length,offset:s.length}),t.length}if(e.size>i)return r(s,n,o);const a=[],h=r(a,[],o),u=Buffer.allocUnsafe(h);for(let t=0,e=a.length;t<e;t++)u[t]=a[t];return t(u,a.length,o),n.push({bin:u,length:h,offset:s.length}),e.set(o,u),h}function r(t,e,i){let n=0,o=0,a=0,h=0;switch(typeof i){case"string":if(a=i.length>32?Buffer.byteLength(i):function(t){let e=0,i=0;for(let s=0,r=t.length;s<r;s++)e=t.charCodeAt(s),e<128?i+=1:e<2048?i+=2:e<55296||e>=57344?i+=3:(s++,i+=4);return i}(i),a<32)t.push(160|a),h=1;else if(a<256)t.push(217,a),h=2;else if(a<65536)t.push(218,a>>8,a),h=3;else{if(!(a<4294967296))throw new Error("String too long");t.push(219,a>>24,a>>16,a>>8,a),h=5}return e.push({str:i,length:a,offset:t.length}),h+a;case"number":return Math.floor(i)===i&&isFinite(i)?i>=0?i<128?(t.push(i),1):i<256?(t.push(204,i),2):i<65536?(t.push(205,i>>8,i),3):i<4294967296?(t.push(206,i>>24,i>>16,i>>8,i),5):(n=i/Math.pow(2,32)|0,o=i>>>0,t.push(207,n>>24,n>>16,n>>8,n,o>>24,o>>16,o>>8,o),9):i>=-32?(t.push(i),1):i>=-128?(t.push(208,i),2):i>=-32768?(t.push(209,i>>8,i),3):i>=-2147483648?(t.push(210,i>>24,i>>16,i>>8,i),5):(n=Math.floor(i/Math.pow(2,32)),o=i>>>0,t.push(211,n>>24,n>>16,n>>8,n,o>>24,o>>16,o>>8,o),9):(t.push(203),e.push({float:i,length:8,offset:t.length}),9);case"object":if(null===i)return t.push(192),1;if(Array.isArray(i)){if(a=i.length,a<16)t.push(144|a),h=1;else if(a<65536)t.push(220,a>>8,a),h=3;else{if(!(a<4294967296))throw new Error("Array too large");t.push(221,a>>24,a>>16,a>>8,a),h=5}for(let s=0;s<a;s++)h+=r(t,e,i[s]);return h}if(i instanceof Date){const e=i.getTime(),s=Math.floor(e/1e3),r=1e6*(e-1e3*s);return s>=0&&r>=0&&s<=17179869183?0===r&&s<=4294967295?(t.push(214,255,s>>24,s>>16,s>>8,s),6):(n=s/4294967296,o=4294967295&s,t.push(215,255,r>>22,r>>14,r>>6,n,o>>24,o>>16,o>>8,o),10):(n=Math.floor(s/4294967296),o=s>>>0,t.push(199,12,255,r>>24,r>>16,r>>8,r,n>>24,n>>16,n>>8,n,o>>24,o>>16,o>>8,o),15)}if(i instanceof Buffer){if(a=i.length,a<256)t.push(196,a),h=2;else if(a<65536)t.push(197,a>>8,a),h=3;else{if(!(a<4294967296))throw new Error("Buffer too large");t.push(198,a>>24,a>>16,a>>8,a),h=5}return e.push({bin:i,length:a,offset:t.length}),h+a}if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return r(t,e,Buffer.from(i));if("function"==typeof i.toJSON)return r(t,e,i.toJSON());const u=[],l=Object.keys(i);let c="";for(let t=0,e=l.length;t<e;t++)c=l[t],void 0!==i[c]&&"function"!=typeof i[c]&&u.push(c);if(a=u.length,a<16)t.push(128|a),h=1;else if(a<65536)t.push(222,a>>8,a),h=3;else{if(!(a<4294967296))throw new Error("Object too large");t.push(223,a>>24,a>>16,a>>8,a),h=5}for(let n=0;n<a;n++)c=u[n],h+=s(t,e,c),h+=r(t,e,i[c]);return h;case"boolean":return t.push(i?195:194),1;case"undefined":return t.push(192),1;default:if("function"==typeof i.toJSON)return r(t,e,i.toJSON());throw new Error("Could not encode")}}return G=function(e){const i=[],s=[],n=r(i,s,e),o=Buffer.allocUnsafe(n);let a=0,h=0,u=-1;s.length>0&&(u=s[0].offset);let l,c=0,p=0;for(let e=0,r=i.length;e<r;e++)for(o[h+e]=i[e];e+1===u;){if(l=s[a],c=l.length,p=h+u,l.bin)if(c>32)l.bin.copy(o,p,0,c);else{const t=l.bin;for(let e=0;e<c;e++)o[p+e]=t[e]}else l.str?c>32?o.write(l.str,p,c,"utf8"):t(o,p,l.str):void 0!==l.float&&o.writeDoubleBE(l.float,p);if(a++,h+=c,!s[a])break;u=s[a].offset}return o}}(),Y.decode=z()),Y);const X={_:{}};class Z extends Error{constructor(t,e="WILCOCRYPT_ERROR"){super(t),this.name="WilcoCryptError",this.code=e,Error.captureStackTrace&&Error.captureStackTrace(this,Z)}}function Q(t="Password: "){return new Promise(e=>{const i=process.stdin,s=process.stdout;if(!i.isTTY)throw new X._.WilcoCryptError("Password prompt requires a TTY","NO_TTY");s.write(t);let r="";i.setRawMode(!0),i.resume(),i.setEncoding("utf8"),i.on("data",function t(n){if("\r"===n||"\n"===n)return s.write("\n"),i.setRawMode(!1),i.pause(),i.removeListener("data",t),void e(r);""===n&&(s.write("\n"),i.setRawMode(!1),i.pause(),i.removeListener("data",t),process.exit(1)),""!==n&&"\b"!==n?(r+=n,s.write("*")):r.length>0&&(r=r.slice(0,-1),s.write("\b \b"))})})}X._.WilcoCryptError=Z,X._.VERSION="2.1.0",X._.MIN_PASSWORD_LENGTH=6,X._.assertKeyAndIv=function(t,e){if(!Buffer.isBuffer(t)||32!==t.length)throw new Z("Invalid encryption key (expected 32-byte Buffer)","INVALID_KEY");if(!Buffer.isBuffer(e)||12!==e.length)throw new Z("Invalid IV (expected 12-byte Buffer for GCM)","INVALID_IV")},X._.assertPassword=function(t){if("string"!=typeof t||t.length<X._.MIN_PASSWORD_LENGTH)throw new Z(`Password must be at least ${X._.MIN_PASSWORD_LENGTH} characters`,"WEAK_PASSWORD")},X._.constantTimeEqual=function(t,e){if(t.length!==e.length)return!1;let i=0;for(let s=0;s<t.length;s++)i|=t[s]^e[s];return 0===i},X._.encryptData=function(t,e,i){X._.assertKeyAndIv(e,i);const s=n.createCipheriv("aes-256-gcm",e,i);return{ciphertext:Buffer.concat([s.update(t),s.final()]),authTag:s.getAuthTag()}},X._.decryptData=function(t,e,i,s){X._.assertKeyAndIv(i,s);try{const r=n.createDecipheriv("aes-256-gcm",i,s);return r.setAuthTag(Buffer.from(e,"hex")),Buffer.concat([r.update(Buffer.from(t,"hex")),r.final()])}catch{throw new Z("Decryption failed (invalid password, corrupted data, or tampered file)","DECRYPTION_FAILED")}},X.encryptData=function(t,e,i=!0){let s;X._.assertPassword(e),s=i?o.gzipSync(t):t;const r=n.randomBytes(12),a=n.randomBytes(16),h=n.scryptSync(e,a,32),{ciphertext:u,authTag:l}=X._.encryptData(s,h,r),c={payload:u.toString("hex"),authTag:l.toString("hex"),salt:a.toString("hex"),iv:r.toString("hex"),version:X._.VERSION};return J.encode(c)},X.decryptData=function(t,e,i=!0){let s;X._.assertPassword(e);try{s=J.decode(t)}catch{throw new Z("Invalid encrypted data format (not MessagePack)","INVALID_FORMAT")}if(s.version!==X._.VERSION)throw new Z(`Version mismatch (expected ${X._.VERSION}, got ${s.version})`,"VERSION_MISMATCH");const r=n.scryptSync(e,Buffer.from(s.salt,"hex"),32),a=X._.decryptData(s.payload,s.authTag,r,Buffer.from(s.iv,"hex"));try{return i?o.gunzipSync(a):a}catch{throw new Z("Decryption succeeded but decompression failed (data may be corrupted or not compressed)","DECOMPRESSION_FAILED")}},X.encryptFile=function(t,e,i=!0){const s=a.readFileSync(t),r=X.encryptData(s,e,i);a.writeFileSync(`${t}.enc`,r)},X.decryptFile=function(t,e,i=!0){if(!t.endsWith(".enc"))throw new Z("Invalid file extension (expected .enc)","INVALID_FILE_EXTENSION");const s=a.readFileSync(t);return X.decryptData(s,e,i)};const tt=new B;tt.name("wilcocrypt").description("File encryption tool").version(X._.VERSION,"--version","Show version").option("-e, --encrypt <file>","Encrypt file").option("-d, --decrypt <file>","Decrypt file").helpOption("-h, --help","Display help"),tt.parse(process.argv);const et=tt.opts(),it=[et.encrypt,et.decrypt,et.unpack].filter(Boolean);0===it.length&&tt.help(),it.length>1&&(console.error("error: please specify only one action (-e, -d or --unpack)"),process.exit(1)),(async()=>{try{if(et.encrypt){const t=await Q("Encryption password: ");return X.encryptFile(et.encrypt,t),void console.log(`Encrypted: ${et.encrypt}.enc`)}if(et.decrypt){const t=await Q("Decryption password: "),e=X.decryptFile(et.decrypt,t);return void process.stdout.write(e)}}catch(t){console.error(`error: ${t.message}`),process.exit(1)}})();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import t from"node:events";import e from"node:child_process";import i from"node:path";import s from"node:fs";import n from"node:process";import r from"./wilcocrypt.min.js";import"crypto";import"zlib";import"fs";function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var a,h,l={},u={},p={};function c(){if(a)return p;a=1;class t extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}return p.CommanderError=t,p.InvalidArgumentError=class extends t{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},p}function m(){if(h)return u;h=1;const{InvalidArgumentError:t}=c();return u.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},u.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"},u}var d,g={},f={};function _(){if(d)return f;d=1;const{humanReadableArgName:t}=m();function e(t){return t.replace(/\x1b\[\d*(;\d*)*m/g,"")}return f.Help=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){const e=t.commands.filter(t=>!t._hidden),i=t._getHelpCommand();return i&&!i._hidden&&e.push(i),this.sortSubcommands&&e.sort((t,e)=>t.name().localeCompare(e.name())),e}compareOptions(t,e){const i=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){const e=t.options.filter(t=>!t.hidden),i=t._getHelpOption();if(i&&!i.hidden){const s=i.short&&t._findOption(i.short),n=i.long&&t._findOption(i.long);s||n?i.long&&!n?e.push(t.createOption(i.long,i.description)):i.short&&!s&&e.push(t.createOption(i.short,i.description)):e.push(i)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let i=t.parent;i;i=i.parent){const t=i.options.filter(t=>!t.hidden);e.push(...t)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t.registeredArguments.find(t=>t.description)?t.registeredArguments:[]}subcommandTerm(e){const i=e.registeredArguments.map(e=>t(e)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(i?" "+i:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(i)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((t,i)=>Math.max(t,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(i)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let e=t.parent;e;e=e.parent)i=e.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue){(t.required||t.optional||t.isBoolean()&&"boolean"==typeof t.defaultValue)&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}if(void 0!==t.presetArg&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),void 0!==t.envVar&&e.push(`env: ${t.envVar}`),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatItemList(t,e,i){return 0===e.length?[]:[i.styleTitle(t),...e,""]}groupItems(t,e,i){const s=new Map;return t.forEach(t=>{const e=i(t);s.has(e)||s.set(e,[])}),e.forEach(t=>{const e=i(t);s.has(e)||s.set(e,[]),s.get(e).push(t)}),s}formatHelp(t,e){const i=e.padWidth(t,e),s=e.helpWidth??80;function n(t,s){return e.formatItem(t,i,s,e)}let r=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""];const o=e.commandDescription(t);o.length>0&&(r=r.concat([e.boxWrap(e.styleCommandDescription(o),s),""]));const a=e.visibleArguments(t).map(t=>n(e.styleArgumentTerm(e.argumentTerm(t)),e.styleArgumentDescription(e.argumentDescription(t))));r=r.concat(this.formatItemList("Arguments:",a,e));const h=this.groupItems(t.options,e.visibleOptions(t),t=>t.helpGroupHeading??"Options:");if(h.forEach((t,i)=>{const s=t.map(t=>n(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));r=r.concat(this.formatItemList(i,s,e))}),e.showGlobalOptions){const i=e.visibleGlobalOptions(t).map(t=>n(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));r=r.concat(this.formatItemList("Global Options:",i,e))}return this.groupItems(t.commands,e.visibleCommands(t),t=>t.helpGroup()||"Commands:").forEach((t,i)=>{const s=t.map(t=>n(e.styleSubcommandTerm(e.subcommandTerm(t)),e.styleSubcommandDescription(e.subcommandDescription(t))));r=r.concat(this.formatItemList(i,s,e))}),r.join("\n")}displayWidth(t){return e(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"[command]"===t?this.styleSubcommandText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,e,i,s){const n=" ".repeat(2);if(!i)return n+t;const r=t.padEnd(e+t.length-s.displayWidth(t)),o=(this.helpWidth??80)-e-2-2;let a;if(o<this.minWidthToWrap||s.preformatted(i))a=i;else{a=s.boxWrap(i,o).replace(/\n/g,"\n"+" ".repeat(e+2))}return n+r+" ".repeat(2)+a.replace(/\n/g,`\n${n}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;const i=t.split(/\r\n|\n/),s=/[\s]*[^\s]+/g,n=[];return i.forEach(t=>{const i=t.match(s);if(null===i)return void n.push("");let r=[i.shift()],o=this.displayWidth(r[0]);i.forEach(t=>{const i=this.displayWidth(t);if(o+i<=e)return r.push(t),void(o+=i);n.push(r.join(""));const s=t.trimStart();r=[s],o=this.displayWidth(s)}),n.push(r.join(""))}),n.join("\n")}},f.stripColor=e,f}var O,C={};function v(){if(O)return C;O=1;const{InvalidArgumentError:t}=c();function e(t){return t.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}return C.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const i=function(t){let e,i;const s=/^-[^-]$/,n=/^--[^-]/,r=t.split(/[ |,]+/).concat("guard");s.test(r[0])&&(e=r.shift());n.test(r[0])&&(i=r.shift());!e&&s.test(r[0])&&(e=r.shift());!e&&n.test(r[0])&&(e=i,i=r.shift());if(r[0].startsWith("-")){const e=r[0],i=`option creation failed due to '${e}' in option flags '${t}'`;if(/^-[^-][^-]/.test(e))throw new Error(`${i}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(s.test(e))throw new Error(`${i}\n- too many short flags`);if(n.test(e))throw new Error(`${i}\n- too many long flags`);throw new Error(`${i}\n- unrecognised flag format`)}if(void 0===e&&void 0===i)throw new Error(`option creation failed due to no flags found in '${t}'.`);return{shortFlag:e,longFlag:i}}(t);this.short=i.shortFlag,this.long=i.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(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return"string"==typeof t&&(e={[t]:!0}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?e(this.name().replace(/^no-/,"")):e(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},C.DualOptions=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,e)=>{this.positiveOptions.has(e)&&this.dualOptions.add(e)})}valueFromOption(t,e){const i=e.attributeName();if(!this.dualOptions.has(i))return!0;const s=this.negativeOptions.get(i).presetArg,n=void 0!==s&&s;return e.negate===(n===t)}},C}var A,b,w,y={};function E(){if(A)return y;A=1;return y.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const i=t.startsWith("--");i&&(t=t.slice(2),e=e.map(t=>t.slice(2)));let s=[],n=3;return e.forEach(e=>{if(e.length<=1)return;const i=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const i=[];for(let e=0;e<=t.length;e++)i[e]=[e];for(let t=0;t<=e.length;t++)i[0][t]=t;for(let s=1;s<=e.length;s++)for(let n=1;n<=t.length;n++){let r=1;r=t[n-1]===e[s-1]?0:1,i[n][s]=Math.min(i[n-1][s]+1,i[n][s-1]+1,i[n-1][s-1]+r),n>1&&s>1&&t[n-1]===e[s-2]&&t[n-2]===e[s-1]&&(i[n][s]=Math.min(i[n][s],i[n-2][s-2]+1))}return i[t.length][e.length]}(t,e),r=Math.max(t.length,e.length);(r-i)/r>.4&&(i<n?(n=i,s=[e]):i===n&&s.push(e))}),s.sort((t,e)=>t.localeCompare(e)),i&&(s=s.map(t=>`--${t}`)),s.length>1?`\n(Did you mean one of ${s.join(", ")}?)`:1===s.length?`\n(Did you mean ${s[0]}?)`:""},y}var x=function(){if(w)return l;w=1;const{Argument:r}=m(),{Command:o}=function(){if(b)return g;b=1;const r=t.EventEmitter,o=e,a=i,h=s,l=n,{Argument:u,humanReadableArgName:p}=m(),{CommanderError:d}=c(),{Help:f,stripColor:O}=_(),{Option:C,DualOptions:A}=v(),{suggestSimilar:w}=E();class y extends r{constructor(t){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=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>l.stdout.write(t),writeErr:t=>l.stderr.write(t),outputError:(t,e)=>e(t),getOutHelpWidth:()=>l.stdout.isTTY?l.stdout.columns:void 0,getErrHelpWidth:()=>l.stderr.isTTY?l.stderr.columns:void 0,getOutHasColors:()=>$()??(l.stdout.isTTY&&l.stdout.hasColors?.()),getErrHasColors:()=>$()??(l.stderr.isTTY&&l.stderr.hasColors?.()),stripColor:t=>O(t)},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(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,i){let s=e,n=i;"object"==typeof s&&null!==s&&(n=s,s=null),n=n||{};const[,r,o]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(r);return s&&(a.description(s),a._executableHandler=!0),n.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!n.noHelp&&!n.hidden),a._executableFile=n.executableFile||null,o&&a.arguments(o),this._registerCommand(a),a.parent=this,a.copyInheritedSettings(this),s?this:a}createCommand(t){return new y(t)}createHelp(){return Object.assign(new f,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new u(t,e)}argument(t,e,i,s){const n=this.createArgument(t,e);return"function"==typeof i?n.default(s).argParser(i):n.default(i),this.addArgument(n),this}arguments(t){return t.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&void 0!==t.defaultValue&&void 0===t.parseArg)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if("boolean"==typeof t)return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;const i=t??"help [command]",[,s,n]=i.match(/([^ ]+) *(.*)/),r=e??"display help for command",o=this.createCommand(s);return o.helpOption(!1),n&&o.arguments(n),r&&o.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=o,(t||e)&&this._initCommandGroup(o),this}addHelpCommand(t,e){return"object"!=typeof t?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this._initCommandGroup(t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(void 0===this._helpCommand&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,e){const i=["preSubcommand","preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new d(t,e,i)),l.exit(t)}action(t){return this._actionHandler=e=>{const i=this.registeredArguments.length,s=e.slice(0,i);return this._storeOptionsAsProperties?s[i]=this:s[i]=this.opts(),s.push(this),t.apply(this,s)},this}createOption(t,e){return new C(t,e)}_callParseArg(t,e,i,s){try{return t.parseArg(e,i)}catch(t){if("commander.invalidArgument"===t.code){const e=`${s} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'\n- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t)}_registerCommand(t){const e=t=>[t.name()].concat(t.aliases()),i=e(t).find(t=>this._findCommand(t));if(i){const s=e(this._findCommand(i)).join("|"),n=e(t).join("|");throw new Error(`cannot add command '${n}' as already have command '${s}'`)}this._initCommandGroup(t),this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name(),i=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(i,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(i,t.defaultValue,"default");const s=(e,s,n)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const r=this.getOptionValue(i);null!==e&&t.parseArg?e=this._callParseArg(t,e,r,s):null!==e&&t.variadic&&(e=t._collectValue(e,r)),null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(i,e,n)};return this.on("option:"+e,e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;s(e,i,"cli")}),t.envVar&&this.on("optionEnv:"+e,e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;s(e,i,"env")}),this}_optionEx(t,e,i,s,n){if("object"==typeof e&&e instanceof C)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const r=this.createOption(e,i);if(r.makeOptionMandatory(!!t.mandatory),"function"==typeof s)r.default(n).argParser(s);else if(s instanceof RegExp){const t=s;s=(e,i)=>{const s=t.exec(e);return s?s[0]:i},r.default(n).argParser(s)}else r.default(s);return this.addOption(r)}option(t,e,i,s){return this._optionEx({},t,e,i,s)}requiredOption(t,e,i,s){return this._optionEx({mandatory:!0},t,e,i,s)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,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(t=!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=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,i){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(i=>{void 0!==i.getOptionValueSource(t)&&(e=i.getOptionValueSource(t))}),e}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},void 0===t&&void 0===e.from){l.versions?.electron&&(e.from="electron");const t=l.execArgv??[];(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print"))&&(e.from="eval")}let i;switch(void 0===t&&(t=l.argv),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],i=t.slice(2);break;case"electron":l.defaultApp?(this._scriptPath=t[1],i=t.slice(2)):i=t.slice(1);break;case"user":i=t.slice(0);break;case"eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_prepareForParse(){null===this._savedState?this.saveStateBeforeParse():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.\n- 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(t,e,i){if(!h.existsSync(t))throw new Error(`'${t}' does not exist\n - if '${i}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory"}`)}_executeSubCommand(t,e){e=e.slice();let i=!1;const s=[".js",".ts",".tsx",".mjs",".cjs"];function n(t,e){const i=a.resolve(t,e);if(h.existsSync(i))return i;if(s.includes(a.extname(e)))return;const n=s.find(t=>h.existsSync(`${i}${t}`));return n?`${i}${n}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r,u=t._executableFile||`${this._name}-${t._name}`,p=this._executableDir||"";if(this._scriptPath){let t;try{t=h.realpathSync(this._scriptPath)}catch{t=this._scriptPath}p=a.resolve(a.dirname(t),p)}if(p){let e=n(p,u);if(!e&&!t._executableFile&&this._scriptPath){const i=a.basename(this._scriptPath,a.extname(this._scriptPath));i!==this._name&&(e=n(p,`${i}-${t._name}`))}u=e||u}i=s.includes(a.extname(u)),"win32"!==l.platform?i?(e.unshift(u),e=x(l.execArgv).concat(e),r=o.spawn(l.argv[0],e,{stdio:"inherit"})):r=o.spawn(u,e,{stdio:"inherit"}):(this._checkForMissingExecutable(u,p,t._name),e.unshift(u),e=x(l.execArgv).concat(e),r=o.spawn(l.execPath,e,{stdio:"inherit"})),r.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(t=>{l.on(t,()=>{!1===r.killed&&null===r.exitCode&&r.kill(t)})});const c=this._exitCallback;r.on("close",t=>{t=t??1,c?c(new d(t,"commander.executeSubCommandAsync","(close)")):l.exit(t)}),r.on("error",e=>{if("ENOENT"===e.code)this._checkForMissingExecutable(u,p,t._name);else if("EACCES"===e.code)throw new Error(`'${u}' not executable`);if(c){const t=new d(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,c(t)}else l.exit(1)}),this.runningCommand=r}_dispatchSubcommand(t,e,i){const s=this._findCommand(t);let n;return s||this.help({error:!0}),s._prepareForParse(),n=this._chainOrCallSubCommandHook(n,s,"preSubcommand"),n=this._chainOrCall(n,()=>{if(!s._executableHandler)return s._parseCommand(e,i);this._executeSubCommand(s,e.concat(i))}),n}_dispatchHelpCommand(t){t||this.help();const e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const t=(t,e,i)=>{let s=e;if(null!==e&&t.parseArg){const n=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;s=this._callParseArg(t,e,i,n)}return s};this._checkNumberOfArguments();const e=[];this.registeredArguments.forEach((i,s)=>{let n=i.defaultValue;i.variadic?s<this.args.length?(n=this.args.slice(s),i.parseArg&&(n=n.reduce((e,s)=>t(i,s,e),i.defaultValue))):void 0===n&&(n=[]):s<this.args.length&&(n=this.args[s],i.parseArg&&(n=t(i,n,i.defaultValue))),e[s]=n}),this.processedArgs=e}_chainOrCall(t,e){return t?.then&&"function"==typeof t.then?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let i=t;const s=[];return this._getCommandAndAncestors().reverse().filter(t=>void 0!==t._lifeCycleHooks[e]).forEach(t=>{t._lifeCycleHooks[e].forEach(e=>{s.push({hookedCommand:t,callback:e})})}),"postAction"===e&&s.reverse(),s.forEach(t=>{i=this._chainOrCall(i,()=>t.callback(t.hookedCommand,this))}),i}_chainOrCallSubCommandHook(t,e,i){let s=t;return void 0!==this._lifeCycleHooks[i]&&this._lifeCycleHooks[i].forEach(t=>{s=this._chainOrCall(s,()=>t(this,e))}),s}_parseCommand(t,e){const i=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),this._outputHelpIfRequested(i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const s=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0])},n=`command:${this.name()}`;if(this._actionHandler){let i;return s(),this._processArguments(),i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,()=>this._actionHandler(this.processedArgs)),this.parent&&(i=this._chainOrCall(i,()=>{this.parent.emit(n,t,e)})),i=this._chainOrCallHooks(i,"postAction"),i}if(this.parent?.listenerCount(n))s(),this._processArguments(),this.parent.emit(n,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(s(),this._processArguments())}else this.commands.length?(s(),this.help({error:!0})):(s(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)})})}_checkForConflictingLocalOptions(){const t=this.options.filter(t=>{const e=t.attributeName();return void 0!==this.getOptionValue(e)&&"default"!==this.getOptionValueSource(e)}),e=t.filter(t=>t.conflictsWith.length>0);e.forEach(e=>{const i=t.find(t=>e.conflictsWith.includes(t.attributeName()));i&&this._conflictingOption(e,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){const e=[],i=[];let s=e;function n(t){return t.length>1&&"-"===t[0]}const r=t=>!!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(t)&&!this._getCommandAndAncestors().some(t=>t.options.map(t=>t.short).some(t=>/^-\d$/.test(t)));let o=null,a=null,h=0;for(;h<t.length||a;){const l=a??t[h++];if(a=null,"--"===l){s===i&&s.push(l),s.push(...t.slice(h));break}if(!o||n(l)&&!r(l)){if(o=null,n(l)){const e=this._findOption(l);if(e){if(e.required){const i=t[h++];void 0===i&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,i)}else if(e.optional){let i=null;h<t.length&&(!n(t[h])||r(t[h]))&&(i=t[h++]),this.emit(`option:${e.name()}`,i)}else this.emit(`option:${e.name()}`);o=e.variadic?e:null;continue}}if(l.length>2&&"-"===l[0]&&"-"!==l[1]){const t=this._findOption(`-${l[1]}`);if(t){t.required||t.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${t.name()}`,l.slice(2)):(this.emit(`option:${t.name()}`),a=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){const t=l.indexOf("="),e=this._findOption(l.slice(0,t));if(e&&(e.required||e.optional)){this.emit(`option:${e.name()}`,l.slice(t+1));continue}}if(s!==e||!n(l)||0===this.commands.length&&r(l)||(s=i),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===i.length){if(this._findCommand(l)){e.push(l),i.push(...t.slice(h));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){e.push(l,...t.slice(h));break}if(this._defaultCommandName){i.push(l,...t.slice(h));break}}if(this._passThroughOptions){s.push(l,...t.slice(h));break}s.push(l)}else this.emit(`option:${o.name()}`,l)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let i=0;i<e;i++){const e=this.options[i].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const i=e||{},s=i.exitCode||1,n=i.code||"commander.error";this._exit(s,n,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in l.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,l.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){const t=new A(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter(i=>void 0!==i.implied&&e(i.attributeName())&&t.valueFromOption(this.getOptionValue(i.attributeName()),i)).forEach(t=>{Object.keys(t.implied).filter(t=>!e(t)).forEach(e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")})})}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const i=t=>{const e=t.attributeName(),i=this.getOptionValue(e),s=this.options.find(t=>t.negate&&e===t.attributeName()),n=this.options.find(t=>!t.negate&&e===t.attributeName());return s&&(void 0===s.presetArg&&!1===i||void 0!==s.presetArg&&i===s.presetArg)?s:n||t},s=t=>{const e=i(t),s=e.attributeName();return"env"===this.getOptionValueSource(s)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},n=`error: ${s(t)} cannot be used with ${s(e)}`;this.error(n,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[],s=this;do{const t=s.createHelp().visibleOptions(s).filter(t=>t.long).map(t=>t.long);i=i.concat(t),s=s.parent}while(s&&!s._enablePositionalOptions);e=w(t,i)}const i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length,i=1===e?"":"s",s=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach(t=>{i.push(t.name()),t.alias()&&i.push(t.alias())}),e=w(t,i)}const i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"})}version(t,e,i){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",i=i||"output the version number";const s=this.createOption(e,i);return this._versionOptionName=s.attributeName(),this._registerOption(s),this.on("option:"+s.name(),()=>{this._outputConfiguration.writeOut(`${t}\n`),this._exit(0,"commander.version",t)}),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return void 0===t?this._summary:(this._summary=t,this)}alias(t){if(void 0===t)return this._aliases[0];let e=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");const i=this.parent?._findCommand(t);if(i){const e=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach(t=>this.alias(t)),this)}usage(t){if(void 0===t){if(this._usage)return this._usage;const t=this.registeredArguments.map(t=>p(t));return[].concat(this.options.length||null!==this._helpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}helpGroup(t){return void 0===t?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return void 0===t?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return void 0===t?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup)}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup)}nameFromFilename(t){return this._name=a.basename(t,a.extname(t)),this}executableDir(t){return void 0===t?this._executableDir:(this._executableDir=t,this)}helpInformation(t){const e=this.createHelp(),i=this._getOutputContext(t);e.prepareContext({error:i.error,helpWidth:i.helpWidth,outputHasColors:i.hasColors});const s=e.formatHelp(this,e);return i.hasColors?s:this._outputConfiguration.stripColor(s)}_getOutputContext(t){const e=!!(t=t||{}).error;let i,s,n;return e?(i=t=>this._outputConfiguration.writeErr(t),s=this._outputConfiguration.getErrHasColors(),n=this._outputConfiguration.getErrHelpWidth()):(i=t=>this._outputConfiguration.writeOut(t),s=this._outputConfiguration.getOutHasColors(),n=this._outputConfiguration.getOutHelpWidth()),{error:e,write:t=>(s||(t=this._outputConfiguration.stripColor(t)),i(t)),hasColors:s,helpWidth:n}}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const i=this._getOutputContext(t),s={error:i.error,write:i.write,command:this};this._getCommandAndAncestors().reverse().forEach(t=>t.emit("beforeAllHelp",s)),this.emit("beforeHelp",s);let n=this.helpInformation({error:i.error});if(e&&(n=e(n),"string"!=typeof n&&!Buffer.isBuffer(n)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(n),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",s),this._getCommandAndAncestors().forEach(t=>t.emit("afterAllHelp",s))}helpOption(t,e){return"boolean"==typeof t?(t?(null===this._helpOption&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return void 0===this._helpOption&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(l.exitCode??0);0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`);const s=`${t}Help`;return this.on(s,t=>{let i;i="function"==typeof e?e({error:t.error,command:t.command}):e,i&&t.write(`${i}\n`)}),this}_outputHelpIfRequested(t){const e=this._getHelpOption();e&&t.find(t=>e.is(t))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function x(t){return t.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i,s="127.0.0.1",n="9229";return null!==(i=t.match(/^(--inspect(-brk)?)$/))?e=i[1]:null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=i[1],/^\d+$/.test(i[3])?n=i[3]:s=i[3]):null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=i[1],s=i[3],n=i[4]),e&&"0"!==n?`${e}=${s}:${parseInt(n)+1}`:t})}function $(){return!l.env.NO_COLOR&&"0"!==l.env.FORCE_COLOR&&"false"!==l.env.FORCE_COLOR&&(!(!l.env.FORCE_COLOR&&void 0===l.env.CLICOLOR_FORCE)||void 0)}return g.Command=y,g.useColor=$,g}(),{CommanderError:a,InvalidArgumentError:h}=c(),{Help:u}=_(),{Option:p}=v();return l.program=new o,l.createCommand=t=>new o(t),l.createOption=(t,e)=>new p(t,e),l.createArgument=(t,e)=>new r(t,e),l.Command=o,l.Option=p,l.Argument=r,l.Help=u,l.CommanderError=a,l.InvalidArgumentError=h,l.InvalidOptionArgumentError=h,l}(),$=o(x);const{program:H,createCommand:S,createArgument:k,createOption:V,CommanderError:T,InvalidArgumentError:P,InvalidOptionArgumentError:G,Command:W,Argument:D,Option:F,Help:N}=$;function I(t="Password: "){return new Promise(e=>{const i=process.stdin,s=process.stdout;if(!i.isTTY)throw new r._.WilcoCryptError("Password prompt requires a TTY","NO_TTY");s.write(t);let n="";i.setRawMode(!0),i.resume(),i.setEncoding("utf8"),i.on("data",function t(r){if("\r"===r||"\n"===r)return s.write("\n"),i.setRawMode(!1),i.pause(),i.removeListener("data",t),void e(n);""===r&&(s.write("\n"),i.setRawMode(!1),i.pause(),i.removeListener("data",t),process.exit(1)),""!==r&&"\b"!==r?(n+=r,s.write("*")):n.length>0&&(n=n.slice(0,-1),s.write("\b \b"))})})}const M=new W;M.name("wilcocrypt").description("File encryption tool").version(r._.VERSION,"--version","Show version").option("-e, --encrypt <file>","Encrypt file").option("-d, --decrypt <file>","Decrypt file").helpOption("-h, --help","Display help"),M.parse(process.argv);const j=M.opts(),q=[j.encrypt,j.decrypt,j.unpack].filter(Boolean);0===q.length&&M.help(),q.length>1&&(console.error("error: please specify only one action (-e, -d or --unpack)"),process.exit(1)),(async()=>{try{if(j.encrypt){const t=await I("Encryption password: ");return r.encryptFile(j.encrypt,t),void console.log(`Encrypted: ${j.encrypt}.enc`)}if(j.decrypt){const t=await I("Decryption password: "),e=r.decryptFile(j.decrypt,t);return void process.stdout.write(e)}}catch(t){console.error(`error: ${t.message}`),process.exit(1)}})();