create-akan-workspace 3.1.0-rc.2 → 3.1.0-rc.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1860 -1960
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,2159 +1,2059 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var __defProp = Object.defineProperty;
4
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
5
- var __exportCjs = (target, getters, setters) => {
6
- for (var name in getters)
7
- __defProp(target, name, {
8
- get: getters[name],
9
- set: setters[name],
10
- enumerable: true,
11
- configurable: true
12
- });
13
- };
14
- var __require = import.meta.require;
15
3
 
16
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/error.js
17
- var require_error = __commonJS(function(exports) {
18
- class CommanderError extends Error {
19
- constructor(exitCode, code, message) {
20
- super(message);
21
- Error.captureStackTrace(this, this.constructor);
22
- this.name = this.constructor.name;
23
- this.code = code;
24
- this.exitCode = exitCode;
25
- this.nestedError = undefined;
26
- }
27
- }
4
+ // pkgs/create-akan-workspace/run.ts
5
+ import { spawn } from "child_process";
28
6
 
29
- class InvalidArgumentError extends CommanderError {
30
- constructor(message) {
31
- super(1, "commander.invalidArgument", message);
32
- Error.captureStackTrace(this, this.constructor);
33
- this.name = this.constructor.name;
34
- }
7
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/error.js
8
+ class CommanderError extends Error {
9
+ constructor(exitCode, code, message) {
10
+ super(message);
11
+ Error.captureStackTrace(this, this.constructor);
12
+ this.name = this.constructor.name;
13
+ this.code = code;
14
+ this.exitCode = exitCode;
15
+ this.nestedError = undefined;
35
16
  }
36
- exports.CommanderError = CommanderError;
37
- exports.InvalidArgumentError = InvalidArgumentError;
38
- });
17
+ }
39
18
 
40
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/argument.js
41
- var require_argument = __commonJS(function(exports) {
42
- var { InvalidArgumentError } = require_error();
19
+ class InvalidArgumentError extends CommanderError {
20
+ constructor(message) {
21
+ super(1, "commander.invalidArgument", message);
22
+ Error.captureStackTrace(this, this.constructor);
23
+ this.name = this.constructor.name;
24
+ }
25
+ }
43
26
 
44
- class Argument {
45
- constructor(name, description) {
46
- this.description = description || "";
47
- this.variadic = false;
48
- this.parseArg = undefined;
49
- this.defaultValue = undefined;
50
- this.defaultValueDescription = undefined;
51
- this.argChoices = undefined;
52
- switch (name[0]) {
53
- case "<":
54
- this.required = true;
55
- this._name = name.slice(1, -1);
56
- break;
57
- case "[":
58
- this.required = false;
59
- this._name = name.slice(1, -1);
60
- break;
61
- default:
62
- this.required = true;
63
- this._name = name;
64
- break;
65
- }
66
- if (this._name.endsWith("...")) {
67
- this.variadic = true;
68
- this._name = this._name.slice(0, -3);
69
- }
27
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/argument.js
28
+ class Argument {
29
+ constructor(name, description) {
30
+ this.description = description || "";
31
+ this.variadic = false;
32
+ this.parseArg = undefined;
33
+ this.defaultValue = undefined;
34
+ this.defaultValueDescription = undefined;
35
+ this.argChoices = undefined;
36
+ switch (name[0]) {
37
+ case "<":
38
+ this.required = true;
39
+ this._name = name.slice(1, -1);
40
+ break;
41
+ case "[":
42
+ this.required = false;
43
+ this._name = name.slice(1, -1);
44
+ break;
45
+ default:
46
+ this.required = true;
47
+ this._name = name;
48
+ break;
49
+ }
50
+ if (this._name.endsWith("...")) {
51
+ this.variadic = true;
52
+ this._name = this._name.slice(0, -3);
70
53
  }
71
- name() {
72
- return this._name;
54
+ }
55
+ name() {
56
+ return this._name;
57
+ }
58
+ _collectValue(value, previous) {
59
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
60
+ return [value];
73
61
  }
74
- _collectValue(value, previous) {
75
- if (previous === this.defaultValue || !Array.isArray(previous)) {
76
- return [value];
62
+ previous.push(value);
63
+ return previous;
64
+ }
65
+ default(value, description) {
66
+ this.defaultValue = value;
67
+ this.defaultValueDescription = description;
68
+ return this;
69
+ }
70
+ argParser(fn) {
71
+ this.parseArg = fn;
72
+ return this;
73
+ }
74
+ choices(values) {
75
+ this.argChoices = values.slice();
76
+ this.parseArg = (arg, previous) => {
77
+ if (!this.argChoices.includes(arg)) {
78
+ throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
77
79
  }
78
- previous.push(value);
79
- return previous;
80
- }
81
- default(value, description) {
82
- this.defaultValue = value;
83
- this.defaultValueDescription = description;
84
- return this;
85
- }
86
- argParser(fn) {
87
- this.parseArg = fn;
88
- return this;
89
- }
90
- choices(values) {
91
- this.argChoices = values.slice();
92
- this.parseArg = (arg, previous) => {
93
- if (!this.argChoices.includes(arg)) {
94
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
95
- }
96
- if (this.variadic) {
97
- return this._collectValue(arg, previous);
98
- }
99
- return arg;
100
- };
101
- return this;
102
- }
103
- argRequired() {
104
- this.required = true;
105
- return this;
106
- }
107
- argOptional() {
108
- this.required = false;
109
- return this;
110
- }
80
+ if (this.variadic) {
81
+ return this._collectValue(arg, previous);
82
+ }
83
+ return arg;
84
+ };
85
+ return this;
86
+ }
87
+ argRequired() {
88
+ this.required = true;
89
+ return this;
111
90
  }
112
- function humanReadableArgName(arg) {
113
- const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
114
- return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
91
+ argOptional() {
92
+ this.required = false;
93
+ return this;
115
94
  }
116
- exports.Argument = Argument;
117
- exports.humanReadableArgName = humanReadableArgName;
118
- });
95
+ }
96
+ function humanReadableArgName(arg) {
97
+ const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
98
+ return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
99
+ }
119
100
 
120
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/help.js
121
- var require_help = __commonJS(function(exports) {
122
- var { humanReadableArgName } = require_argument();
101
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/command.js
102
+ import { EventEmitter } from "events";
103
+ import childProcess from "child_process";
104
+ import path from "path";
105
+ import fs from "fs";
106
+ import process2 from "process";
107
+ import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
123
108
 
124
- class Help {
125
- constructor() {
126
- this.helpWidth = undefined;
127
- this.minWidthToWrap = 40;
128
- this.sortSubcommands = false;
129
- this.sortOptions = false;
130
- this.showGlobalOptions = false;
131
- }
132
- prepareContext(contextOptions) {
133
- this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
134
- }
135
- visibleCommands(cmd) {
136
- const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
137
- const helpCommand = cmd._getHelpCommand();
138
- if (helpCommand && !helpCommand._hidden) {
139
- visibleCommands.push(helpCommand);
140
- }
141
- if (this.sortSubcommands) {
142
- visibleCommands.sort((a, b) => {
143
- return a.name().localeCompare(b.name());
144
- });
145
- }
146
- return visibleCommands;
147
- }
148
- compareOptions(a, b) {
149
- const getSortKey = (option) => {
150
- return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
151
- };
152
- return getSortKey(a).localeCompare(getSortKey(b));
153
- }
154
- visibleOptions(cmd) {
155
- const visibleOptions = cmd.options.filter((option) => !option.hidden);
156
- const helpOption = cmd._getHelpOption();
157
- if (helpOption && !helpOption.hidden) {
158
- const removeShort = helpOption.short && cmd._findOption(helpOption.short);
159
- const removeLong = helpOption.long && cmd._findOption(helpOption.long);
160
- if (!removeShort && !removeLong) {
161
- visibleOptions.push(helpOption);
162
- } else if (helpOption.long && !removeLong) {
163
- visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
164
- } else if (helpOption.short && !removeShort) {
165
- visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
166
- }
167
- }
168
- if (this.sortOptions) {
169
- visibleOptions.sort(this.compareOptions);
170
- }
171
- return visibleOptions;
172
- }
173
- visibleGlobalOptions(cmd) {
174
- if (!this.showGlobalOptions)
175
- return [];
176
- const globalOptions = [];
177
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
178
- const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
179
- globalOptions.push(...visibleOptions);
180
- }
181
- if (this.sortOptions) {
182
- globalOptions.sort(this.compareOptions);
183
- }
184
- return globalOptions;
109
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/help.js
110
+ import { stripVTControlCharacters } from "util";
111
+
112
+ class Help {
113
+ constructor() {
114
+ this.helpWidth = undefined;
115
+ this.minWidthToWrap = 40;
116
+ this.sortSubcommands = false;
117
+ this.sortOptions = false;
118
+ this.showGlobalOptions = false;
119
+ }
120
+ prepareContext(contextOptions) {
121
+ this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
122
+ }
123
+ visibleCommands(cmd) {
124
+ const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
125
+ const helpCommand = cmd._getHelpCommand();
126
+ if (helpCommand && !helpCommand._hidden) {
127
+ visibleCommands.push(helpCommand);
128
+ }
129
+ if (this.sortSubcommands) {
130
+ visibleCommands.sort((a, b) => {
131
+ return a.name().localeCompare(b.name());
132
+ });
185
133
  }
186
- visibleArguments(cmd) {
187
- if (cmd._argsDescription) {
188
- cmd.registeredArguments.forEach((argument) => {
189
- argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
190
- });
191
- }
192
- if (cmd.registeredArguments.find((argument) => argument.description)) {
193
- return cmd.registeredArguments;
194
- }
134
+ return visibleCommands;
135
+ }
136
+ compareOptions(a, b) {
137
+ const getSortKey = (option) => {
138
+ return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
139
+ };
140
+ return getSortKey(a).localeCompare(getSortKey(b));
141
+ }
142
+ visibleOptions(cmd) {
143
+ const visibleOptions = cmd.options.filter((option) => !option.hidden);
144
+ const helpOption = cmd._getHelpOption();
145
+ if (helpOption && !helpOption.hidden) {
146
+ const removeShort = helpOption.short && cmd._findOption(helpOption.short);
147
+ const removeLong = helpOption.long && cmd._findOption(helpOption.long);
148
+ if (!removeShort && !removeLong) {
149
+ visibleOptions.push(helpOption);
150
+ } else if (helpOption.long && !removeLong) {
151
+ visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
152
+ } else if (helpOption.short && !removeShort) {
153
+ visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
154
+ }
155
+ }
156
+ if (this.sortOptions) {
157
+ visibleOptions.sort(this.compareOptions);
158
+ }
159
+ return visibleOptions;
160
+ }
161
+ visibleGlobalOptions(cmd) {
162
+ if (!this.showGlobalOptions)
195
163
  return [];
164
+ const globalOptions = [];
165
+ for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
166
+ const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
167
+ globalOptions.push(...visibleOptions);
196
168
  }
197
- subcommandTerm(cmd) {
198
- const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
199
- return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
169
+ if (this.sortOptions) {
170
+ globalOptions.sort(this.compareOptions);
200
171
  }
201
- optionTerm(option) {
202
- return option.flags;
203
- }
204
- argumentTerm(argument) {
205
- return argument.name();
172
+ return globalOptions;
173
+ }
174
+ visibleArguments(cmd) {
175
+ if (cmd._argsDescription) {
176
+ cmd.registeredArguments.forEach((argument) => {
177
+ argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
178
+ });
206
179
  }
207
- longestSubcommandTermLength(cmd, helper) {
208
- return helper.visibleCommands(cmd).reduce((max, command) => {
209
- return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
210
- }, 0);
180
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
181
+ return cmd.registeredArguments;
211
182
  }
212
- longestOptionTermLength(cmd, helper) {
213
- return helper.visibleOptions(cmd).reduce((max, option) => {
214
- return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
215
- }, 0);
183
+ return [];
184
+ }
185
+ subcommandTerm(cmd) {
186
+ const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
187
+ return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
188
+ }
189
+ optionTerm(option) {
190
+ return option.flags;
191
+ }
192
+ argumentTerm(argument) {
193
+ return argument.name();
194
+ }
195
+ longestSubcommandTermLength(cmd, helper) {
196
+ return helper.visibleCommands(cmd).reduce((max, command) => {
197
+ return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
198
+ }, 0);
199
+ }
200
+ longestOptionTermLength(cmd, helper) {
201
+ return helper.visibleOptions(cmd).reduce((max, option) => {
202
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
203
+ }, 0);
204
+ }
205
+ longestGlobalOptionTermLength(cmd, helper) {
206
+ return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
207
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
208
+ }, 0);
209
+ }
210
+ longestArgumentTermLength(cmd, helper) {
211
+ return helper.visibleArguments(cmd).reduce((max, argument) => {
212
+ return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
213
+ }, 0);
214
+ }
215
+ commandUsage(cmd) {
216
+ let cmdName = cmd._name;
217
+ if (cmd._aliases[0]) {
218
+ cmdName = cmdName + "|" + cmd._aliases[0];
216
219
  }
217
- longestGlobalOptionTermLength(cmd, helper) {
218
- return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
219
- return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
220
- }, 0);
220
+ let ancestorCmdNames = "";
221
+ for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
222
+ ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
221
223
  }
222
- longestArgumentTermLength(cmd, helper) {
223
- return helper.visibleArguments(cmd).reduce((max, argument) => {
224
- return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
225
- }, 0);
224
+ return ancestorCmdNames + cmdName + " " + cmd.usage();
225
+ }
226
+ commandDescription(cmd) {
227
+ return cmd.description();
228
+ }
229
+ subcommandDescription(cmd) {
230
+ return cmd.summary() || cmd.description();
231
+ }
232
+ optionDescription(option) {
233
+ const extraInfo = [];
234
+ if (option.argChoices) {
235
+ extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
226
236
  }
227
- commandUsage(cmd) {
228
- let cmdName = cmd._name;
229
- if (cmd._aliases[0]) {
230
- cmdName = cmdName + "|" + cmd._aliases[0];
237
+ if (option.defaultValue !== undefined) {
238
+ const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
239
+ if (showDefault) {
240
+ extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
231
241
  }
232
- let ancestorCmdNames = "";
233
- for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
234
- ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
235
- }
236
- return ancestorCmdNames + cmdName + " " + cmd.usage();
237
242
  }
238
- commandDescription(cmd) {
239
- return cmd.description();
243
+ if (option.presetArg !== undefined && option.optional) {
244
+ extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
240
245
  }
241
- subcommandDescription(cmd) {
242
- return cmd.summary() || cmd.description();
246
+ if (option.envVar !== undefined) {
247
+ extraInfo.push(`env: ${option.envVar}`);
243
248
  }
244
- optionDescription(option) {
245
- const extraInfo = [];
246
- if (option.argChoices) {
247
- extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
248
- }
249
- if (option.defaultValue !== undefined) {
250
- const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
251
- if (showDefault) {
252
- extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
253
- }
254
- }
255
- if (option.presetArg !== undefined && option.optional) {
256
- extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
257
- }
258
- if (option.envVar !== undefined) {
259
- extraInfo.push(`env: ${option.envVar}`);
260
- }
261
- if (extraInfo.length > 0) {
262
- const extraDescription = `(${extraInfo.join(", ")})`;
263
- if (option.description) {
264
- return `${option.description} ${extraDescription}`;
265
- }
266
- return extraDescription;
249
+ if (extraInfo.length > 0) {
250
+ const extraDescription = `(${extraInfo.join(", ")})`;
251
+ if (option.description) {
252
+ return `${option.description} ${extraDescription}`;
267
253
  }
268
- return option.description;
254
+ return extraDescription;
269
255
  }
270
- argumentDescription(argument) {
271
- const extraInfo = [];
272
- if (argument.argChoices) {
273
- extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
274
- }
275
- if (argument.defaultValue !== undefined) {
276
- extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
277
- }
278
- if (extraInfo.length > 0) {
279
- const extraDescription = `(${extraInfo.join(", ")})`;
280
- if (argument.description) {
281
- return `${argument.description} ${extraDescription}`;
282
- }
283
- return extraDescription;
256
+ return option.description;
257
+ }
258
+ argumentDescription(argument) {
259
+ const extraInfo = [];
260
+ if (argument.argChoices) {
261
+ extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
262
+ }
263
+ if (argument.defaultValue !== undefined) {
264
+ extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
265
+ }
266
+ if (extraInfo.length > 0) {
267
+ const extraDescription = `(${extraInfo.join(", ")})`;
268
+ if (argument.description) {
269
+ return `${argument.description} ${extraDescription}`;
284
270
  }
285
- return argument.description;
286
- }
287
- formatItemList(heading, items, helper) {
288
- if (items.length === 0)
289
- return [];
290
- return [helper.styleTitle(heading), ...items, ""];
291
- }
292
- groupItems(unsortedItems, visibleItems, getGroup) {
293
- const result = new Map;
294
- unsortedItems.forEach((item) => {
295
- const group = getGroup(item);
296
- if (!result.has(group))
297
- result.set(group, []);
298
- });
299
- visibleItems.forEach((item) => {
300
- const group = getGroup(item);
301
- if (!result.has(group)) {
302
- result.set(group, []);
303
- }
304
- result.get(group).push(item);
305
- });
306
- return result;
271
+ return extraDescription;
307
272
  }
308
- formatHelp(cmd, helper) {
309
- const termWidth = helper.padWidth(cmd, helper);
310
- const helpWidth = helper.helpWidth ?? 80;
311
- function callFormatItem(term, description) {
312
- return helper.formatItem(term, termWidth, description, helper);
273
+ return argument.description;
274
+ }
275
+ formatItemList(heading, items, helper) {
276
+ if (items.length === 0)
277
+ return [];
278
+ return [helper.styleTitle(heading), ...items, ""];
279
+ }
280
+ groupItems(unsortedItems, visibleItems, getGroup) {
281
+ const result = new Map;
282
+ unsortedItems.forEach((item) => {
283
+ const group = getGroup(item);
284
+ if (!result.has(group))
285
+ result.set(group, []);
286
+ });
287
+ visibleItems.forEach((item) => {
288
+ const group = getGroup(item);
289
+ if (!result.has(group)) {
290
+ result.set(group, []);
313
291
  }
314
- let output = [
315
- `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
292
+ result.get(group).push(item);
293
+ });
294
+ return result;
295
+ }
296
+ formatHelp(cmd, helper) {
297
+ const termWidth = helper.padWidth(cmd, helper);
298
+ const helpWidth = helper.helpWidth ?? 80;
299
+ function callFormatItem(term, description) {
300
+ return helper.formatItem(term, termWidth, description, helper);
301
+ }
302
+ let output = [
303
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
304
+ ""
305
+ ];
306
+ const commandDescription = helper.commandDescription(cmd);
307
+ if (commandDescription.length > 0) {
308
+ output = output.concat([
309
+ helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
316
310
  ""
317
- ];
318
- const commandDescription = helper.commandDescription(cmd);
319
- if (commandDescription.length > 0) {
320
- output = output.concat([
321
- helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
322
- ""
323
- ]);
324
- }
325
- const argumentList = helper.visibleArguments(cmd).map((argument) => {
326
- return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
311
+ ]);
312
+ }
313
+ const argumentList = helper.visibleArguments(cmd).map((argument) => {
314
+ return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
315
+ });
316
+ output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
317
+ const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
318
+ optionGroups.forEach((options, group) => {
319
+ const optionList = options.map((option) => {
320
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
327
321
  });
328
- output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
329
- const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
330
- optionGroups.forEach((options, group) => {
331
- const optionList = options.map((option) => {
332
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
333
- });
334
- output = output.concat(this.formatItemList(group, optionList, helper));
322
+ output = output.concat(this.formatItemList(group, optionList, helper));
323
+ });
324
+ if (helper.showGlobalOptions) {
325
+ const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
326
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
335
327
  });
336
- if (helper.showGlobalOptions) {
337
- const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
338
- return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
339
- });
340
- output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
341
- }
342
- const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
343
- commandGroups.forEach((commands, group) => {
344
- const commandList = commands.map((sub) => {
345
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
346
- });
347
- output = output.concat(this.formatItemList(group, commandList, helper));
328
+ output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
329
+ }
330
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
331
+ commandGroups.forEach((commands, group) => {
332
+ const commandList = commands.map((sub) => {
333
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
348
334
  });
349
- return output.join(`
335
+ output = output.concat(this.formatItemList(group, commandList, helper));
336
+ });
337
+ return output.join(`
350
338
  `);
351
- }
352
- displayWidth(str) {
353
- return stripColor(str).length;
354
- }
355
- styleTitle(str) {
356
- return str;
357
- }
358
- styleUsage(str) {
359
- return str.split(" ").map((word) => {
360
- if (word === "[options]")
361
- return this.styleOptionText(word);
362
- if (word === "[command]")
363
- return this.styleSubcommandText(word);
364
- if (word[0] === "[" || word[0] === "<")
365
- return this.styleArgumentText(word);
366
- return this.styleCommandText(word);
367
- }).join(" ");
368
- }
369
- styleCommandDescription(str) {
370
- return this.styleDescriptionText(str);
371
- }
372
- styleOptionDescription(str) {
373
- return this.styleDescriptionText(str);
374
- }
375
- styleSubcommandDescription(str) {
376
- return this.styleDescriptionText(str);
377
- }
378
- styleArgumentDescription(str) {
379
- return this.styleDescriptionText(str);
380
- }
381
- styleDescriptionText(str) {
382
- return str;
383
- }
384
- styleOptionTerm(str) {
385
- return this.styleOptionText(str);
386
- }
387
- styleSubcommandTerm(str) {
388
- return str.split(" ").map((word) => {
389
- if (word === "[options]")
390
- return this.styleOptionText(word);
391
- if (word[0] === "[" || word[0] === "<")
392
- return this.styleArgumentText(word);
339
+ }
340
+ displayWidth(str) {
341
+ return stripVTControlCharacters(str).length;
342
+ }
343
+ styleTitle(str) {
344
+ return str;
345
+ }
346
+ styleUsage(str) {
347
+ return str.split(" ").map((word) => {
348
+ if (word === "[options]")
349
+ return this.styleOptionText(word);
350
+ if (word === "[command]")
393
351
  return this.styleSubcommandText(word);
394
- }).join(" ");
395
- }
396
- styleArgumentTerm(str) {
397
- return this.styleArgumentText(str);
398
- }
399
- styleOptionText(str) {
400
- return str;
401
- }
402
- styleArgumentText(str) {
403
- return str;
404
- }
405
- styleSubcommandText(str) {
406
- return str;
352
+ if (word[0] === "[" || word[0] === "<")
353
+ return this.styleArgumentText(word);
354
+ return this.styleCommandText(word);
355
+ }).join(" ");
356
+ }
357
+ styleCommandDescription(str) {
358
+ return this.styleDescriptionText(str);
359
+ }
360
+ styleOptionDescription(str) {
361
+ return this.styleDescriptionText(str);
362
+ }
363
+ styleSubcommandDescription(str) {
364
+ return this.styleDescriptionText(str);
365
+ }
366
+ styleArgumentDescription(str) {
367
+ return this.styleDescriptionText(str);
368
+ }
369
+ styleDescriptionText(str) {
370
+ return str;
371
+ }
372
+ styleOptionTerm(str) {
373
+ return this.styleOptionText(str);
374
+ }
375
+ styleSubcommandTerm(str) {
376
+ return str.split(" ").map((word) => {
377
+ if (word === "[options]")
378
+ return this.styleOptionText(word);
379
+ if (word[0] === "[" || word[0] === "<")
380
+ return this.styleArgumentText(word);
381
+ return this.styleSubcommandText(word);
382
+ }).join(" ");
383
+ }
384
+ styleArgumentTerm(str) {
385
+ return this.styleArgumentText(str);
386
+ }
387
+ styleOptionText(str) {
388
+ return str;
389
+ }
390
+ styleArgumentText(str) {
391
+ return str;
392
+ }
393
+ styleSubcommandText(str) {
394
+ return str;
395
+ }
396
+ styleCommandText(str) {
397
+ return str;
398
+ }
399
+ padWidth(cmd, helper) {
400
+ return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
401
+ }
402
+ preformatted(str) {
403
+ return /\n[^\S\r\n]/.test(str);
404
+ }
405
+ formatItem(term, termWidth, description, helper) {
406
+ const itemIndent = 2;
407
+ const itemIndentStr = " ".repeat(itemIndent);
408
+ if (!description)
409
+ return itemIndentStr + term;
410
+ const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
411
+ const spacerWidth = 2;
412
+ const helpWidth = this.helpWidth ?? 80;
413
+ const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
414
+ let formattedDescription;
415
+ if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
416
+ formattedDescription = description;
417
+ } else {
418
+ const wrappedDescription = helper.boxWrap(description, remainingWidth);
419
+ formattedDescription = wrappedDescription.replace(/\n/g, `
420
+ ` + " ".repeat(termWidth + spacerWidth));
407
421
  }
408
- styleCommandText(str) {
422
+ return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
423
+ ${itemIndentStr}`);
424
+ }
425
+ boxWrap(str, width) {
426
+ if (width < this.minWidthToWrap)
409
427
  return str;
410
- }
411
- padWidth(cmd, helper) {
412
- return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
413
- }
414
- preformatted(str) {
415
- return /\n[^\S\r\n]/.test(str);
416
- }
417
- formatItem(term, termWidth, description, helper) {
418
- const itemIndent = 2;
419
- const itemIndentStr = " ".repeat(itemIndent);
420
- if (!description)
421
- return itemIndentStr + term;
422
- const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
423
- const spacerWidth = 2;
424
- const helpWidth = this.helpWidth ?? 80;
425
- const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
426
- let formattedDescription;
427
- if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
428
- formattedDescription = description;
429
- } else {
430
- const wrappedDescription = helper.boxWrap(description, remainingWidth);
431
- formattedDescription = wrappedDescription.replace(/\n/g, `
432
- ` + " ".repeat(termWidth + spacerWidth));
428
+ const rawLines = str.split(/\r\n|\n/);
429
+ const chunkPattern = /[\s]*[^\s]+/g;
430
+ const wrappedLines = [];
431
+ rawLines.forEach((line) => {
432
+ const chunks = line.match(chunkPattern);
433
+ if (chunks === null) {
434
+ wrappedLines.push("");
435
+ return;
433
436
  }
434
- return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
435
- ${itemIndentStr}`);
436
- }
437
- boxWrap(str, width) {
438
- if (width < this.minWidthToWrap)
439
- return str;
440
- const rawLines = str.split(/\r\n|\n/);
441
- const chunkPattern = /[\s]*[^\s]+/g;
442
- const wrappedLines = [];
443
- rawLines.forEach((line) => {
444
- const chunks = line.match(chunkPattern);
445
- if (chunks === null) {
446
- wrappedLines.push("");
437
+ let sumChunks = [chunks.shift()];
438
+ let sumWidth = this.displayWidth(sumChunks[0]);
439
+ chunks.forEach((chunk) => {
440
+ const visibleWidth = this.displayWidth(chunk);
441
+ if (sumWidth + visibleWidth <= width) {
442
+ sumChunks.push(chunk);
443
+ sumWidth += visibleWidth;
447
444
  return;
448
445
  }
449
- let sumChunks = [chunks.shift()];
450
- let sumWidth = this.displayWidth(sumChunks[0]);
451
- chunks.forEach((chunk) => {
452
- const visibleWidth = this.displayWidth(chunk);
453
- if (sumWidth + visibleWidth <= width) {
454
- sumChunks.push(chunk);
455
- sumWidth += visibleWidth;
456
- return;
457
- }
458
- wrappedLines.push(sumChunks.join(""));
459
- const nextChunk = chunk.trimStart();
460
- sumChunks = [nextChunk];
461
- sumWidth = this.displayWidth(nextChunk);
462
- });
463
446
  wrappedLines.push(sumChunks.join(""));
447
+ const nextChunk = chunk.trimStart();
448
+ sumChunks = [nextChunk];
449
+ sumWidth = this.displayWidth(nextChunk);
464
450
  });
465
- return wrappedLines.join(`
451
+ wrappedLines.push(sumChunks.join(""));
452
+ });
453
+ return wrappedLines.join(`
466
454
  `);
467
- }
468
- }
469
- function stripColor(str) {
470
- const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
471
- return str.replace(sgrPattern, "");
472
455
  }
473
- exports.Help = Help;
474
- exports.stripColor = stripColor;
475
- });
456
+ }
476
457
 
477
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/option.js
478
- var require_option = __commonJS(function(exports) {
479
- var { InvalidArgumentError } = require_error();
480
-
481
- class Option {
482
- constructor(flags, description) {
483
- this.flags = flags;
484
- this.description = description || "";
485
- this.required = flags.includes("<");
486
- this.optional = flags.includes("[");
487
- this.variadic = /\w\.\.\.[>\]]$/.test(flags);
488
- this.mandatory = false;
489
- const optionFlags = splitOptionFlags(flags);
490
- this.short = optionFlags.shortFlag;
491
- this.long = optionFlags.longFlag;
492
- this.negate = false;
493
- if (this.long) {
494
- this.negate = this.long.startsWith("--no-");
495
- }
496
- this.defaultValue = undefined;
497
- this.defaultValueDescription = undefined;
498
- this.presetArg = undefined;
499
- this.envVar = undefined;
500
- this.parseArg = undefined;
501
- this.hidden = false;
502
- this.argChoices = undefined;
503
- this.conflictsWith = [];
504
- this.implied = undefined;
505
- this.helpGroupHeading = undefined;
506
- }
507
- default(value, description) {
508
- this.defaultValue = value;
509
- this.defaultValueDescription = description;
510
- return this;
511
- }
512
- preset(arg) {
513
- this.presetArg = arg;
514
- return this;
515
- }
516
- conflicts(names) {
517
- this.conflictsWith = this.conflictsWith.concat(names);
518
- return this;
519
- }
520
- implies(impliedOptionValues) {
521
- let newImplied = impliedOptionValues;
522
- if (typeof impliedOptionValues === "string") {
523
- newImplied = { [impliedOptionValues]: true };
524
- }
525
- this.implied = Object.assign(this.implied || {}, newImplied);
526
- return this;
527
- }
528
- env(name) {
529
- this.envVar = name;
530
- return this;
531
- }
532
- argParser(fn) {
533
- this.parseArg = fn;
534
- return this;
535
- }
536
- makeOptionMandatory(mandatory = true) {
537
- this.mandatory = !!mandatory;
538
- return this;
539
- }
540
- hideHelp(hide = true) {
541
- this.hidden = !!hide;
542
- return this;
458
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/option.js
459
+ class Option {
460
+ constructor(flags, description) {
461
+ this.flags = flags;
462
+ this.description = description || "";
463
+ this.required = flags.includes("<");
464
+ this.optional = flags.includes("[");
465
+ this.variadic = /\w\.\.\.[>\]]$/.test(flags);
466
+ this.mandatory = false;
467
+ const optionFlags = splitOptionFlags(flags);
468
+ this.short = optionFlags.shortFlag;
469
+ this.long = optionFlags.longFlag;
470
+ this.negate = false;
471
+ if (this.long) {
472
+ this.negate = this.long.startsWith("--no-");
473
+ }
474
+ this.defaultValue = undefined;
475
+ this.defaultValueDescription = undefined;
476
+ this.presetArg = undefined;
477
+ this.envVar = undefined;
478
+ this.parseArg = undefined;
479
+ this.hidden = false;
480
+ this.argChoices = undefined;
481
+ this.conflictsWith = [];
482
+ this.implied = undefined;
483
+ this.helpGroupHeading = undefined;
484
+ }
485
+ default(value, description) {
486
+ this.defaultValue = value;
487
+ this.defaultValueDescription = description;
488
+ return this;
489
+ }
490
+ preset(arg) {
491
+ this.presetArg = arg;
492
+ return this;
493
+ }
494
+ conflicts(names) {
495
+ this.conflictsWith = this.conflictsWith.concat(names);
496
+ return this;
497
+ }
498
+ implies(impliedOptionValues) {
499
+ let newImplied = impliedOptionValues;
500
+ if (typeof impliedOptionValues === "string") {
501
+ newImplied = { [impliedOptionValues]: true };
543
502
  }
544
- _collectValue(value, previous) {
545
- if (previous === this.defaultValue || !Array.isArray(previous)) {
546
- return [value];
547
- }
548
- previous.push(value);
549
- return previous;
550
- }
551
- choices(values) {
552
- this.argChoices = values.slice();
553
- this.parseArg = (arg, previous) => {
554
- if (!this.argChoices.includes(arg)) {
555
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
556
- }
557
- if (this.variadic) {
558
- return this._collectValue(arg, previous);
559
- }
560
- return arg;
561
- };
562
- return this;
503
+ this.implied = Object.assign(this.implied || {}, newImplied);
504
+ return this;
505
+ }
506
+ env(name) {
507
+ this.envVar = name;
508
+ return this;
509
+ }
510
+ argParser(fn) {
511
+ this.parseArg = fn;
512
+ return this;
513
+ }
514
+ makeOptionMandatory(mandatory = true) {
515
+ this.mandatory = !!mandatory;
516
+ return this;
517
+ }
518
+ hideHelp(hide = true) {
519
+ this.hidden = !!hide;
520
+ return this;
521
+ }
522
+ _collectValue(value, previous) {
523
+ if (previous === this.defaultValue || !Array.isArray(previous)) {
524
+ return [value];
563
525
  }
564
- name() {
565
- if (this.long) {
566
- return this.long.replace(/^--/, "");
526
+ previous.push(value);
527
+ return previous;
528
+ }
529
+ choices(values) {
530
+ this.argChoices = values.slice();
531
+ this.parseArg = (arg, previous) => {
532
+ if (!this.argChoices.includes(arg)) {
533
+ throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
567
534
  }
568
- return this.short.replace(/^-/, "");
569
- }
570
- attributeName() {
571
- if (this.negate) {
572
- return camelcase(this.name().replace(/^no-/, ""));
535
+ if (this.variadic) {
536
+ return this._collectValue(arg, previous);
573
537
  }
574
- return camelcase(this.name());
575
- }
576
- helpGroup(heading) {
577
- this.helpGroupHeading = heading;
578
- return this;
579
- }
580
- is(arg) {
581
- return this.short === arg || this.long === arg;
582
- }
583
- isBoolean() {
584
- return !this.required && !this.optional && !this.negate;
585
- }
538
+ return arg;
539
+ };
540
+ return this;
586
541
  }
587
-
588
- class DualOptions {
589
- constructor(options) {
590
- this.positiveOptions = new Map;
591
- this.negativeOptions = new Map;
592
- this.dualOptions = new Set;
593
- options.forEach((option) => {
594
- if (option.negate) {
595
- this.negativeOptions.set(option.attributeName(), option);
596
- } else {
597
- this.positiveOptions.set(option.attributeName(), option);
598
- }
599
- });
600
- this.negativeOptions.forEach((value, key) => {
601
- if (this.positiveOptions.has(key)) {
602
- this.dualOptions.add(key);
603
- }
604
- });
542
+ name() {
543
+ if (this.long) {
544
+ return this.long.replace(/^--/, "");
605
545
  }
606
- valueFromOption(value, option) {
607
- const optionKey = option.attributeName();
608
- if (!this.dualOptions.has(optionKey))
609
- return true;
610
- const preset = this.negativeOptions.get(optionKey).presetArg;
611
- const negativeValue = preset !== undefined ? preset : false;
612
- return option.negate === (negativeValue === value);
546
+ return this.short.replace(/^-/, "");
547
+ }
548
+ attributeName() {
549
+ if (this.negate) {
550
+ return camelcase(this.name().replace(/^no-/, ""));
613
551
  }
552
+ return camelcase(this.name());
553
+ }
554
+ helpGroup(heading) {
555
+ this.helpGroupHeading = heading;
556
+ return this;
614
557
  }
615
- function camelcase(str) {
616
- return str.split("-").reduce((str, word) => {
617
- return str + word[0].toUpperCase() + word.slice(1);
558
+ is(arg) {
559
+ return this.short === arg || this.long === arg;
560
+ }
561
+ isBoolean() {
562
+ return !this.required && !this.optional && !this.negate;
563
+ }
564
+ }
565
+
566
+ class DualOptions {
567
+ constructor(options) {
568
+ this.positiveOptions = new Map;
569
+ this.negativeOptions = new Map;
570
+ this.dualOptions = new Set;
571
+ options.forEach((option) => {
572
+ if (option.negate) {
573
+ this.negativeOptions.set(option.attributeName(), option);
574
+ } else {
575
+ this.positiveOptions.set(option.attributeName(), option);
576
+ }
577
+ });
578
+ this.negativeOptions.forEach((value, key) => {
579
+ if (this.positiveOptions.has(key)) {
580
+ this.dualOptions.add(key);
581
+ }
618
582
  });
619
583
  }
620
- function splitOptionFlags(flags) {
621
- let shortFlag;
622
- let longFlag;
623
- const shortFlagExp = /^-[^-]$/;
624
- const longFlagExp = /^--[^-]/;
625
- const flagParts = flags.split(/[ |,]+/).concat("guard");
626
- if (shortFlagExp.test(flagParts[0]))
627
- shortFlag = flagParts.shift();
628
- if (longFlagExp.test(flagParts[0]))
629
- longFlag = flagParts.shift();
630
- if (!shortFlag && shortFlagExp.test(flagParts[0]))
631
- shortFlag = flagParts.shift();
632
- if (!shortFlag && longFlagExp.test(flagParts[0])) {
633
- shortFlag = longFlag;
634
- longFlag = flagParts.shift();
635
- }
636
- if (flagParts[0].startsWith("-")) {
637
- const unsupportedFlag = flagParts[0];
638
- const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
639
- if (/^-[^-][^-]/.test(unsupportedFlag))
640
- throw new Error(`${baseError}
584
+ valueFromOption(value, option) {
585
+ const optionKey = option.attributeName();
586
+ if (!this.dualOptions.has(optionKey))
587
+ return true;
588
+ const preset = this.negativeOptions.get(optionKey).presetArg;
589
+ const negativeValue = preset !== undefined ? preset : false;
590
+ return option.negate === (negativeValue === value);
591
+ }
592
+ }
593
+ function camelcase(str) {
594
+ return str.split("-").reduce((str, word) => {
595
+ return str + word[0].toUpperCase() + word.slice(1);
596
+ });
597
+ }
598
+ function splitOptionFlags(flags) {
599
+ let shortFlag;
600
+ let longFlag;
601
+ const shortFlagExp = /^-[^-]$/;
602
+ const longFlagExp = /^--[^-]/;
603
+ const flagParts = flags.split(/[ |,]+/).concat("guard");
604
+ if (shortFlagExp.test(flagParts[0]))
605
+ shortFlag = flagParts.shift();
606
+ if (longFlagExp.test(flagParts[0]))
607
+ longFlag = flagParts.shift();
608
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
609
+ shortFlag = flagParts.shift();
610
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
611
+ shortFlag = longFlag;
612
+ longFlag = flagParts.shift();
613
+ }
614
+ if (flagParts[0].startsWith("-")) {
615
+ const unsupportedFlag = flagParts[0];
616
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
617
+ if (/^-[^-][^-]/.test(unsupportedFlag))
618
+ throw new Error(`${baseError}
641
619
  - a short flag is a single dash and a single character
642
620
  - either use a single dash and a single character (for a short flag)
643
621
  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
644
- if (shortFlagExp.test(unsupportedFlag))
645
- throw new Error(`${baseError}
622
+ if (shortFlagExp.test(unsupportedFlag))
623
+ throw new Error(`${baseError}
646
624
  - too many short flags`);
647
- if (longFlagExp.test(unsupportedFlag))
648
- throw new Error(`${baseError}
649
- - too many long flags`);
625
+ if (longFlagExp.test(unsupportedFlag))
650
626
  throw new Error(`${baseError}
627
+ - too many long flags`);
628
+ throw new Error(`${baseError}
651
629
  - unrecognised flag format`);
652
- }
653
- if (shortFlag === undefined && longFlag === undefined)
654
- throw new Error(`option creation failed due to no flags found in '${flags}'.`);
655
- return { shortFlag, longFlag };
656
630
  }
657
- exports.Option = Option;
658
- exports.DualOptions = DualOptions;
659
- });
631
+ if (shortFlag === undefined && longFlag === undefined)
632
+ throw new Error(`option creation failed due to no flags found in '${flags}'.`);
633
+ return { shortFlag, longFlag };
634
+ }
660
635
 
661
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/suggestSimilar.js
662
- var require_suggestSimilar = __commonJS(function(exports) {
663
- var maxDistance = 3;
664
- function editDistance(a, b) {
665
- if (Math.abs(a.length - b.length) > maxDistance)
666
- return Math.max(a.length, b.length);
667
- const d = [];
668
- for (let i = 0;i <= a.length; i++) {
669
- d[i] = [i];
670
- }
671
- for (let j = 0;j <= b.length; j++) {
672
- d[0][j] = j;
673
- }
674
- for (let j = 1;j <= b.length; j++) {
675
- for (let i = 1;i <= a.length; i++) {
676
- let cost = 1;
677
- if (a[i - 1] === b[j - 1]) {
678
- cost = 0;
679
- } else {
680
- cost = 1;
681
- }
682
- d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
683
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
684
- d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
685
- }
636
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/suggestSimilar.js
637
+ var maxDistance = 3;
638
+ function editDistance(a, b) {
639
+ if (Math.abs(a.length - b.length) > maxDistance)
640
+ return Math.max(a.length, b.length);
641
+ const d = [];
642
+ for (let i = 0;i <= a.length; i++) {
643
+ d[i] = [i];
644
+ }
645
+ for (let j = 0;j <= b.length; j++) {
646
+ d[0][j] = j;
647
+ }
648
+ for (let j = 1;j <= b.length; j++) {
649
+ for (let i = 1;i <= a.length; i++) {
650
+ let cost;
651
+ if (a[i - 1] === b[j - 1]) {
652
+ cost = 0;
653
+ } else {
654
+ cost = 1;
655
+ }
656
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
657
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
658
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
686
659
  }
687
660
  }
688
- return d[a.length][b.length];
689
- }
690
- function suggestSimilar(word, candidates) {
691
- if (!candidates || candidates.length === 0)
692
- return "";
693
- candidates = Array.from(new Set(candidates));
694
- const searchingOptions = word.startsWith("--");
695
- if (searchingOptions) {
696
- word = word.slice(2);
697
- candidates = candidates.map((candidate) => candidate.slice(2));
698
- }
699
- let similar = [];
700
- let bestDistance = maxDistance;
701
- const minSimilarity = 0.4;
702
- candidates.forEach((candidate) => {
703
- if (candidate.length <= 1)
704
- return;
705
- const distance = editDistance(word, candidate);
706
- const length = Math.max(word.length, candidate.length);
707
- const similarity = (length - distance) / length;
708
- if (similarity > minSimilarity) {
709
- if (distance < bestDistance) {
710
- bestDistance = distance;
711
- similar = [candidate];
712
- } else if (distance === bestDistance) {
713
- similar.push(candidate);
714
- }
661
+ }
662
+ return d[a.length][b.length];
663
+ }
664
+ function suggestSimilar(word, candidates) {
665
+ if (!candidates || candidates.length === 0)
666
+ return "";
667
+ candidates = Array.from(new Set(candidates));
668
+ const searchingOptions = word.startsWith("--");
669
+ if (searchingOptions) {
670
+ word = word.slice(2);
671
+ candidates = candidates.map((candidate) => candidate.slice(2));
672
+ }
673
+ let similar = [];
674
+ let bestDistance = maxDistance;
675
+ const minSimilarity = 0.4;
676
+ candidates.forEach((candidate) => {
677
+ if (candidate.length <= 1)
678
+ return;
679
+ const distance = editDistance(word, candidate);
680
+ const length = Math.max(word.length, candidate.length);
681
+ const similarity = (length - distance) / length;
682
+ if (similarity > minSimilarity) {
683
+ if (distance < bestDistance) {
684
+ bestDistance = distance;
685
+ similar = [candidate];
686
+ } else if (distance === bestDistance) {
687
+ similar.push(candidate);
715
688
  }
716
- });
717
- similar.sort((a, b) => a.localeCompare(b));
718
- if (searchingOptions) {
719
- similar = similar.map((candidate) => `--${candidate}`);
720
689
  }
721
- if (similar.length > 1) {
722
- return `
690
+ });
691
+ similar.sort((a, b) => a.localeCompare(b));
692
+ if (searchingOptions) {
693
+ similar = similar.map((candidate) => `--${candidate}`);
694
+ }
695
+ if (similar.length > 1) {
696
+ return `
723
697
  (Did you mean one of ${similar.join(", ")}?)`;
724
- }
725
- if (similar.length === 1) {
726
- return `
698
+ }
699
+ if (similar.length === 1) {
700
+ return `
727
701
  (Did you mean ${similar[0]}?)`;
728
- }
729
- return "";
730
702
  }
731
- exports.suggestSimilar = suggestSimilar;
732
- });
703
+ return "";
704
+ }
733
705
 
734
- // node_modules/.bun/commander@14.0.3/node_modules/commander/lib/command.js
735
- var require_command = __commonJS(function(exports) {
736
- var EventEmitter = __require("events").EventEmitter;
737
- var childProcess = __require("child_process");
738
- var path = __require("path");
739
- var fs = __require("fs");
740
- var process2 = __require("process");
741
- var { Argument, humanReadableArgName } = require_argument();
742
- var { CommanderError } = require_error();
743
- var { Help, stripColor } = require_help();
744
- var { Option, DualOptions } = require_option();
745
- var { suggestSimilar } = require_suggestSimilar();
746
-
747
- class Command extends EventEmitter {
748
- constructor(name) {
749
- super();
750
- this.commands = [];
751
- this.options = [];
752
- this.parent = null;
753
- this._allowUnknownOption = false;
754
- this._allowExcessArguments = false;
755
- this.registeredArguments = [];
756
- this._args = this.registeredArguments;
757
- this.args = [];
758
- this.rawArgs = [];
759
- this.processedArgs = [];
760
- this._scriptPath = null;
761
- this._name = name || "";
762
- this._optionValues = {};
763
- this._optionValueSources = {};
764
- this._storeOptionsAsProperties = false;
765
- this._actionHandler = null;
766
- this._executableHandler = false;
767
- this._executableFile = null;
768
- this._executableDir = null;
769
- this._defaultCommandName = null;
770
- this._exitCallback = null;
771
- this._aliases = [];
772
- this._combineFlagAndOptionalValue = true;
773
- this._description = "";
774
- this._summary = "";
775
- this._argsDescription = undefined;
776
- this._enablePositionalOptions = false;
777
- this._passThroughOptions = false;
778
- this._lifeCycleHooks = {};
779
- this._showHelpAfterError = false;
780
- this._showSuggestionAfterError = true;
781
- this._savedState = null;
782
- this._outputConfiguration = {
783
- writeOut: (str) => process2.stdout.write(str),
784
- writeErr: (str) => process2.stderr.write(str),
785
- outputError: (str, write) => write(str),
786
- getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
787
- getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
788
- getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
789
- getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
790
- stripColor: (str) => stripColor(str)
791
- };
792
- this._hidden = false;
793
- this._helpOption = undefined;
794
- this._addImplicitHelpCommand = undefined;
795
- this._helpCommand = undefined;
796
- this._helpConfiguration = {};
797
- this._helpGroupHeading = undefined;
798
- this._defaultCommandGroup = undefined;
799
- this._defaultOptionGroup = undefined;
800
- }
801
- copyInheritedSettings(sourceCommand) {
802
- this._outputConfiguration = sourceCommand._outputConfiguration;
803
- this._helpOption = sourceCommand._helpOption;
804
- this._helpCommand = sourceCommand._helpCommand;
805
- this._helpConfiguration = sourceCommand._helpConfiguration;
806
- this._exitCallback = sourceCommand._exitCallback;
807
- this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
808
- this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
809
- this._allowExcessArguments = sourceCommand._allowExcessArguments;
810
- this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
811
- this._showHelpAfterError = sourceCommand._showHelpAfterError;
812
- this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
813
- return this;
814
- }
815
- _getCommandAndAncestors() {
816
- const result = [];
817
- for (let command = this;command; command = command.parent) {
818
- result.push(command);
819
- }
820
- return result;
821
- }
822
- command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
823
- let desc = actionOptsOrExecDesc;
824
- let opts = execOpts;
825
- if (typeof desc === "object" && desc !== null) {
826
- opts = desc;
827
- desc = null;
828
- }
829
- opts = opts || {};
830
- const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
831
- const cmd = this.createCommand(name);
832
- if (desc) {
833
- cmd.description(desc);
834
- cmd._executableHandler = true;
835
- }
836
- if (opts.isDefault)
837
- this._defaultCommandName = cmd._name;
838
- cmd._hidden = !!(opts.noHelp || opts.hidden);
839
- cmd._executableFile = opts.executableFile || null;
840
- if (args)
841
- cmd.arguments(args);
842
- this._registerCommand(cmd);
843
- cmd.parent = this;
844
- cmd.copyInheritedSettings(this);
845
- if (desc)
846
- return this;
847
- return cmd;
848
- }
849
- createCommand(name) {
850
- return new Command(name);
851
- }
852
- createHelp() {
853
- return Object.assign(new Help, this.configureHelp());
854
- }
855
- configureHelp(configuration) {
856
- if (configuration === undefined)
857
- return this._helpConfiguration;
858
- this._helpConfiguration = configuration;
859
- return this;
860
- }
861
- configureOutput(configuration) {
862
- if (configuration === undefined)
863
- return this._outputConfiguration;
864
- this._outputConfiguration = {
865
- ...this._outputConfiguration,
866
- ...configuration
867
- };
868
- return this;
706
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/lib/command.js
707
+ class Command extends EventEmitter {
708
+ constructor(name) {
709
+ super();
710
+ this.commands = [];
711
+ this.options = [];
712
+ this.parent = null;
713
+ this._allowUnknownOption = false;
714
+ this._allowExcessArguments = false;
715
+ this.registeredArguments = [];
716
+ this._args = this.registeredArguments;
717
+ this.args = [];
718
+ this.rawArgs = [];
719
+ this.processedArgs = [];
720
+ this._scriptPath = null;
721
+ this._name = name || "";
722
+ this._optionValues = {};
723
+ this._optionValueSources = {};
724
+ this._storeOptionsAsProperties = false;
725
+ this._actionHandler = null;
726
+ this._executableHandler = false;
727
+ this._executableFile = null;
728
+ this._executableDir = null;
729
+ this._defaultCommandName = null;
730
+ this._exitCallback = null;
731
+ this._aliases = [];
732
+ this._combineFlagAndOptionalValue = true;
733
+ this._description = "";
734
+ this._summary = "";
735
+ this._argsDescription = undefined;
736
+ this._enablePositionalOptions = false;
737
+ this._passThroughOptions = false;
738
+ this._lifeCycleHooks = {};
739
+ this._showHelpAfterError = false;
740
+ this._showSuggestionAfterError = true;
741
+ this._savedState = null;
742
+ this._outputConfiguration = {
743
+ writeOut: (str) => process2.stdout.write(str),
744
+ writeErr: (str) => process2.stderr.write(str),
745
+ outputError: (str, write) => write(str),
746
+ getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
747
+ getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
748
+ getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
749
+ getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
750
+ stripColor: (str) => stripVTControlCharacters2(str)
751
+ };
752
+ this._hidden = false;
753
+ this._helpOption = undefined;
754
+ this._addImplicitHelpCommand = undefined;
755
+ this._helpCommand = undefined;
756
+ this._helpConfiguration = {};
757
+ this._helpGroupHeading = undefined;
758
+ this._defaultCommandGroup = undefined;
759
+ this._defaultOptionGroup = undefined;
760
+ }
761
+ copyInheritedSettings(sourceCommand) {
762
+ this._outputConfiguration = sourceCommand._outputConfiguration;
763
+ this._helpOption = sourceCommand._helpOption;
764
+ this._helpCommand = sourceCommand._helpCommand;
765
+ this._helpConfiguration = sourceCommand._helpConfiguration;
766
+ this._exitCallback = sourceCommand._exitCallback;
767
+ this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
768
+ this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
769
+ this._allowExcessArguments = sourceCommand._allowExcessArguments;
770
+ this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
771
+ this._showHelpAfterError = sourceCommand._showHelpAfterError;
772
+ this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
773
+ return this;
774
+ }
775
+ _getCommandAndAncestors() {
776
+ const result = [];
777
+ for (let command = this;command; command = command.parent) {
778
+ result.push(command);
869
779
  }
870
- showHelpAfterError(displayHelp = true) {
871
- if (typeof displayHelp !== "string")
872
- displayHelp = !!displayHelp;
873
- this._showHelpAfterError = displayHelp;
780
+ return result;
781
+ }
782
+ command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
783
+ let desc = actionOptsOrExecDesc;
784
+ let opts = execOpts;
785
+ if (typeof desc === "object" && desc !== null) {
786
+ opts = desc;
787
+ desc = null;
788
+ }
789
+ opts = opts || {};
790
+ const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
791
+ const cmd = this.createCommand(name);
792
+ if (desc) {
793
+ cmd.description(desc);
794
+ cmd._executableHandler = true;
795
+ }
796
+ if (opts.isDefault)
797
+ this._defaultCommandName = cmd._name;
798
+ cmd._hidden = !!(opts.noHelp || opts.hidden);
799
+ cmd._executableFile = opts.executableFile || null;
800
+ if (args)
801
+ cmd.arguments(args);
802
+ this._registerCommand(cmd);
803
+ cmd.parent = this;
804
+ cmd.copyInheritedSettings(this);
805
+ if (desc)
874
806
  return this;
875
- }
876
- showSuggestionAfterError(displaySuggestion = true) {
877
- this._showSuggestionAfterError = !!displaySuggestion;
878
- return this;
879
- }
880
- addCommand(cmd, opts) {
881
- if (!cmd._name) {
882
- throw new Error(`Command passed to .addCommand() must have a name
807
+ return cmd;
808
+ }
809
+ createCommand(name) {
810
+ return new Command(name);
811
+ }
812
+ createHelp() {
813
+ return Object.assign(new Help, this.configureHelp());
814
+ }
815
+ configureHelp(configuration) {
816
+ if (configuration === undefined)
817
+ return this._helpConfiguration;
818
+ this._helpConfiguration = configuration;
819
+ return this;
820
+ }
821
+ configureOutput(configuration) {
822
+ if (configuration === undefined)
823
+ return this._outputConfiguration;
824
+ this._outputConfiguration = {
825
+ ...this._outputConfiguration,
826
+ ...configuration
827
+ };
828
+ return this;
829
+ }
830
+ showHelpAfterError(displayHelp = true) {
831
+ if (typeof displayHelp !== "string")
832
+ displayHelp = !!displayHelp;
833
+ this._showHelpAfterError = displayHelp;
834
+ return this;
835
+ }
836
+ showSuggestionAfterError(displaySuggestion = true) {
837
+ this._showSuggestionAfterError = !!displaySuggestion;
838
+ return this;
839
+ }
840
+ addCommand(cmd, opts) {
841
+ if (!cmd._name) {
842
+ throw new Error(`Command passed to .addCommand() must have a name
883
843
  - specify the name in Command constructor or using .name()`);
884
- }
885
- opts = opts || {};
886
- if (opts.isDefault)
887
- this._defaultCommandName = cmd._name;
888
- if (opts.noHelp || opts.hidden)
889
- cmd._hidden = true;
890
- this._registerCommand(cmd);
891
- cmd.parent = this;
892
- cmd._checkForBrokenPassThrough();
893
- return this;
894
- }
895
- createArgument(name, description) {
896
- return new Argument(name, description);
897
844
  }
898
- argument(name, description, parseArg, defaultValue) {
899
- const argument = this.createArgument(name, description);
900
- if (typeof parseArg === "function") {
901
- argument.default(defaultValue).argParser(parseArg);
902
- } else {
903
- argument.default(parseArg);
904
- }
905
- this.addArgument(argument);
906
- return this;
907
- }
908
- arguments(names) {
909
- names.trim().split(/ +/).forEach((detail) => {
910
- this.argument(detail);
911
- });
912
- return this;
845
+ opts = opts || {};
846
+ if (opts.isDefault)
847
+ this._defaultCommandName = cmd._name;
848
+ if (opts.noHelp || opts.hidden)
849
+ cmd._hidden = true;
850
+ this._registerCommand(cmd);
851
+ cmd.parent = this;
852
+ cmd._checkForBrokenPassThrough();
853
+ return this;
854
+ }
855
+ createArgument(name, description) {
856
+ return new Argument(name, description);
857
+ }
858
+ argument(name, description, parseArg, defaultValue) {
859
+ const argument = this.createArgument(name, description);
860
+ if (typeof parseArg === "function") {
861
+ argument.default(defaultValue).argParser(parseArg);
862
+ } else {
863
+ argument.default(parseArg);
864
+ }
865
+ this.addArgument(argument);
866
+ return this;
867
+ }
868
+ arguments(names) {
869
+ names.trim().split(/ +/).forEach((detail) => {
870
+ this.argument(detail);
871
+ });
872
+ return this;
873
+ }
874
+ addArgument(argument) {
875
+ const previousArgument = this.registeredArguments.slice(-1)[0];
876
+ if (previousArgument?.variadic) {
877
+ throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
913
878
  }
914
- addArgument(argument) {
915
- const previousArgument = this.registeredArguments.slice(-1)[0];
916
- if (previousArgument?.variadic) {
917
- throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
918
- }
919
- if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
920
- throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
921
- }
922
- this.registeredArguments.push(argument);
923
- return this;
879
+ if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
880
+ throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
924
881
  }
925
- helpCommand(enableOrNameAndArgs, description) {
926
- if (typeof enableOrNameAndArgs === "boolean") {
927
- this._addImplicitHelpCommand = enableOrNameAndArgs;
928
- if (enableOrNameAndArgs && this._defaultCommandGroup) {
929
- this._initCommandGroup(this._getHelpCommand());
930
- }
931
- return this;
882
+ this.registeredArguments.push(argument);
883
+ return this;
884
+ }
885
+ helpCommand(enableOrNameAndArgs, description) {
886
+ if (typeof enableOrNameAndArgs === "boolean") {
887
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
888
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
889
+ this._initCommandGroup(this._getHelpCommand());
932
890
  }
933
- const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
934
- const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
935
- const helpDescription = description ?? "display help for command";
936
- const helpCommand = this.createCommand(helpName);
937
- helpCommand.helpOption(false);
938
- if (helpArgs)
939
- helpCommand.arguments(helpArgs);
940
- if (helpDescription)
941
- helpCommand.description(helpDescription);
942
- this._addImplicitHelpCommand = true;
943
- this._helpCommand = helpCommand;
944
- if (enableOrNameAndArgs || description)
945
- this._initCommandGroup(helpCommand);
946
891
  return this;
947
892
  }
948
- addHelpCommand(helpCommand, deprecatedDescription) {
949
- if (typeof helpCommand !== "object") {
950
- this.helpCommand(helpCommand, deprecatedDescription);
951
- return this;
952
- }
953
- this._addImplicitHelpCommand = true;
954
- this._helpCommand = helpCommand;
893
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
894
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
895
+ const helpDescription = description ?? "display help for command";
896
+ const helpCommand = this.createCommand(helpName);
897
+ helpCommand.helpOption(false);
898
+ if (helpArgs)
899
+ helpCommand.arguments(helpArgs);
900
+ if (helpDescription)
901
+ helpCommand.description(helpDescription);
902
+ this._addImplicitHelpCommand = true;
903
+ this._helpCommand = helpCommand;
904
+ if (enableOrNameAndArgs || description)
955
905
  this._initCommandGroup(helpCommand);
906
+ return this;
907
+ }
908
+ addHelpCommand(helpCommand, deprecatedDescription) {
909
+ if (typeof helpCommand !== "object") {
910
+ this.helpCommand(helpCommand, deprecatedDescription);
956
911
  return this;
957
912
  }
958
- _getHelpCommand() {
959
- const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
960
- if (hasImplicitHelpCommand) {
961
- if (this._helpCommand === undefined) {
962
- this.helpCommand(undefined, undefined);
963
- }
964
- return this._helpCommand;
913
+ this._addImplicitHelpCommand = true;
914
+ this._helpCommand = helpCommand;
915
+ this._initCommandGroup(helpCommand);
916
+ return this;
917
+ }
918
+ _getHelpCommand() {
919
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
920
+ if (hasImplicitHelpCommand) {
921
+ if (this._helpCommand === undefined) {
922
+ this.helpCommand(undefined, undefined);
965
923
  }
966
- return null;
924
+ return this._helpCommand;
967
925
  }
968
- hook(event, listener) {
969
- const allowedValues = ["preSubcommand", "preAction", "postAction"];
970
- if (!allowedValues.includes(event)) {
971
- throw new Error(`Unexpected value for event passed to hook : '${event}'.
926
+ return null;
927
+ }
928
+ hook(event, listener) {
929
+ const allowedValues = ["preSubcommand", "preAction", "postAction"];
930
+ if (!allowedValues.includes(event)) {
931
+ throw new Error(`Unexpected value for event passed to hook : '${event}'.
972
932
  Expecting one of '${allowedValues.join("', '")}'`);
973
- }
974
- if (this._lifeCycleHooks[event]) {
975
- this._lifeCycleHooks[event].push(listener);
976
- } else {
977
- this._lifeCycleHooks[event] = [listener];
978
- }
979
- return this;
980
933
  }
981
- exitOverride(fn) {
982
- if (fn) {
983
- this._exitCallback = fn;
984
- } else {
985
- this._exitCallback = (err) => {
986
- if (err.code !== "commander.executeSubCommandAsync") {
987
- throw err;
988
- }
989
- };
990
- }
991
- return this;
934
+ if (this._lifeCycleHooks[event]) {
935
+ this._lifeCycleHooks[event].push(listener);
936
+ } else {
937
+ this._lifeCycleHooks[event] = [listener];
992
938
  }
993
- _exit(exitCode, code, message) {
994
- if (this._exitCallback) {
995
- this._exitCallback(new CommanderError(exitCode, code, message));
996
- }
997
- process2.exit(exitCode);
998
- }
999
- action(fn) {
1000
- const listener = (args) => {
1001
- const expectedArgsCount = this.registeredArguments.length;
1002
- const actionArgs = args.slice(0, expectedArgsCount);
1003
- if (this._storeOptionsAsProperties) {
1004
- actionArgs[expectedArgsCount] = this;
1005
- } else {
1006
- actionArgs[expectedArgsCount] = this.opts();
939
+ return this;
940
+ }
941
+ exitOverride(fn) {
942
+ if (fn) {
943
+ this._exitCallback = fn;
944
+ } else {
945
+ this._exitCallback = (err) => {
946
+ if (err.code !== "commander.executeSubCommandAsync") {
947
+ throw err;
1007
948
  }
1008
- actionArgs.push(this);
1009
- return fn.apply(this, actionArgs);
1010
949
  };
1011
- this._actionHandler = listener;
1012
- return this;
1013
950
  }
1014
- createOption(flags, description) {
1015
- return new Option(flags, description);
951
+ return this;
952
+ }
953
+ _exit(exitCode, code, message) {
954
+ if (this._exitCallback) {
955
+ this._exitCallback(new CommanderError(exitCode, code, message));
1016
956
  }
1017
- _callParseArg(target, value, previous, invalidArgumentMessage) {
1018
- try {
1019
- return target.parseArg(value, previous);
1020
- } catch (err) {
1021
- if (err.code === "commander.invalidArgument") {
1022
- const message = `${invalidArgumentMessage} ${err.message}`;
1023
- this.error(message, { exitCode: err.exitCode, code: err.code });
1024
- }
1025
- throw err;
957
+ process2.exit(exitCode);
958
+ }
959
+ action(fn) {
960
+ const listener = (args) => {
961
+ const expectedArgsCount = this.registeredArguments.length;
962
+ const actionArgs = args.slice(0, expectedArgsCount);
963
+ if (this._storeOptionsAsProperties) {
964
+ actionArgs[expectedArgsCount] = this;
965
+ } else {
966
+ actionArgs[expectedArgsCount] = this.opts();
1026
967
  }
1027
- }
1028
- _registerOption(option) {
1029
- const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
1030
- if (matchingOption) {
1031
- const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
1032
- throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
1033
- - already used by option '${matchingOption.flags}'`);
968
+ actionArgs.push(this);
969
+ return fn.apply(this, actionArgs);
970
+ };
971
+ this._actionHandler = listener;
972
+ return this;
973
+ }
974
+ createOption(flags, description) {
975
+ return new Option(flags, description);
976
+ }
977
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
978
+ try {
979
+ return target.parseArg(value, previous);
980
+ } catch (err) {
981
+ if (err.code === "commander.invalidArgument") {
982
+ const message = `${invalidArgumentMessage} ${err.message}`;
983
+ this.error(message, { exitCode: err.exitCode, code: err.code });
1034
984
  }
1035
- this._initOptionGroup(option);
1036
- this.options.push(option);
985
+ throw err;
1037
986
  }
1038
- _registerCommand(command) {
1039
- const knownBy = (cmd) => {
1040
- return [cmd.name()].concat(cmd.aliases());
1041
- };
1042
- const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
1043
- if (alreadyUsed) {
1044
- const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1045
- const newCmd = knownBy(command).join("|");
1046
- throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1047
- }
1048
- this._initCommandGroup(command);
1049
- this.commands.push(command);
987
+ }
988
+ _registerOption(option) {
989
+ const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
990
+ if (matchingOption) {
991
+ const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
992
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
993
+ - already used by option '${matchingOption.flags}'`);
1050
994
  }
1051
- addOption(option) {
1052
- this._registerOption(option);
1053
- const oname = option.name();
1054
- const name = option.attributeName();
1055
- if (option.negate) {
1056
- const positiveLongFlag = option.long.replace(/^--no-/, "--");
1057
- if (!this._findOption(positiveLongFlag)) {
1058
- this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
995
+ this._initOptionGroup(option);
996
+ this.options.push(option);
997
+ }
998
+ _registerCommand(command) {
999
+ const knownBy = (cmd) => {
1000
+ return [cmd.name()].concat(cmd.aliases());
1001
+ };
1002
+ const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
1003
+ if (alreadyUsed) {
1004
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
1005
+ const newCmd = knownBy(command).join("|");
1006
+ throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
1007
+ }
1008
+ this._initCommandGroup(command);
1009
+ this.commands.push(command);
1010
+ }
1011
+ addOption(option) {
1012
+ this._registerOption(option);
1013
+ const oname = option.name();
1014
+ const name = option.attributeName();
1015
+ if (option.defaultValue !== undefined) {
1016
+ this.setOptionValueWithSource(name, option.defaultValue, "default");
1017
+ }
1018
+ const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1019
+ if (val == null && option.presetArg !== undefined) {
1020
+ val = option.presetArg;
1021
+ }
1022
+ const oldValue = this.getOptionValue(name);
1023
+ if (val !== null && option.parseArg) {
1024
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1025
+ } else if (val !== null && option.variadic) {
1026
+ val = option._collectValue(val, oldValue);
1027
+ }
1028
+ if (val == null) {
1029
+ if (option.negate) {
1030
+ val = false;
1031
+ } else if (option.isBoolean() || option.optional) {
1032
+ val = true;
1033
+ } else {
1034
+ val = "";
1059
1035
  }
1060
- } else if (option.defaultValue !== undefined) {
1061
- this.setOptionValueWithSource(name, option.defaultValue, "default");
1062
1036
  }
1063
- const handleOptionValue = (val, invalidValueMessage, valueSource) => {
1064
- if (val == null && option.presetArg !== undefined) {
1065
- val = option.presetArg;
1066
- }
1067
- const oldValue = this.getOptionValue(name);
1068
- if (val !== null && option.parseArg) {
1069
- val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1070
- } else if (val !== null && option.variadic) {
1071
- val = option._collectValue(val, oldValue);
1072
- }
1073
- if (val == null) {
1074
- if (option.negate) {
1075
- val = false;
1076
- } else if (option.isBoolean() || option.optional) {
1077
- val = true;
1078
- } else {
1079
- val = "";
1080
- }
1081
- }
1082
- this.setOptionValueWithSource(name, val, valueSource);
1083
- };
1084
- this.on("option:" + oname, (val) => {
1085
- const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1086
- handleOptionValue(val, invalidValueMessage, "cli");
1037
+ this.setOptionValueWithSource(name, val, valueSource);
1038
+ };
1039
+ this.on("option:" + oname, (val) => {
1040
+ const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
1041
+ handleOptionValue(val, invalidValueMessage, "cli");
1042
+ });
1043
+ if (option.envVar) {
1044
+ this.on("optionEnv:" + oname, (val) => {
1045
+ const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1046
+ handleOptionValue(val, invalidValueMessage, "env");
1087
1047
  });
1088
- if (option.envVar) {
1089
- this.on("optionEnv:" + oname, (val) => {
1090
- const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
1091
- handleOptionValue(val, invalidValueMessage, "env");
1092
- });
1093
- }
1094
- return this;
1095
- }
1096
- _optionEx(config, flags, description, fn, defaultValue) {
1097
- if (typeof flags === "object" && flags instanceof Option) {
1098
- throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
1099
- }
1100
- const option = this.createOption(flags, description);
1101
- option.makeOptionMandatory(!!config.mandatory);
1102
- if (typeof fn === "function") {
1103
- option.default(defaultValue).argParser(fn);
1104
- } else if (fn instanceof RegExp) {
1105
- const regex = fn;
1106
- fn = (val, def) => {
1107
- const m = regex.exec(val);
1108
- return m ? m[0] : def;
1109
- };
1110
- option.default(defaultValue).argParser(fn);
1111
- } else {
1112
- option.default(fn);
1113
- }
1114
- return this.addOption(option);
1115
1048
  }
1116
- option(flags, description, parseArg, defaultValue) {
1117
- return this._optionEx({}, flags, description, parseArg, defaultValue);
1118
- }
1119
- requiredOption(flags, description, parseArg, defaultValue) {
1120
- return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1121
- }
1122
- combineFlagAndOptionalValue(combine = true) {
1123
- this._combineFlagAndOptionalValue = !!combine;
1124
- return this;
1125
- }
1126
- allowUnknownOption(allowUnknown = true) {
1127
- this._allowUnknownOption = !!allowUnknown;
1128
- return this;
1129
- }
1130
- allowExcessArguments(allowExcess = true) {
1131
- this._allowExcessArguments = !!allowExcess;
1132
- return this;
1133
- }
1134
- enablePositionalOptions(positional = true) {
1135
- this._enablePositionalOptions = !!positional;
1136
- return this;
1137
- }
1138
- passThroughOptions(passThrough = true) {
1139
- this._passThroughOptions = !!passThrough;
1140
- this._checkForBrokenPassThrough();
1141
- return this;
1142
- }
1143
- _checkForBrokenPassThrough() {
1144
- if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1145
- throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
1146
- }
1147
- }
1148
- storeOptionsAsProperties(storeAsProperties = true) {
1149
- if (this.options.length) {
1150
- throw new Error("call .storeOptionsAsProperties() before adding options");
1151
- }
1152
- if (Object.keys(this._optionValues).length) {
1153
- throw new Error("call .storeOptionsAsProperties() before setting option values");
1154
- }
1155
- this._storeOptionsAsProperties = !!storeAsProperties;
1156
- return this;
1157
- }
1158
- getOptionValue(key) {
1159
- if (this._storeOptionsAsProperties) {
1160
- return this[key];
1161
- }
1162
- return this._optionValues[key];
1049
+ return this;
1050
+ }
1051
+ _optionEx(config, flags, description, fn, defaultValue) {
1052
+ if (typeof flags === "object" && flags instanceof Option) {
1053
+ throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
1054
+ }
1055
+ const option = this.createOption(flags, description);
1056
+ option.makeOptionMandatory(!!config.mandatory);
1057
+ if (typeof fn === "function") {
1058
+ option.default(defaultValue).argParser(fn);
1059
+ } else if (fn instanceof RegExp) {
1060
+ const regex = fn;
1061
+ fn = (val, def) => {
1062
+ const m = regex.exec(val);
1063
+ return m ? m[0] : def;
1064
+ };
1065
+ option.default(defaultValue).argParser(fn);
1066
+ } else {
1067
+ option.default(fn);
1163
1068
  }
1164
- setOptionValue(key, value) {
1165
- return this.setOptionValueWithSource(key, value, undefined);
1069
+ return this.addOption(option);
1070
+ }
1071
+ option(flags, description, parseArg, defaultValue) {
1072
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
1073
+ }
1074
+ requiredOption(flags, description, parseArg, defaultValue) {
1075
+ return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1076
+ }
1077
+ combineFlagAndOptionalValue(combine = true) {
1078
+ this._combineFlagAndOptionalValue = !!combine;
1079
+ return this;
1080
+ }
1081
+ allowUnknownOption(allowUnknown = true) {
1082
+ this._allowUnknownOption = !!allowUnknown;
1083
+ return this;
1084
+ }
1085
+ allowExcessArguments(allowExcess = true) {
1086
+ this._allowExcessArguments = !!allowExcess;
1087
+ return this;
1088
+ }
1089
+ enablePositionalOptions(positional = true) {
1090
+ this._enablePositionalOptions = !!positional;
1091
+ return this;
1092
+ }
1093
+ passThroughOptions(passThrough = true) {
1094
+ this._passThroughOptions = !!passThrough;
1095
+ this._checkForBrokenPassThrough();
1096
+ return this;
1097
+ }
1098
+ _checkForBrokenPassThrough() {
1099
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
1100
+ throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
1166
1101
  }
1167
- setOptionValueWithSource(key, value, source) {
1168
- if (this._storeOptionsAsProperties) {
1169
- this[key] = value;
1170
- } else {
1171
- this._optionValues[key] = value;
1172
- }
1173
- this._optionValueSources[key] = source;
1174
- return this;
1102
+ }
1103
+ storeOptionsAsProperties(storeAsProperties = true) {
1104
+ if (this.options.length) {
1105
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1175
1106
  }
1176
- getOptionValueSource(key) {
1177
- return this._optionValueSources[key];
1107
+ if (Object.keys(this._optionValues).length) {
1108
+ throw new Error("call .storeOptionsAsProperties() before setting option values");
1178
1109
  }
1179
- getOptionValueSourceWithGlobals(key) {
1180
- let source;
1181
- this._getCommandAndAncestors().forEach((cmd) => {
1182
- if (cmd.getOptionValueSource(key) !== undefined) {
1183
- source = cmd.getOptionValueSource(key);
1184
- }
1185
- });
1186
- return source;
1110
+ this._storeOptionsAsProperties = !!storeAsProperties;
1111
+ return this;
1112
+ }
1113
+ getOptionValue(key) {
1114
+ if (this._storeOptionsAsProperties) {
1115
+ return this[key];
1187
1116
  }
1188
- _prepareUserArgs(argv2, parseOptions) {
1189
- if (argv2 !== undefined && !Array.isArray(argv2)) {
1190
- throw new Error("first parameter to parse must be array or undefined");
1117
+ return this._optionValues[key];
1118
+ }
1119
+ setOptionValue(key, value) {
1120
+ return this.setOptionValueWithSource(key, value, undefined);
1121
+ }
1122
+ setOptionValueWithSource(key, value, source) {
1123
+ if (this._storeOptionsAsProperties) {
1124
+ this[key] = value;
1125
+ } else {
1126
+ this._optionValues[key] = value;
1127
+ }
1128
+ this._optionValueSources[key] = source;
1129
+ return this;
1130
+ }
1131
+ getOptionValueSource(key) {
1132
+ return this._optionValueSources[key];
1133
+ }
1134
+ getOptionValueSourceWithGlobals(key) {
1135
+ let source;
1136
+ this._getCommandAndAncestors().forEach((cmd) => {
1137
+ if (cmd.getOptionValueSource(key) !== undefined) {
1138
+ source = cmd.getOptionValueSource(key);
1191
1139
  }
1192
- parseOptions = parseOptions || {};
1193
- if (argv2 === undefined && parseOptions.from === undefined) {
1194
- if (process2.versions?.electron) {
1195
- parseOptions.from = "electron";
1140
+ });
1141
+ return source;
1142
+ }
1143
+ _prepareUserArgs(argv, parseOptions) {
1144
+ if (argv !== undefined && !Array.isArray(argv)) {
1145
+ throw new Error("first parameter to parse must be array or undefined");
1146
+ }
1147
+ parseOptions = parseOptions || {};
1148
+ if (argv === undefined && parseOptions.from === undefined) {
1149
+ if (process2.versions?.electron) {
1150
+ parseOptions.from = "electron";
1151
+ }
1152
+ const execArgv = process2.execArgv ?? [];
1153
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
1154
+ parseOptions.from = "eval";
1155
+ }
1156
+ }
1157
+ if (argv === undefined) {
1158
+ argv = process2.argv;
1159
+ }
1160
+ this.rawArgs = argv.slice();
1161
+ let userArgs;
1162
+ switch (parseOptions.from) {
1163
+ case undefined:
1164
+ case "node":
1165
+ this._scriptPath = argv[1];
1166
+ userArgs = argv.slice(2);
1167
+ break;
1168
+ case "electron":
1169
+ if (process2.defaultApp) {
1170
+ this._scriptPath = argv[1];
1171
+ userArgs = argv.slice(2);
1172
+ } else {
1173
+ userArgs = argv.slice(1);
1196
1174
  }
1197
- const execArgv2 = process2.execArgv ?? [];
1198
- if (execArgv2.includes("-e") || execArgv2.includes("--eval") || execArgv2.includes("-p") || execArgv2.includes("--print")) {
1199
- parseOptions.from = "eval";
1175
+ break;
1176
+ case "user":
1177
+ userArgs = argv.slice(0);
1178
+ break;
1179
+ case "eval":
1180
+ userArgs = argv.slice(1);
1181
+ break;
1182
+ default:
1183
+ throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
1184
+ }
1185
+ if (!this._name && this._scriptPath)
1186
+ this.nameFromFilename(this._scriptPath);
1187
+ this._name = this._name || "program";
1188
+ return userArgs;
1189
+ }
1190
+ parse(argv, parseOptions) {
1191
+ this._prepareForParse();
1192
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1193
+ this._parseCommand([], userArgs);
1194
+ return this;
1195
+ }
1196
+ async parseAsync(argv, parseOptions) {
1197
+ this._prepareForParse();
1198
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
1199
+ await this._parseCommand([], userArgs);
1200
+ return this;
1201
+ }
1202
+ _prepareForParse() {
1203
+ if (this._savedState === null) {
1204
+ this.options.filter((option) => option.negate && option.defaultValue === undefined && this.getOptionValue(option.attributeName()) === undefined).forEach((option) => {
1205
+ const positiveLongFlag = option.long.replace(/^--no-/, "--");
1206
+ if (!this._findOption(positiveLongFlag)) {
1207
+ this.setOptionValueWithSource(option.attributeName(), true, "default");
1200
1208
  }
1201
- }
1202
- if (argv2 === undefined) {
1203
- argv2 = process2.argv;
1204
- }
1205
- this.rawArgs = argv2.slice();
1206
- let userArgs;
1207
- switch (parseOptions.from) {
1208
- case undefined:
1209
- case "node":
1210
- this._scriptPath = argv2[1];
1211
- userArgs = argv2.slice(2);
1212
- break;
1213
- case "electron":
1214
- if (process2.defaultApp) {
1215
- this._scriptPath = argv2[1];
1216
- userArgs = argv2.slice(2);
1217
- } else {
1218
- userArgs = argv2.slice(1);
1219
- }
1220
- break;
1221
- case "user":
1222
- userArgs = argv2.slice(0);
1223
- break;
1224
- case "eval":
1225
- userArgs = argv2.slice(1);
1226
- break;
1227
- default:
1228
- throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
1229
- }
1230
- if (!this._name && this._scriptPath)
1231
- this.nameFromFilename(this._scriptPath);
1232
- this._name = this._name || "program";
1233
- return userArgs;
1234
- }
1235
- parse(argv, parseOptions) {
1236
- this._prepareForParse();
1237
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1238
- this._parseCommand([], userArgs);
1239
- return this;
1240
- }
1241
- async parseAsync(argv, parseOptions) {
1242
- this._prepareForParse();
1243
- const userArgs = this._prepareUserArgs(argv, parseOptions);
1244
- await this._parseCommand([], userArgs);
1245
- return this;
1246
- }
1247
- _prepareForParse() {
1248
- if (this._savedState === null) {
1249
- this.saveStateBeforeParse();
1250
- } else {
1251
- this.restoreStateBeforeParse();
1252
- }
1253
- }
1254
- saveStateBeforeParse() {
1255
- this._savedState = {
1256
- _name: this._name,
1257
- _optionValues: { ...this._optionValues },
1258
- _optionValueSources: { ...this._optionValueSources }
1259
- };
1209
+ });
1210
+ this.saveStateBeforeParse();
1211
+ } else {
1212
+ this.restoreStateBeforeParse();
1260
1213
  }
1261
- restoreStateBeforeParse() {
1262
- if (this._storeOptionsAsProperties)
1263
- throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
1214
+ }
1215
+ saveStateBeforeParse() {
1216
+ this._savedState = {
1217
+ _name: this._name,
1218
+ _optionValues: { ...this._optionValues },
1219
+ _optionValueSources: { ...this._optionValueSources }
1220
+ };
1221
+ }
1222
+ restoreStateBeforeParse() {
1223
+ if (this._storeOptionsAsProperties)
1224
+ throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
1264
1225
  - either make a new Command for each call to parse, or stop storing options as properties`);
1265
- this._name = this._savedState._name;
1266
- this._scriptPath = null;
1267
- this.rawArgs = [];
1268
- this._optionValues = { ...this._savedState._optionValues };
1269
- this._optionValueSources = { ...this._savedState._optionValueSources };
1270
- this.args = [];
1271
- this.processedArgs = [];
1272
- }
1273
- _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1274
- if (fs.existsSync(executableFile))
1275
- return;
1276
- const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
1277
- const executableMissing = `'${executableFile}' does not exist
1226
+ this._name = this._savedState._name;
1227
+ this._scriptPath = null;
1228
+ this.rawArgs = [];
1229
+ this._optionValues = { ...this._savedState._optionValues };
1230
+ this._optionValueSources = { ...this._savedState._optionValueSources };
1231
+ this.args = [];
1232
+ this.processedArgs = [];
1233
+ }
1234
+ _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1235
+ if (fs.existsSync(executableFile))
1236
+ return;
1237
+ const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
1238
+ const executableMissing = `'${executableFile}' does not exist
1278
1239
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1279
1240
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1280
1241
  - ${executableDirMessage}`;
1281
- throw new Error(executableMissing);
1282
- }
1283
- _executeSubCommand(subcommand, args) {
1284
- args = args.slice();
1285
- let launchWithNode = false;
1286
- const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1287
- function findFile(baseDir, baseName) {
1288
- const localBin = path.resolve(baseDir, baseName);
1289
- if (fs.existsSync(localBin))
1290
- return localBin;
1291
- if (sourceExt.includes(path.extname(baseName)))
1292
- return;
1293
- const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1294
- if (foundExt)
1295
- return `${localBin}${foundExt}`;
1242
+ throw new Error(executableMissing);
1243
+ }
1244
+ _executeSubCommand(subcommand, args) {
1245
+ args = args.slice();
1246
+ const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1247
+ function findFile(baseDir, baseName) {
1248
+ const localBin = path.resolve(baseDir, baseName);
1249
+ if (fs.existsSync(localBin))
1250
+ return localBin;
1251
+ if (sourceExt.includes(path.extname(baseName)))
1296
1252
  return;
1297
- }
1298
- this._checkForMissingMandatoryOptions();
1299
- this._checkForConflictingOptions();
1300
- let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1301
- let executableDir = this._executableDir || "";
1302
- if (this._scriptPath) {
1303
- let resolvedScriptPath;
1304
- try {
1305
- resolvedScriptPath = fs.realpathSync(this._scriptPath);
1306
- } catch {
1307
- resolvedScriptPath = this._scriptPath;
1308
- }
1309
- executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1310
- }
1311
- if (executableDir) {
1312
- let localFile = findFile(executableDir, executableFile);
1313
- if (!localFile && !subcommand._executableFile && this._scriptPath) {
1314
- const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1315
- if (legacyName !== this._name) {
1316
- localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1317
- }
1253
+ const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
1254
+ if (foundExt)
1255
+ return `${localBin}${foundExt}`;
1256
+ return;
1257
+ }
1258
+ this._checkForMissingMandatoryOptions();
1259
+ this._checkForConflictingOptions();
1260
+ let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
1261
+ let executableDir = this._executableDir || "";
1262
+ if (this._scriptPath) {
1263
+ let resolvedScriptPath;
1264
+ try {
1265
+ resolvedScriptPath = fs.realpathSync(this._scriptPath);
1266
+ } catch {
1267
+ resolvedScriptPath = this._scriptPath;
1268
+ }
1269
+ executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
1270
+ }
1271
+ if (executableDir) {
1272
+ let localFile = findFile(executableDir, executableFile);
1273
+ if (!localFile && !subcommand._executableFile && this._scriptPath) {
1274
+ const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
1275
+ if (legacyName !== this._name) {
1276
+ localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1318
1277
  }
1319
- executableFile = localFile || executableFile;
1320
1278
  }
1321
- launchWithNode = sourceExt.includes(path.extname(executableFile));
1322
- let proc;
1323
- if (process2.platform !== "win32") {
1324
- if (launchWithNode) {
1325
- args.unshift(executableFile);
1326
- args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1327
- proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
1328
- } else {
1329
- proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1330
- }
1331
- } else {
1332
- this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1279
+ executableFile = localFile || executableFile;
1280
+ }
1281
+ const launchWithNode = sourceExt.includes(path.extname(executableFile));
1282
+ let proc;
1283
+ if (process2.platform !== "win32") {
1284
+ if (launchWithNode) {
1333
1285
  args.unshift(executableFile);
1334
1286
  args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1335
- proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
1336
- }
1337
- if (!proc.killed) {
1338
- const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1339
- signals.forEach((signal) => {
1340
- process2.on(signal, () => {
1341
- if (proc.killed === false && proc.exitCode === null) {
1342
- proc.kill(signal);
1343
- }
1344
- });
1287
+ proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
1288
+ } else {
1289
+ proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1290
+ }
1291
+ } else {
1292
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1293
+ args.unshift(executableFile);
1294
+ args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1295
+ proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
1296
+ }
1297
+ if (!proc.killed) {
1298
+ const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
1299
+ signals.forEach((signal) => {
1300
+ process2.on(signal, () => {
1301
+ if (proc.killed === false && proc.exitCode === null) {
1302
+ proc.kill(signal);
1303
+ }
1345
1304
  });
1346
- }
1347
- const exitCallback = this._exitCallback;
1348
- proc.on("close", (code) => {
1349
- code = code ?? 1;
1350
- if (!exitCallback) {
1351
- process2.exit(code);
1352
- } else {
1353
- exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
1354
- }
1355
- });
1356
- proc.on("error", (err) => {
1357
- if (err.code === "ENOENT") {
1358
- this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1359
- } else if (err.code === "EACCES") {
1360
- throw new Error(`'${executableFile}' not executable`);
1361
- }
1362
- if (!exitCallback) {
1363
- process2.exit(1);
1364
- } else {
1365
- const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
1366
- wrappedError.nestedError = err;
1367
- exitCallback(wrappedError);
1368
- }
1369
1305
  });
1370
- this.runningCommand = proc;
1371
1306
  }
1372
- _dispatchSubcommand(commandName, operands, unknown) {
1373
- const subCommand = this._findCommand(commandName);
1374
- if (!subCommand)
1375
- this.help({ error: true });
1376
- subCommand._prepareForParse();
1377
- let promiseChain;
1378
- promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1379
- promiseChain = this._chainOrCall(promiseChain, () => {
1380
- if (subCommand._executableHandler) {
1381
- this._executeSubCommand(subCommand, operands.concat(unknown));
1382
- } else {
1383
- return subCommand._parseCommand(operands, unknown);
1384
- }
1385
- });
1386
- return promiseChain;
1387
- }
1388
- _dispatchHelpCommand(subcommandName) {
1389
- if (!subcommandName) {
1390
- this.help();
1307
+ const exitCallback = this._exitCallback;
1308
+ proc.on("close", (code) => {
1309
+ code = code ?? 1;
1310
+ if (!exitCallback) {
1311
+ process2.exit(code);
1312
+ } else {
1313
+ exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
1391
1314
  }
1392
- const subCommand = this._findCommand(subcommandName);
1393
- if (subCommand && !subCommand._executableHandler) {
1394
- subCommand.help();
1315
+ });
1316
+ proc.on("error", (err) => {
1317
+ if (err.code === "ENOENT") {
1318
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1319
+ } else if (err.code === "EACCES") {
1320
+ throw new Error(`'${executableFile}' not executable`);
1395
1321
  }
1396
- return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
1397
- }
1398
- _checkNumberOfArguments() {
1399
- this.registeredArguments.forEach((arg, i) => {
1400
- if (arg.required && this.args[i] == null) {
1401
- this.missingArgument(arg.name());
1402
- }
1403
- });
1404
- if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1405
- return;
1322
+ if (!exitCallback) {
1323
+ process2.exit(1);
1324
+ } else {
1325
+ const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
1326
+ wrappedError.nestedError = err;
1327
+ exitCallback(wrappedError);
1406
1328
  }
1407
- if (this.args.length > this.registeredArguments.length) {
1408
- this._excessArguments(this.args);
1329
+ });
1330
+ this.runningCommand = proc;
1331
+ }
1332
+ _dispatchSubcommand(commandName, operands, unknown) {
1333
+ const subCommand = this._findCommand(commandName);
1334
+ if (!subCommand)
1335
+ this.help({ error: true });
1336
+ subCommand._prepareForParse();
1337
+ let promiseChain;
1338
+ promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1339
+ promiseChain = this._chainOrCall(promiseChain, () => {
1340
+ if (subCommand._executableHandler) {
1341
+ this._executeSubCommand(subCommand, operands.concat(unknown));
1342
+ } else {
1343
+ return subCommand._parseCommand(operands, unknown);
1409
1344
  }
1345
+ });
1346
+ return promiseChain;
1347
+ }
1348
+ _dispatchHelpCommand(subcommandName) {
1349
+ if (!subcommandName) {
1350
+ this.help();
1410
1351
  }
1411
- _processArguments() {
1412
- const myParseArg = (argument, value, previous) => {
1413
- let parsedValue = value;
1414
- if (value !== null && argument.parseArg) {
1415
- const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1416
- parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1417
- }
1418
- return parsedValue;
1419
- };
1420
- this._checkNumberOfArguments();
1421
- const processedArgs = [];
1422
- this.registeredArguments.forEach((declaredArg, index) => {
1423
- let value = declaredArg.defaultValue;
1424
- if (declaredArg.variadic) {
1425
- if (index < this.args.length) {
1426
- value = this.args.slice(index);
1427
- if (declaredArg.parseArg) {
1428
- value = value.reduce((processed, v) => {
1429
- return myParseArg(declaredArg, v, processed);
1430
- }, declaredArg.defaultValue);
1431
- }
1432
- } else if (value === undefined) {
1433
- value = [];
1434
- }
1435
- } else if (index < this.args.length) {
1436
- value = this.args[index];
1352
+ const subCommand = this._findCommand(subcommandName);
1353
+ if (subCommand && !subCommand._executableHandler) {
1354
+ subCommand.help();
1355
+ }
1356
+ return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
1357
+ }
1358
+ _checkNumberOfArguments() {
1359
+ this.registeredArguments.forEach((arg, i) => {
1360
+ if (arg.required && this.args[i] == null) {
1361
+ this.missingArgument(arg.name());
1362
+ }
1363
+ });
1364
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1365
+ return;
1366
+ }
1367
+ if (this.args.length > this.registeredArguments.length) {
1368
+ this._excessArguments(this.args);
1369
+ }
1370
+ }
1371
+ _processArguments() {
1372
+ const myParseArg = (argument, value, previous) => {
1373
+ let parsedValue = value;
1374
+ if (value !== null && argument.parseArg) {
1375
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1376
+ parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1377
+ }
1378
+ return parsedValue;
1379
+ };
1380
+ this._checkNumberOfArguments();
1381
+ const processedArgs = [];
1382
+ this.registeredArguments.forEach((declaredArg, index) => {
1383
+ let value = declaredArg.defaultValue;
1384
+ if (declaredArg.variadic) {
1385
+ if (index < this.args.length) {
1386
+ value = this.args.slice(index);
1437
1387
  if (declaredArg.parseArg) {
1438
- value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1388
+ value = value.reduce((processed, v) => {
1389
+ return myParseArg(declaredArg, v, processed);
1390
+ }, declaredArg.defaultValue);
1439
1391
  }
1392
+ } else if (value === undefined) {
1393
+ value = [];
1440
1394
  }
1441
- processedArgs[index] = value;
1395
+ } else if (index < this.args.length) {
1396
+ value = this.args[index];
1397
+ if (declaredArg.parseArg) {
1398
+ value = myParseArg(declaredArg, value, declaredArg.defaultValue);
1399
+ }
1400
+ }
1401
+ processedArgs[index] = value;
1402
+ });
1403
+ this.processedArgs = processedArgs;
1404
+ }
1405
+ _chainOrCall(promise, fn) {
1406
+ if (promise?.then && typeof promise.then === "function") {
1407
+ return promise.then(() => fn());
1408
+ }
1409
+ return fn();
1410
+ }
1411
+ _chainOrCallHooks(promise, event) {
1412
+ let result = promise;
1413
+ const hooks = [];
1414
+ this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
1415
+ hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1416
+ hooks.push({ hookedCommand, callback });
1442
1417
  });
1443
- this.processedArgs = processedArgs;
1418
+ });
1419
+ if (event === "postAction") {
1420
+ hooks.reverse();
1444
1421
  }
1445
- _chainOrCall(promise, fn) {
1446
- if (promise?.then && typeof promise.then === "function") {
1447
- return promise.then(() => fn());
1448
- }
1449
- return fn();
1450
- }
1451
- _chainOrCallHooks(promise, event) {
1452
- let result = promise;
1453
- const hooks = [];
1454
- this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
1455
- hookedCommand._lifeCycleHooks[event].forEach((callback) => {
1456
- hooks.push({ hookedCommand, callback });
1457
- });
1422
+ hooks.forEach((hookDetail) => {
1423
+ result = this._chainOrCall(result, () => {
1424
+ return hookDetail.callback(hookDetail.hookedCommand, this);
1458
1425
  });
1459
- if (event === "postAction") {
1460
- hooks.reverse();
1461
- }
1462
- hooks.forEach((hookDetail) => {
1426
+ });
1427
+ return result;
1428
+ }
1429
+ _chainOrCallSubCommandHook(promise, subCommand, event) {
1430
+ let result = promise;
1431
+ if (this._lifeCycleHooks[event] !== undefined) {
1432
+ this._lifeCycleHooks[event].forEach((hook) => {
1463
1433
  result = this._chainOrCall(result, () => {
1464
- return hookDetail.callback(hookDetail.hookedCommand, this);
1434
+ return hook(this, subCommand);
1465
1435
  });
1466
1436
  });
1467
- return result;
1468
1437
  }
1469
- _chainOrCallSubCommandHook(promise, subCommand, event) {
1470
- let result = promise;
1471
- if (this._lifeCycleHooks[event] !== undefined) {
1472
- this._lifeCycleHooks[event].forEach((hook) => {
1473
- result = this._chainOrCall(result, () => {
1474
- return hook(this, subCommand);
1475
- });
1438
+ return result;
1439
+ }
1440
+ _parseCommand(operands, unknown) {
1441
+ const parsed = this.parseOptions(unknown);
1442
+ this._parseOptionsEnv();
1443
+ this._parseOptionsImplied();
1444
+ operands = operands.concat(parsed.operands);
1445
+ unknown = parsed.unknown;
1446
+ this.args = operands.concat(unknown);
1447
+ if (operands && this._findCommand(operands[0])) {
1448
+ return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1449
+ }
1450
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1451
+ return this._dispatchHelpCommand(operands[1]);
1452
+ }
1453
+ if (this._defaultCommandName) {
1454
+ this._outputHelpIfRequested(unknown);
1455
+ return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1456
+ }
1457
+ if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1458
+ this.help({ error: true });
1459
+ }
1460
+ this._outputHelpIfRequested(parsed.unknown);
1461
+ this._checkForMissingMandatoryOptions();
1462
+ this._checkForConflictingOptions();
1463
+ const checkForUnknownOptions = () => {
1464
+ if (parsed.unknown.length > 0) {
1465
+ this.unknownOption(parsed.unknown[0]);
1466
+ }
1467
+ };
1468
+ const commandEvent = `command:${this.name()}`;
1469
+ if (this._actionHandler) {
1470
+ checkForUnknownOptions();
1471
+ this._processArguments();
1472
+ let promiseChain;
1473
+ promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
1474
+ promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1475
+ if (this.parent) {
1476
+ promiseChain = this._chainOrCall(promiseChain, () => {
1477
+ this.parent.emit(commandEvent, operands, unknown);
1476
1478
  });
1477
1479
  }
1478
- return result;
1480
+ promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1481
+ return promiseChain;
1479
1482
  }
1480
- _parseCommand(operands, unknown) {
1481
- const parsed = this.parseOptions(unknown);
1482
- this._parseOptionsEnv();
1483
- this._parseOptionsImplied();
1484
- operands = operands.concat(parsed.operands);
1485
- unknown = parsed.unknown;
1486
- this.args = operands.concat(unknown);
1487
- if (operands && this._findCommand(operands[0])) {
1488
- return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
1489
- }
1490
- if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
1491
- return this._dispatchHelpCommand(operands[1]);
1492
- }
1493
- if (this._defaultCommandName) {
1494
- this._outputHelpIfRequested(unknown);
1495
- return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
1496
- }
1497
- if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
1498
- this.help({ error: true });
1483
+ if (this.parent?.listenerCount(commandEvent)) {
1484
+ checkForUnknownOptions();
1485
+ this._processArguments();
1486
+ this.parent.emit(commandEvent, operands, unknown);
1487
+ } else if (operands.length) {
1488
+ if (this._findCommand("*")) {
1489
+ return this._dispatchSubcommand("*", operands, unknown);
1499
1490
  }
1500
- this._outputHelpIfRequested(parsed.unknown);
1501
- this._checkForMissingMandatoryOptions();
1502
- this._checkForConflictingOptions();
1503
- const checkForUnknownOptions = () => {
1504
- if (parsed.unknown.length > 0) {
1505
- this.unknownOption(parsed.unknown[0]);
1506
- }
1507
- };
1508
- const commandEvent = `command:${this.name()}`;
1509
- if (this._actionHandler) {
1510
- checkForUnknownOptions();
1511
- this._processArguments();
1512
- let promiseChain;
1513
- promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
1514
- promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
1515
- if (this.parent) {
1516
- promiseChain = this._chainOrCall(promiseChain, () => {
1517
- this.parent.emit(commandEvent, operands, unknown);
1518
- });
1519
- }
1520
- promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1521
- return promiseChain;
1522
- }
1523
- if (this.parent?.listenerCount(commandEvent)) {
1524
- checkForUnknownOptions();
1525
- this._processArguments();
1526
- this.parent.emit(commandEvent, operands, unknown);
1527
- } else if (operands.length) {
1528
- if (this._findCommand("*")) {
1529
- return this._dispatchSubcommand("*", operands, unknown);
1530
- }
1531
- if (this.listenerCount("command:*")) {
1532
- this.emit("command:*", operands, unknown);
1533
- } else if (this.commands.length) {
1534
- this.unknownCommand();
1535
- } else {
1536
- checkForUnknownOptions();
1537
- this._processArguments();
1538
- }
1491
+ if (this.listenerCount("command:*")) {
1492
+ this.emit("command:*", operands, unknown);
1539
1493
  } else if (this.commands.length) {
1540
- checkForUnknownOptions();
1541
- this.help({ error: true });
1494
+ this.unknownCommand();
1542
1495
  } else {
1543
1496
  checkForUnknownOptions();
1544
1497
  this._processArguments();
1545
1498
  }
1499
+ } else if (this.commands.length) {
1500
+ checkForUnknownOptions();
1501
+ this.help({ error: true });
1502
+ } else {
1503
+ checkForUnknownOptions();
1504
+ this._processArguments();
1546
1505
  }
1547
- _findCommand(name) {
1548
- if (!name)
1549
- return;
1550
- return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
1551
- }
1552
- _findOption(arg) {
1553
- return this.options.find((option) => option.is(arg));
1554
- }
1555
- _checkForMissingMandatoryOptions() {
1556
- this._getCommandAndAncestors().forEach((cmd) => {
1557
- cmd.options.forEach((anOption) => {
1558
- if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
1559
- cmd.missingMandatoryOptionValue(anOption);
1560
- }
1561
- });
1562
- });
1563
- }
1564
- _checkForConflictingLocalOptions() {
1565
- const definedNonDefaultOptions = this.options.filter((option) => {
1566
- const optionKey = option.attributeName();
1567
- if (this.getOptionValue(optionKey) === undefined) {
1568
- return false;
1569
- }
1570
- return this.getOptionValueSource(optionKey) !== "default";
1571
- });
1572
- const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
1573
- optionsWithConflicting.forEach((option) => {
1574
- const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
1575
- if (conflictingAndDefined) {
1576
- this._conflictingOption(option, conflictingAndDefined);
1506
+ }
1507
+ _findCommand(name) {
1508
+ if (!name)
1509
+ return;
1510
+ return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
1511
+ }
1512
+ _findOption(arg) {
1513
+ return this.options.find((option) => option.is(arg));
1514
+ }
1515
+ _checkForMissingMandatoryOptions() {
1516
+ this._getCommandAndAncestors().forEach((cmd) => {
1517
+ cmd.options.forEach((anOption) => {
1518
+ if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
1519
+ cmd.missingMandatoryOptionValue(anOption);
1577
1520
  }
1578
1521
  });
1579
- }
1580
- _checkForConflictingOptions() {
1581
- this._getCommandAndAncestors().forEach((cmd) => {
1582
- cmd._checkForConflictingLocalOptions();
1583
- });
1584
- }
1585
- parseOptions(args) {
1586
- const operands = [];
1587
- const unknown = [];
1588
- let dest = operands;
1589
- function maybeOption(arg) {
1590
- return arg.length > 1 && arg[0] === "-";
1522
+ });
1523
+ }
1524
+ _checkForConflictingLocalOptions() {
1525
+ const definedNonDefaultOptions = this.options.filter((option) => {
1526
+ const optionKey = option.attributeName();
1527
+ if (this.getOptionValue(optionKey) === undefined) {
1528
+ return false;
1591
1529
  }
1592
- const negativeNumberArg = (arg) => {
1593
- if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
1594
- return false;
1595
- return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
1596
- };
1597
- let activeVariadicOption = null;
1598
- let activeGroup = null;
1599
- let i = 0;
1600
- while (i < args.length || activeGroup) {
1601
- const arg = activeGroup ?? args[i++];
1602
- activeGroup = null;
1603
- if (arg === "--") {
1604
- if (dest === unknown)
1605
- dest.push(arg);
1606
- dest.push(...args.slice(i));
1607
- break;
1608
- }
1609
- if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1610
- this.emit(`option:${activeVariadicOption.name()}`, arg);
1611
- continue;
1612
- }
1613
- activeVariadicOption = null;
1614
- if (maybeOption(arg)) {
1615
- const option = this._findOption(arg);
1616
- if (option) {
1617
- if (option.required) {
1618
- const value = args[i++];
1619
- if (value === undefined)
1620
- this.optionMissingArgument(option);
1621
- this.emit(`option:${option.name()}`, value);
1622
- } else if (option.optional) {
1623
- let value = null;
1624
- if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
1625
- value = args[i++];
1626
- }
1627
- this.emit(`option:${option.name()}`, value);
1628
- } else {
1629
- this.emit(`option:${option.name()}`);
1630
- }
1631
- activeVariadicOption = option.variadic ? option : null;
1632
- continue;
1633
- }
1634
- }
1635
- if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
1636
- const option = this._findOption(`-${arg[1]}`);
1637
- if (option) {
1638
- if (option.required || option.optional && this._combineFlagAndOptionalValue) {
1639
- this.emit(`option:${option.name()}`, arg.slice(2));
1640
- } else {
1641
- this.emit(`option:${option.name()}`);
1642
- activeGroup = `-${arg.slice(2)}`;
1530
+ return this.getOptionValueSource(optionKey) !== "default";
1531
+ });
1532
+ const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
1533
+ optionsWithConflicting.forEach((option) => {
1534
+ const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
1535
+ if (conflictingAndDefined) {
1536
+ this._conflictingOption(option, conflictingAndDefined);
1537
+ }
1538
+ });
1539
+ }
1540
+ _checkForConflictingOptions() {
1541
+ this._getCommandAndAncestors().forEach((cmd) => {
1542
+ cmd._checkForConflictingLocalOptions();
1543
+ });
1544
+ }
1545
+ parseOptions(args) {
1546
+ const operands = [];
1547
+ const unknown = [];
1548
+ let dest = operands;
1549
+ function maybeOption(arg) {
1550
+ return arg.length > 1 && arg[0] === "-";
1551
+ }
1552
+ const negativeNumberArg = (arg) => {
1553
+ if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
1554
+ return false;
1555
+ return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
1556
+ };
1557
+ let activeVariadicOption = null;
1558
+ let activeGroup = null;
1559
+ let i = 0;
1560
+ while (i < args.length || activeGroup) {
1561
+ const arg = activeGroup ?? args[i++];
1562
+ activeGroup = null;
1563
+ if (arg === "--") {
1564
+ if (dest === unknown)
1565
+ dest.push(arg);
1566
+ dest.push(...args.slice(i));
1567
+ break;
1568
+ }
1569
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1570
+ this.emit(`option:${activeVariadicOption.name()}`, arg);
1571
+ continue;
1572
+ }
1573
+ activeVariadicOption = null;
1574
+ if (maybeOption(arg)) {
1575
+ const option = this._findOption(arg);
1576
+ if (option) {
1577
+ if (option.required) {
1578
+ const value = args[i++];
1579
+ if (value === undefined)
1580
+ this.optionMissingArgument(option);
1581
+ this.emit(`option:${option.name()}`, value);
1582
+ } else if (option.optional) {
1583
+ let value = null;
1584
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
1585
+ value = args[i++];
1643
1586
  }
1644
- continue;
1587
+ this.emit(`option:${option.name()}`, value);
1588
+ } else {
1589
+ this.emit(`option:${option.name()}`);
1645
1590
  }
1591
+ activeVariadicOption = option.variadic ? option : null;
1592
+ continue;
1646
1593
  }
1647
- if (/^--[^=]+=/.test(arg)) {
1648
- const index = arg.indexOf("=");
1649
- const option = this._findOption(arg.slice(0, index));
1650
- if (option && (option.required || option.optional)) {
1651
- this.emit(`option:${option.name()}`, arg.slice(index + 1));
1652
- continue;
1594
+ }
1595
+ if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
1596
+ const option = this._findOption(`-${arg[1]}`);
1597
+ if (option) {
1598
+ if (option.required || option.optional && this._combineFlagAndOptionalValue) {
1599
+ this.emit(`option:${option.name()}`, arg.slice(2));
1600
+ } else {
1601
+ this.emit(`option:${option.name()}`);
1602
+ activeGroup = `-${arg.slice(2)}`;
1653
1603
  }
1604
+ continue;
1654
1605
  }
1655
- if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
1656
- dest = unknown;
1657
- }
1658
- if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1659
- if (this._findCommand(arg)) {
1660
- operands.push(arg);
1661
- unknown.push(...args.slice(i));
1662
- break;
1663
- } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1664
- operands.push(arg, ...args.slice(i));
1665
- break;
1666
- } else if (this._defaultCommandName) {
1667
- unknown.push(arg, ...args.slice(i));
1668
- break;
1669
- }
1606
+ }
1607
+ if (/^--[^=]+=/.test(arg)) {
1608
+ const index = arg.indexOf("=");
1609
+ const option = this._findOption(arg.slice(0, index));
1610
+ if (option && (option.required || option.optional)) {
1611
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
1612
+ continue;
1670
1613
  }
1671
- if (this._passThroughOptions) {
1672
- dest.push(arg, ...args.slice(i));
1614
+ }
1615
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
1616
+ dest = unknown;
1617
+ }
1618
+ if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1619
+ if (this._findCommand(arg)) {
1620
+ operands.push(arg);
1621
+ unknown.push(...args.slice(i));
1622
+ break;
1623
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1624
+ operands.push(arg, ...args.slice(i));
1625
+ break;
1626
+ } else if (this._defaultCommandName) {
1627
+ unknown.push(arg, ...args.slice(i));
1673
1628
  break;
1674
1629
  }
1675
- dest.push(arg);
1676
1630
  }
1677
- return { operands, unknown };
1678
- }
1679
- opts() {
1680
- if (this._storeOptionsAsProperties) {
1681
- const result = {};
1682
- const len = this.options.length;
1683
- for (let i = 0;i < len; i++) {
1684
- const key = this.options[i].attributeName();
1685
- result[key] = key === this._versionOptionName ? this._version : this[key];
1686
- }
1687
- return result;
1631
+ if (this._passThroughOptions) {
1632
+ dest.push(arg, ...args.slice(i));
1633
+ break;
1688
1634
  }
1689
- return this._optionValues;
1635
+ dest.push(arg);
1690
1636
  }
1691
- optsWithGlobals() {
1692
- return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
1637
+ return { operands, unknown };
1638
+ }
1639
+ opts() {
1640
+ if (this._storeOptionsAsProperties) {
1641
+ const result = {};
1642
+ const len = this.options.length;
1643
+ for (let i = 0;i < len; i++) {
1644
+ const key = this.options[i].attributeName();
1645
+ result[key] = key === this._versionOptionName ? this._version : this[key];
1646
+ }
1647
+ return result;
1693
1648
  }
1694
- error(message, errorOptions) {
1695
- this._outputConfiguration.outputError(`${message}
1649
+ return this._optionValues;
1650
+ }
1651
+ optsWithGlobals() {
1652
+ return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
1653
+ }
1654
+ error(message, errorOptions) {
1655
+ this._outputConfiguration.outputError(`${message}
1696
1656
  `, this._outputConfiguration.writeErr);
1697
- if (typeof this._showHelpAfterError === "string") {
1698
- this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1657
+ if (typeof this._showHelpAfterError === "string") {
1658
+ this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1699
1659
  `);
1700
- } else if (this._showHelpAfterError) {
1701
- this._outputConfiguration.writeErr(`
1660
+ } else if (this._showHelpAfterError) {
1661
+ this._outputConfiguration.writeErr(`
1702
1662
  `);
1703
- this.outputHelp({ error: true });
1704
- }
1705
- const config = errorOptions || {};
1706
- const exitCode = config.exitCode || 1;
1707
- const code = config.code || "commander.error";
1708
- this._exit(exitCode, code, message);
1709
- }
1710
- _parseOptionsEnv() {
1711
- this.options.forEach((option) => {
1712
- if (option.envVar && option.envVar in process2.env) {
1713
- const optionKey = option.attributeName();
1714
- if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
1715
- if (option.required || option.optional) {
1716
- this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
1717
- } else {
1718
- this.emit(`optionEnv:${option.name()}`);
1719
- }
1720
- }
1721
- }
1722
- });
1723
- }
1724
- _parseOptionsImplied() {
1725
- const dualHelper = new DualOptions(this.options);
1726
- const hasCustomOptionValue = (optionKey) => {
1727
- return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
1728
- };
1729
- this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
1730
- Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
1731
- this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
1732
- });
1733
- });
1734
- }
1735
- missingArgument(name) {
1736
- const message = `error: missing required argument '${name}'`;
1737
- this.error(message, { code: "commander.missingArgument" });
1738
- }
1739
- optionMissingArgument(option) {
1740
- const message = `error: option '${option.flags}' argument missing`;
1741
- this.error(message, { code: "commander.optionMissingArgument" });
1663
+ this.outputHelp({ error: true });
1742
1664
  }
1743
- missingMandatoryOptionValue(option) {
1744
- const message = `error: required option '${option.flags}' not specified`;
1745
- this.error(message, { code: "commander.missingMandatoryOptionValue" });
1746
- }
1747
- _conflictingOption(option, conflictingOption) {
1748
- const findBestOptionFromValue = (option) => {
1665
+ const config = errorOptions || {};
1666
+ const exitCode = config.exitCode || 1;
1667
+ const code = config.code || "commander.error";
1668
+ this._exit(exitCode, code, message);
1669
+ }
1670
+ _parseOptionsEnv() {
1671
+ this.options.forEach((option) => {
1672
+ if (option.envVar && option.envVar in process2.env) {
1749
1673
  const optionKey = option.attributeName();
1750
- const optionValue = this.getOptionValue(optionKey);
1751
- const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
1752
- const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
1753
- if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
1754
- return negativeOption;
1755
- }
1756
- return positiveOption || option;
1757
- };
1758
- const getErrorMessage = (option) => {
1759
- const bestOption = findBestOptionFromValue(option);
1760
- const optionKey = bestOption.attributeName();
1761
- const source = this.getOptionValueSource(optionKey);
1762
- if (source === "env") {
1763
- return `environment variable '${bestOption.envVar}'`;
1674
+ if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
1675
+ if (option.required || option.optional) {
1676
+ this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
1677
+ } else {
1678
+ this.emit(`optionEnv:${option.name()}`);
1679
+ }
1764
1680
  }
1765
- return `option '${bestOption.flags}'`;
1766
- };
1767
- const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1768
- this.error(message, { code: "commander.conflictingOption" });
1769
- }
1770
- unknownOption(flag) {
1771
- if (this._allowUnknownOption)
1772
- return;
1773
- let suggestion = "";
1774
- if (flag.startsWith("--") && this._showSuggestionAfterError) {
1775
- let candidateFlags = [];
1776
- let command = this;
1777
- do {
1778
- const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
1779
- candidateFlags = candidateFlags.concat(moreFlags);
1780
- command = command.parent;
1781
- } while (command && !command._enablePositionalOptions);
1782
- suggestion = suggestSimilar(flag, candidateFlags);
1783
- }
1784
- const message = `error: unknown option '${flag}'${suggestion}`;
1785
- this.error(message, { code: "commander.unknownOption" });
1786
- }
1787
- _excessArguments(receivedArgs) {
1788
- if (this._allowExcessArguments)
1789
- return;
1790
- const expected = this.registeredArguments.length;
1791
- const s = expected === 1 ? "" : "s";
1792
- const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
1793
- const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
1794
- this.error(message, { code: "commander.excessArguments" });
1795
- }
1796
- unknownCommand() {
1797
- const unknownName = this.args[0];
1798
- let suggestion = "";
1799
- if (this._showSuggestionAfterError) {
1800
- const candidateNames = [];
1801
- this.createHelp().visibleCommands(this).forEach((command) => {
1802
- candidateNames.push(command.name());
1803
- if (command.alias())
1804
- candidateNames.push(command.alias());
1805
- });
1806
- suggestion = suggestSimilar(unknownName, candidateNames);
1807
1681
  }
1808
- const message = `error: unknown command '${unknownName}'${suggestion}`;
1809
- this.error(message, { code: "commander.unknownCommand" });
1810
- }
1811
- version(str, flags, description) {
1812
- if (str === undefined)
1813
- return this._version;
1814
- this._version = str;
1815
- flags = flags || "-V, --version";
1816
- description = description || "output the version number";
1817
- const versionOption = this.createOption(flags, description);
1818
- this._versionOptionName = versionOption.attributeName();
1819
- this._registerOption(versionOption);
1820
- this.on("option:" + versionOption.name(), () => {
1821
- this._outputConfiguration.writeOut(`${str}
1822
- `);
1823
- this._exit(0, "commander.version", str);
1682
+ });
1683
+ }
1684
+ _parseOptionsImplied() {
1685
+ const dualHelper = new DualOptions(this.options);
1686
+ const hasCustomOptionValue = (optionKey) => {
1687
+ return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
1688
+ };
1689
+ this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
1690
+ Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
1691
+ this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
1824
1692
  });
1825
- return this;
1826
- }
1827
- description(str, argsDescription) {
1828
- if (str === undefined && argsDescription === undefined)
1829
- return this._description;
1830
- this._description = str;
1831
- if (argsDescription) {
1832
- this._argsDescription = argsDescription;
1833
- }
1834
- return this;
1835
- }
1836
- summary(str) {
1837
- if (str === undefined)
1838
- return this._summary;
1839
- this._summary = str;
1840
- return this;
1841
- }
1842
- alias(alias) {
1843
- if (alias === undefined)
1844
- return this._aliases[0];
1693
+ });
1694
+ }
1695
+ missingArgument(name) {
1696
+ const message = `error: missing required argument '${name}'`;
1697
+ this.error(message, { code: "commander.missingArgument" });
1698
+ }
1699
+ optionMissingArgument(option) {
1700
+ const message = `error: option '${option.flags}' argument missing`;
1701
+ this.error(message, { code: "commander.optionMissingArgument" });
1702
+ }
1703
+ missingMandatoryOptionValue(option) {
1704
+ const message = `error: required option '${option.flags}' not specified`;
1705
+ this.error(message, { code: "commander.missingMandatoryOptionValue" });
1706
+ }
1707
+ _conflictingOption(option, conflictingOption) {
1708
+ const findBestOptionFromValue = (option) => {
1709
+ const optionKey = option.attributeName();
1710
+ const optionValue = this.getOptionValue(optionKey);
1711
+ const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
1712
+ const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
1713
+ if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
1714
+ return negativeOption;
1715
+ }
1716
+ return positiveOption || option;
1717
+ };
1718
+ const getErrorMessage = (option) => {
1719
+ const bestOption = findBestOptionFromValue(option);
1720
+ const optionKey = bestOption.attributeName();
1721
+ const source = this.getOptionValueSource(optionKey);
1722
+ if (source === "env") {
1723
+ return `environment variable '${bestOption.envVar}'`;
1724
+ }
1725
+ return `option '${bestOption.flags}'`;
1726
+ };
1727
+ const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
1728
+ this.error(message, { code: "commander.conflictingOption" });
1729
+ }
1730
+ unknownOption(flag) {
1731
+ if (this._allowUnknownOption)
1732
+ return;
1733
+ let suggestion = "";
1734
+ if (flag.startsWith("--") && this._showSuggestionAfterError) {
1735
+ let candidateFlags = [];
1845
1736
  let command = this;
1846
- if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1847
- command = this.commands[this.commands.length - 1];
1848
- }
1849
- if (alias === command._name)
1850
- throw new Error("Command alias can't be the same as its name");
1851
- const matchingCommand = this.parent?._findCommand(alias);
1852
- if (matchingCommand) {
1853
- const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
1854
- throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1855
- }
1856
- command._aliases.push(alias);
1857
- return this;
1858
- }
1859
- aliases(aliases) {
1860
- if (aliases === undefined)
1861
- return this._aliases;
1862
- aliases.forEach((alias) => this.alias(alias));
1863
- return this;
1864
- }
1865
- usage(str) {
1866
- if (str === undefined) {
1867
- if (this._usage)
1868
- return this._usage;
1869
- const args = this.registeredArguments.map((arg) => {
1870
- return humanReadableArgName(arg);
1871
- });
1872
- return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
1873
- }
1874
- this._usage = str;
1875
- return this;
1876
- }
1877
- name(str) {
1878
- if (str === undefined)
1879
- return this._name;
1880
- this._name = str;
1881
- return this;
1882
- }
1883
- helpGroup(heading) {
1884
- if (heading === undefined)
1885
- return this._helpGroupHeading ?? "";
1886
- this._helpGroupHeading = heading;
1887
- return this;
1888
- }
1889
- commandsGroup(heading) {
1890
- if (heading === undefined)
1891
- return this._defaultCommandGroup ?? "";
1892
- this._defaultCommandGroup = heading;
1893
- return this;
1894
- }
1895
- optionsGroup(heading) {
1896
- if (heading === undefined)
1897
- return this._defaultOptionGroup ?? "";
1898
- this._defaultOptionGroup = heading;
1899
- return this;
1900
- }
1901
- _initOptionGroup(option) {
1902
- if (this._defaultOptionGroup && !option.helpGroupHeading)
1903
- option.helpGroup(this._defaultOptionGroup);
1904
- }
1905
- _initCommandGroup(cmd) {
1906
- if (this._defaultCommandGroup && !cmd.helpGroup())
1907
- cmd.helpGroup(this._defaultCommandGroup);
1908
- }
1909
- nameFromFilename(filename) {
1910
- this._name = path.basename(filename, path.extname(filename));
1911
- return this;
1912
- }
1913
- executableDir(path) {
1914
- if (path === undefined)
1915
- return this._executableDir;
1916
- this._executableDir = path;
1917
- return this;
1737
+ do {
1738
+ const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
1739
+ candidateFlags = candidateFlags.concat(moreFlags);
1740
+ command = command.parent;
1741
+ } while (command && !command._enablePositionalOptions);
1742
+ suggestion = suggestSimilar(flag, candidateFlags);
1743
+ }
1744
+ const message = `error: unknown option '${flag}'${suggestion}`;
1745
+ this.error(message, { code: "commander.unknownOption" });
1746
+ }
1747
+ _excessArguments(receivedArgs) {
1748
+ if (this._allowExcessArguments)
1749
+ return;
1750
+ const expected = this.registeredArguments.length;
1751
+ const s = expected === 1 ? "" : "s";
1752
+ const received = receivedArgs.length;
1753
+ const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
1754
+ const details = receivedArgs.join(", ");
1755
+ const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${received}: ${details}.`;
1756
+ this.error(message, { code: "commander.excessArguments" });
1757
+ }
1758
+ unknownCommand() {
1759
+ const unknownName = this.args[0];
1760
+ let suggestion = "";
1761
+ if (this._showSuggestionAfterError) {
1762
+ const candidateNames = [];
1763
+ this.createHelp().visibleCommands(this).forEach((command) => {
1764
+ candidateNames.push(command.name());
1765
+ if (command.alias())
1766
+ candidateNames.push(command.alias());
1767
+ });
1768
+ suggestion = suggestSimilar(unknownName, candidateNames);
1918
1769
  }
1919
- helpInformation(contextOptions) {
1920
- const helper = this.createHelp();
1921
- const context = this._getOutputContext(contextOptions);
1922
- helper.prepareContext({
1923
- error: context.error,
1924
- helpWidth: context.helpWidth,
1925
- outputHasColors: context.hasColors
1770
+ const message = `error: unknown command '${unknownName}'${suggestion}`;
1771
+ this.error(message, { code: "commander.unknownCommand" });
1772
+ }
1773
+ version(str, flags, description) {
1774
+ if (str === undefined)
1775
+ return this._version;
1776
+ this._version = str;
1777
+ flags = flags || "-V, --version";
1778
+ description = description || "output the version number";
1779
+ const versionOption = this.createOption(flags, description);
1780
+ this._versionOptionName = versionOption.attributeName();
1781
+ this._registerOption(versionOption);
1782
+ this.on("option:" + versionOption.name(), () => {
1783
+ this._outputConfiguration.writeOut(`${str}
1784
+ `);
1785
+ this._exit(0, "commander.version", str);
1786
+ });
1787
+ return this;
1788
+ }
1789
+ description(str, argsDescription) {
1790
+ if (str === undefined && argsDescription === undefined)
1791
+ return this._description;
1792
+ this._description = str;
1793
+ if (argsDescription) {
1794
+ this._argsDescription = argsDescription;
1795
+ }
1796
+ return this;
1797
+ }
1798
+ summary(str) {
1799
+ if (str === undefined)
1800
+ return this._summary;
1801
+ this._summary = str;
1802
+ return this;
1803
+ }
1804
+ alias(alias) {
1805
+ if (alias === undefined)
1806
+ return this._aliases[0];
1807
+ let command = this;
1808
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1809
+ command = this.commands[this.commands.length - 1];
1810
+ }
1811
+ if (alias === command._name)
1812
+ throw new Error("Command alias can't be the same as its name");
1813
+ const matchingCommand = this.parent?._findCommand(alias);
1814
+ if (matchingCommand) {
1815
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
1816
+ throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
1817
+ }
1818
+ command._aliases.push(alias);
1819
+ return this;
1820
+ }
1821
+ aliases(aliases) {
1822
+ if (aliases === undefined)
1823
+ return this._aliases;
1824
+ aliases.forEach((alias) => this.alias(alias));
1825
+ return this;
1826
+ }
1827
+ usage(str) {
1828
+ if (str === undefined) {
1829
+ if (this._usage)
1830
+ return this._usage;
1831
+ const args = this.registeredArguments.map((arg) => {
1832
+ return humanReadableArgName(arg);
1926
1833
  });
1927
- const text = helper.formatHelp(this, helper);
1928
- if (context.hasColors)
1929
- return text;
1930
- return this._outputConfiguration.stripColor(text);
1931
- }
1932
- _getOutputContext(contextOptions) {
1933
- contextOptions = contextOptions || {};
1934
- const error = !!contextOptions.error;
1935
- let baseWrite;
1936
- let hasColors;
1937
- let helpWidth;
1938
- if (error) {
1939
- baseWrite = (str) => this._outputConfiguration.writeErr(str);
1940
- hasColors = this._outputConfiguration.getErrHasColors();
1941
- helpWidth = this._outputConfiguration.getErrHelpWidth();
1942
- } else {
1943
- baseWrite = (str) => this._outputConfiguration.writeOut(str);
1944
- hasColors = this._outputConfiguration.getOutHasColors();
1945
- helpWidth = this._outputConfiguration.getOutHelpWidth();
1946
- }
1947
- const write = (str) => {
1948
- if (!hasColors)
1949
- str = this._outputConfiguration.stripColor(str);
1950
- return baseWrite(str);
1951
- };
1952
- return { error, write, hasColors, helpWidth };
1834
+ return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
1953
1835
  }
1954
- outputHelp(contextOptions) {
1955
- let deprecatedCallback;
1956
- if (typeof contextOptions === "function") {
1957
- deprecatedCallback = contextOptions;
1958
- contextOptions = undefined;
1959
- }
1960
- const outputContext = this._getOutputContext(contextOptions);
1961
- const eventContext = {
1962
- error: outputContext.error,
1963
- write: outputContext.write,
1964
- command: this
1965
- };
1966
- this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
1967
- this.emit("beforeHelp", eventContext);
1968
- let helpInformation = this.helpInformation({ error: outputContext.error });
1969
- if (deprecatedCallback) {
1970
- helpInformation = deprecatedCallback(helpInformation);
1971
- if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1972
- throw new Error("outputHelp callback must return a string or a Buffer");
1973
- }
1974
- }
1975
- outputContext.write(helpInformation);
1976
- if (this._getHelpOption()?.long) {
1977
- this.emit(this._getHelpOption().long);
1978
- }
1979
- this.emit("afterHelp", eventContext);
1980
- this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
1981
- }
1982
- helpOption(flags, description) {
1983
- if (typeof flags === "boolean") {
1984
- if (flags) {
1985
- if (this._helpOption === null)
1986
- this._helpOption = undefined;
1987
- if (this._defaultOptionGroup) {
1988
- this._initOptionGroup(this._getHelpOption());
1989
- }
1990
- } else {
1991
- this._helpOption = null;
1836
+ this._usage = str;
1837
+ return this;
1838
+ }
1839
+ name(str) {
1840
+ if (str === undefined)
1841
+ return this._name;
1842
+ this._name = str;
1843
+ return this;
1844
+ }
1845
+ helpGroup(heading) {
1846
+ if (heading === undefined)
1847
+ return this._helpGroupHeading ?? "";
1848
+ this._helpGroupHeading = heading;
1849
+ return this;
1850
+ }
1851
+ commandsGroup(heading) {
1852
+ if (heading === undefined)
1853
+ return this._defaultCommandGroup ?? "";
1854
+ this._defaultCommandGroup = heading;
1855
+ return this;
1856
+ }
1857
+ optionsGroup(heading) {
1858
+ if (heading === undefined)
1859
+ return this._defaultOptionGroup ?? "";
1860
+ this._defaultOptionGroup = heading;
1861
+ return this;
1862
+ }
1863
+ _initOptionGroup(option) {
1864
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
1865
+ option.helpGroup(this._defaultOptionGroup);
1866
+ }
1867
+ _initCommandGroup(cmd) {
1868
+ if (this._defaultCommandGroup && !cmd.helpGroup())
1869
+ cmd.helpGroup(this._defaultCommandGroup);
1870
+ }
1871
+ nameFromFilename(filename) {
1872
+ this._name = path.basename(filename, path.extname(filename));
1873
+ return this;
1874
+ }
1875
+ executableDir(path2) {
1876
+ if (path2 === undefined)
1877
+ return this._executableDir;
1878
+ this._executableDir = path2;
1879
+ return this;
1880
+ }
1881
+ helpInformation(contextOptions) {
1882
+ const helper = this.createHelp();
1883
+ const context = this._getOutputContext(contextOptions);
1884
+ helper.prepareContext({
1885
+ error: context.error,
1886
+ helpWidth: context.helpWidth,
1887
+ outputHasColors: context.hasColors
1888
+ });
1889
+ const text = helper.formatHelp(this, helper);
1890
+ if (context.hasColors)
1891
+ return text;
1892
+ return this._outputConfiguration.stripColor(text);
1893
+ }
1894
+ _getOutputContext(contextOptions) {
1895
+ contextOptions = contextOptions || {};
1896
+ const error = !!contextOptions.error;
1897
+ let baseWrite;
1898
+ let hasColors;
1899
+ let helpWidth;
1900
+ if (error) {
1901
+ baseWrite = (str) => this._outputConfiguration.writeErr(str);
1902
+ hasColors = this._outputConfiguration.getErrHasColors();
1903
+ helpWidth = this._outputConfiguration.getErrHelpWidth();
1904
+ } else {
1905
+ baseWrite = (str) => this._outputConfiguration.writeOut(str);
1906
+ hasColors = this._outputConfiguration.getOutHasColors();
1907
+ helpWidth = this._outputConfiguration.getOutHelpWidth();
1908
+ }
1909
+ const write = (str) => {
1910
+ if (!hasColors)
1911
+ str = this._outputConfiguration.stripColor(str);
1912
+ return baseWrite(str);
1913
+ };
1914
+ return { error, write, hasColors, helpWidth };
1915
+ }
1916
+ outputHelp(contextOptions) {
1917
+ let deprecatedCallback;
1918
+ if (typeof contextOptions === "function") {
1919
+ deprecatedCallback = contextOptions;
1920
+ contextOptions = undefined;
1921
+ }
1922
+ const outputContext = this._getOutputContext(contextOptions);
1923
+ const eventContext = {
1924
+ error: outputContext.error,
1925
+ write: outputContext.write,
1926
+ command: this
1927
+ };
1928
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
1929
+ this.emit("beforeHelp", eventContext);
1930
+ let helpInformation = this.helpInformation({ error: outputContext.error });
1931
+ if (deprecatedCallback) {
1932
+ helpInformation = deprecatedCallback(helpInformation);
1933
+ if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1934
+ throw new Error("outputHelp callback must return a string or a Buffer");
1935
+ }
1936
+ }
1937
+ outputContext.write(helpInformation);
1938
+ if (this._getHelpOption()?.long) {
1939
+ this.emit(this._getHelpOption().long);
1940
+ }
1941
+ this.emit("afterHelp", eventContext);
1942
+ this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
1943
+ }
1944
+ helpOption(flags, description) {
1945
+ if (typeof flags === "boolean") {
1946
+ if (flags) {
1947
+ if (this._helpOption === null)
1948
+ this._helpOption = undefined;
1949
+ if (this._defaultOptionGroup) {
1950
+ this._initOptionGroup(this._getHelpOption());
1992
1951
  }
1993
- return this;
1952
+ } else {
1953
+ this._helpOption = null;
1994
1954
  }
1995
- this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
1996
- if (flags || description)
1997
- this._initOptionGroup(this._helpOption);
1998
1955
  return this;
1999
1956
  }
2000
- _getHelpOption() {
2001
- if (this._helpOption === undefined) {
2002
- this.helpOption(undefined, undefined);
2003
- }
2004
- return this._helpOption;
2005
- }
2006
- addHelpOption(option) {
2007
- this._helpOption = option;
2008
- this._initOptionGroup(option);
2009
- return this;
1957
+ this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
1958
+ if (flags || description)
1959
+ this._initOptionGroup(this._helpOption);
1960
+ return this;
1961
+ }
1962
+ _getHelpOption() {
1963
+ if (this._helpOption === undefined) {
1964
+ this.helpOption(undefined, undefined);
2010
1965
  }
2011
- help(contextOptions) {
2012
- this.outputHelp(contextOptions);
2013
- let exitCode2 = Number(process2.exitCode ?? 0);
2014
- if (exitCode2 === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
2015
- exitCode2 = 1;
2016
- }
2017
- this._exit(exitCode2, "commander.help", "(outputHelp)");
1966
+ return this._helpOption;
1967
+ }
1968
+ addHelpOption(option) {
1969
+ this._helpOption = option;
1970
+ this._initOptionGroup(option);
1971
+ return this;
1972
+ }
1973
+ help(contextOptions) {
1974
+ this.outputHelp(contextOptions);
1975
+ let exitCode = Number(process2.exitCode ?? 0);
1976
+ if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
1977
+ exitCode = 1;
2018
1978
  }
2019
- addHelpText(position, text) {
2020
- const allowedValues = ["beforeAll", "before", "after", "afterAll"];
2021
- if (!allowedValues.includes(position)) {
2022
- throw new Error(`Unexpected value for position to addHelpText.
1979
+ this._exit(exitCode, "commander.help", "(outputHelp)");
1980
+ }
1981
+ addHelpText(position, text) {
1982
+ const allowedValues = ["beforeAll", "before", "after", "afterAll"];
1983
+ if (!allowedValues.includes(position)) {
1984
+ throw new Error(`Unexpected value for position to addHelpText.
2023
1985
  Expecting one of '${allowedValues.join("', '")}'`);
1986
+ }
1987
+ const helpEvent = `${position}Help`;
1988
+ this.on(helpEvent, (context) => {
1989
+ let helpStr;
1990
+ if (typeof text === "function") {
1991
+ helpStr = text({ error: context.error, command: context.command });
1992
+ } else {
1993
+ helpStr = text;
2024
1994
  }
2025
- const helpEvent = `${position}Help`;
2026
- this.on(helpEvent, (context) => {
2027
- let helpStr;
2028
- if (typeof text === "function") {
2029
- helpStr = text({ error: context.error, command: context.command });
2030
- } else {
2031
- helpStr = text;
2032
- }
2033
- if (helpStr) {
2034
- context.write(`${helpStr}
1995
+ if (helpStr) {
1996
+ context.write(`${helpStr}
2035
1997
  `);
2036
- }
2037
- });
2038
- return this;
2039
- }
2040
- _outputHelpIfRequested(args) {
2041
- const helpOption = this._getHelpOption();
2042
- const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
2043
- if (helpRequested) {
2044
- this.outputHelp();
2045
- this._exit(0, "commander.helpDisplayed", "(outputHelp)");
2046
1998
  }
1999
+ });
2000
+ return this;
2001
+ }
2002
+ _outputHelpIfRequested(args) {
2003
+ const helpOption = this._getHelpOption();
2004
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
2005
+ if (helpRequested) {
2006
+ this.outputHelp();
2007
+ this._exit(0, "commander.helpDisplayed", "(outputHelp)");
2047
2008
  }
2048
2009
  }
2049
- function incrementNodeInspectorPort(args) {
2050
- return args.map((arg) => {
2051
- if (!arg.startsWith("--inspect")) {
2052
- return arg;
2053
- }
2054
- let debugOption;
2055
- let debugHost = "127.0.0.1";
2056
- let debugPort = "9229";
2057
- let match;
2058
- if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2059
- debugOption = match[1];
2060
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2061
- debugOption = match[1];
2062
- if (/^\d+$/.test(match[3])) {
2063
- debugPort = match[3];
2064
- } else {
2065
- debugHost = match[3];
2066
- }
2067
- } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2068
- debugOption = match[1];
2010
+ }
2011
+ function incrementNodeInspectorPort(args) {
2012
+ return args.map((arg) => {
2013
+ if (!arg.startsWith("--inspect")) {
2014
+ return arg;
2015
+ }
2016
+ let debugOption;
2017
+ let debugHost = "127.0.0.1";
2018
+ let debugPort = "9229";
2019
+ let match;
2020
+ if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
2021
+ debugOption = match[1];
2022
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
2023
+ debugOption = match[1];
2024
+ if (/^\d+$/.test(match[3])) {
2025
+ debugPort = match[3];
2026
+ } else {
2069
2027
  debugHost = match[3];
2070
- debugPort = match[4];
2071
2028
  }
2072
- if (debugOption && debugPort !== "0") {
2073
- return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2074
- }
2075
- return arg;
2076
- });
2077
- }
2078
- function useColor() {
2079
- if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
2080
- return false;
2081
- if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
2082
- return true;
2083
- return;
2084
- }
2085
- exports.Command = Command;
2086
- exports.useColor = useColor;
2087
- });
2088
-
2089
- // pkgs/create-akan-workspace/run.ts
2090
- import { spawn } from "child_process";
2091
-
2092
- // node_modules/.bun/commander@14.0.3/node_modules/commander/index.js
2093
- var exports_commander = {};
2094
- __exportCjs(exports_commander, {
2095
- program: () => $program,
2096
- createCommand: () => $createCommand,
2097
- createOption: () => $createOption,
2098
- createArgument: () => $createArgument,
2099
- Command: () => $Command,
2100
- Option: () => $Option,
2101
- Argument: () => $Argument,
2102
- Help: () => $Help,
2103
- CommanderError: () => $CommanderError,
2104
- InvalidArgumentError: () => $InvalidArgumentError,
2105
- InvalidOptionArgumentError: () => $InvalidOptionArgumentError
2106
- }, {
2107
- program: (value) => $program = value,
2108
- createCommand: (value) => $createCommand = value,
2109
- createOption: (value) => $createOption = value,
2110
- createArgument: (value) => $createArgument = value,
2111
- Command: (value) => $Command = value,
2112
- Option: (value) => $Option = value,
2113
- Argument: (value) => $Argument = value,
2114
- Help: (value) => $Help = value,
2115
- CommanderError: (value) => $CommanderError = value,
2116
- InvalidArgumentError: (value) => $InvalidArgumentError = value,
2117
- InvalidOptionArgumentError: (value) => $InvalidOptionArgumentError = value
2118
- });
2119
- var { Argument } = require_argument();
2120
- var { Command } = require_command();
2121
- var { CommanderError, InvalidArgumentError } = require_error();
2122
- var { Help } = require_help();
2123
- var { Option } = require_option();
2124
- var $program = new Command;
2125
- var $createCommand = (name) => new Command(name);
2126
- var $createOption = (flags, description) => new Option(flags, description);
2127
- var $createArgument = (name, description) => new Argument(name, description);
2128
- var $Command = Command;
2129
- var $Option = Option;
2130
- var $Argument = Argument;
2131
- var $Help = Help;
2132
- var $CommanderError = CommanderError;
2133
- var $InvalidArgumentError = InvalidArgumentError;
2134
- var $InvalidOptionArgumentError = InvalidArgumentError;
2029
+ } else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
2030
+ debugOption = match[1];
2031
+ debugHost = match[3];
2032
+ debugPort = match[4];
2033
+ }
2034
+ if (debugOption && debugPort !== "0") {
2035
+ return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
2036
+ }
2037
+ return arg;
2038
+ });
2039
+ }
2040
+ function useColor() {
2041
+ if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
2042
+ return false;
2043
+ if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
2044
+ return true;
2045
+ return;
2046
+ }
2135
2047
 
2136
- // node_modules/.bun/commander@14.0.3/node_modules/commander/esm.mjs
2137
- var {
2138
- program,
2139
- createCommand,
2140
- createArgument,
2141
- createOption,
2142
- CommanderError: CommanderError2,
2143
- InvalidArgumentError: InvalidArgumentError2,
2144
- InvalidOptionArgumentError,
2145
- Command: Command2,
2146
- Argument: Argument2,
2147
- Option: Option2,
2148
- Help: Help2
2149
- } = exports_commander;
2048
+ // node_modules/.bun/commander@15.0.0/node_modules/commander/index.js
2049
+ var program = new Command;
2150
2050
 
2151
2051
  // pkgs/create-akan-workspace/run.ts
2152
2052
  var spawnProcess = (spawnCommand, command, args, options = {}) => {
2153
2053
  const proc = spawnCommand(command, args, { cwd: process.cwd(), stdio: "inherit", ...options });
2154
2054
  return new Promise((resolve, reject) => {
2155
2055
  proc.on("exit", (code, signal) => {
2156
- if (!!code || signal)
2056
+ if (code || signal)
2157
2057
  reject({ code, signal });
2158
2058
  else
2159
2059
  resolve({ code, signal });
@@ -2171,7 +2071,7 @@ var run = async ({
2171
2071
  argv = process.argv,
2172
2072
  spawnCommand = spawn
2173
2073
  } = {}) => {
2174
- const program = new Command2().name("create-akan-workspace");
2074
+ const program = new Command().name("create-akan-workspace");
2175
2075
  program.argument("[org]", "organization name").option("-a, --app <string>", "application name").option("-d, --dir <string>", "directory").option("-l, --libs <boolean>", "install shared and util libraries", false).option("-i, --init <boolean>", "install dependencies and initialize git", true).option("-r, --registry <string>", "npm registry URL for installing Akan packages").option("-o, --owner <string>", "owner of the workspace").action(async (org, options) => {
2176
2076
  const packageVersion = await getPackageVersion();
2177
2077
  const registry = options.registry ?? process.env.AKAN_NPM_REGISTRY;