@bemoje/cli 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +1516 -59
- package/lib/index.d.cts +2658 -6
- package/lib/index.d.ts +2658 -6
- package/lib/index.js +1504 -8
- package/package.json +53 -85
- package/lib/lib/Command.cjs +0 -450
- package/lib/lib/Command.d.cts +0 -1
- package/lib/lib/Command.d.ts +0 -1
- package/lib/lib/Command.js +0 -443
- package/lib/lib/Help.cjs +0 -552
- package/lib/lib/Help.d.cts +0 -1
- package/lib/lib/Help.d.ts +0 -1
- package/lib/lib/Help.js +0 -545
- package/lib/lib/helpers/findCommand.cjs +0 -14
- package/lib/lib/helpers/findCommand.d.cts +0 -8
- package/lib/lib/helpers/findCommand.d.ts +0 -8
- package/lib/lib/helpers/findCommand.js +0 -11
- package/lib/lib/helpers/findOption.cjs +0 -16
- package/lib/lib/helpers/findOption.d.cts +0 -8
- package/lib/lib/helpers/findOption.d.ts +0 -8
- package/lib/lib/helpers/findOption.js +0 -14
- package/lib/lib/helpers/getCommandAncestors.cjs +0 -12
- package/lib/lib/helpers/getCommandAncestors.d.cts +0 -8
- package/lib/lib/helpers/getCommandAncestors.d.ts +0 -8
- package/lib/lib/helpers/getCommandAncestors.js +0 -9
- package/lib/lib/helpers/getCommandAndAncestors.cjs +0 -15
- package/lib/lib/helpers/getCommandAndAncestors.d.cts +0 -8
- package/lib/lib/helpers/getCommandAndAncestors.d.ts +0 -8
- package/lib/lib/helpers/getCommandAndAncestors.js +0 -13
- package/lib/lib/helpers/parseOptionFlags.cjs +0 -28
- package/lib/lib/helpers/parseOptionFlags.d.cts +0 -13
- package/lib/lib/helpers/parseOptionFlags.d.ts +0 -13
- package/lib/lib/helpers/parseOptionFlags.js +0 -26
- package/lib/lib/types.cjs +0 -2
- package/lib/lib/types.d.cts +0 -1
- package/lib/lib/types.d.ts +0 -1
- package/lib/lib/types.js +0 -1
package/lib/lib/Command.js
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
-
import { Help } from './Help';
|
|
3
|
-
import { collectVariadicOptionValues } from './internal/collectVariadicOptionValues';
|
|
4
|
-
import colors from 'ansi-colors';
|
|
5
|
-
import { valuesOf, objSortKeys, filterObject } from '@mono/object';
|
|
6
|
-
import { findCommand } from './helpers/findCommand';
|
|
7
|
-
import { findOption } from './helpers/findOption';
|
|
8
|
-
import { getCommandAncestors } from './helpers/getCommandAncestors';
|
|
9
|
-
import { getCommandAndAncestors } from './helpers/getCommandAndAncestors';
|
|
10
|
-
import { inspect, parseArgs } from 'util';
|
|
11
|
-
import { kebabCase, upperFirst } from 'es-toolkit/string';
|
|
12
|
-
import { lazyProp } from '@mono/decorators';
|
|
13
|
-
import { mergeOptionDefaults } from './internal/mergeOptionDefaults';
|
|
14
|
-
import { normalizeArgv } from './internal/normalizeArgv';
|
|
15
|
-
import { parseOptionFlags } from './helpers/parseOptionFlags';
|
|
16
|
-
import { resolveArguments } from './internal/resolveArguments';
|
|
17
|
-
import { setName } from '@mono/fn';
|
|
18
|
-
import { timer } from '@mono/node';
|
|
19
|
-
import { uniq } from 'es-toolkit/array';
|
|
20
|
-
import { validateParsed } from './internal/validateParsed';
|
|
21
|
-
|
|
22
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
23
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
-
}
|
|
28
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
29
|
-
function _ts_metadata(k, v) {
|
|
30
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
31
|
-
}
|
|
32
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
33
|
-
class Command {
|
|
34
|
-
static {
|
|
35
|
-
__name(this, "Command");
|
|
36
|
-
}
|
|
37
|
-
/** parent command in the hierarchy, undefined for root command */
|
|
38
|
-
parent;
|
|
39
|
-
/** the command name used to invoke it */
|
|
40
|
-
name;
|
|
41
|
-
/** semantic version string displayed by --version flag */
|
|
42
|
-
version;
|
|
43
|
-
/** alternative names for invoking this command */
|
|
44
|
-
aliases;
|
|
45
|
-
/** brief one-line description shown in command lists */
|
|
46
|
-
summary;
|
|
47
|
-
/** full description displayed in help text */
|
|
48
|
-
description;
|
|
49
|
-
/** whether to exclude from help listings */
|
|
50
|
-
hidden;
|
|
51
|
-
/** category for organizing related commands in help output */
|
|
52
|
-
group;
|
|
53
|
-
/** positional arguments this command accepts */
|
|
54
|
-
arguments;
|
|
55
|
-
/** cLI options (flags) this command recognizes */
|
|
56
|
-
options;
|
|
57
|
-
/** subcommands registered with this command */
|
|
58
|
-
commands;
|
|
59
|
-
/** main action handler executed when command is invoked */
|
|
60
|
-
action;
|
|
61
|
-
/** option-driven actions (e.g., --help, --version) executed when their conditions match */
|
|
62
|
-
hooks;
|
|
63
|
-
constructor(name, parent) {
|
|
64
|
-
this.name = name;
|
|
65
|
-
this.aliases = [];
|
|
66
|
-
this.description = "";
|
|
67
|
-
this.arguments = [];
|
|
68
|
-
this.options = [];
|
|
69
|
-
this.commands = {};
|
|
70
|
-
this.hooks = [];
|
|
71
|
-
Object.defineProperty(this, "parent", {
|
|
72
|
-
value: parent,
|
|
73
|
-
enumerable: false
|
|
74
|
-
});
|
|
75
|
-
if (!parent) {
|
|
76
|
-
this.addOption("-D, --debug", {
|
|
77
|
-
description: "Display debug information"
|
|
78
|
-
}).addOptionHook("debug", ({ cmd, ...data }) => {
|
|
79
|
-
console.debug(inspect(cmd, {
|
|
80
|
-
depth: 1,
|
|
81
|
-
colors: true
|
|
82
|
-
}));
|
|
83
|
-
console.debug(inspect(data, {
|
|
84
|
-
depth: 3,
|
|
85
|
-
colors: true
|
|
86
|
-
}));
|
|
87
|
-
});
|
|
88
|
-
this.addOption("-h, --help", {
|
|
89
|
-
description: "Display help information"
|
|
90
|
-
}).addOptionHook("help", ({ cmd }) => {
|
|
91
|
-
console.log(cmd.renderHelp());
|
|
92
|
-
process.exitCode = 0;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
get help() {
|
|
97
|
-
return new Help(this);
|
|
98
|
-
}
|
|
99
|
-
/** configure how the help is rendered */
|
|
100
|
-
helpConfiguration(cb) {
|
|
101
|
-
const help = this.help;
|
|
102
|
-
cb?.(help);
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
/** renders formatted help text using provided help definition */
|
|
106
|
-
renderHelp(config = {}) {
|
|
107
|
-
const result = this.help.render();
|
|
108
|
-
return config.noColor ? colors.stripColor(result) : result;
|
|
109
|
-
}
|
|
110
|
-
/** sets the command name */
|
|
111
|
-
setName(name) {
|
|
112
|
-
this.name = name;
|
|
113
|
-
}
|
|
114
|
-
/** sets command aliases, flattening nested arrays */
|
|
115
|
-
setAliases(...aliases) {
|
|
116
|
-
this.aliases = [];
|
|
117
|
-
this.addAliases(...aliases);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
/** adds aliases to existing ones */
|
|
121
|
-
addAliases(...aliases) {
|
|
122
|
-
const taken = this.parent ? valuesOf(this.parent.commands).flatMap((c) => {
|
|
123
|
-
return [
|
|
124
|
-
c.name,
|
|
125
|
-
...c.aliases
|
|
126
|
-
];
|
|
127
|
-
}) : [];
|
|
128
|
-
uniq(aliases.flat()).filter((a) => {
|
|
129
|
-
return !this.aliases.includes(a) && a !== this.name;
|
|
130
|
-
}).forEach((a) => {
|
|
131
|
-
if (taken.includes(a)) {
|
|
132
|
-
throw new Error(`Alias "${a}" is already used by a sibling command: ${findCommand(this.parent, a)?.name}`);
|
|
133
|
-
}
|
|
134
|
-
this.aliases.push(a);
|
|
135
|
-
});
|
|
136
|
-
this.aliases.sort((a, b) => {
|
|
137
|
-
return a.length - b.length;
|
|
138
|
-
});
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
/** sets the command version */
|
|
142
|
-
setVersion(version) {
|
|
143
|
-
this.version = version;
|
|
144
|
-
if (findOption(this, "version")) {
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
return this.addOption("-V, --version", {
|
|
148
|
-
description: "Display semver version"
|
|
149
|
-
}).addOptionHook("version", ({ cmd }) => {
|
|
150
|
-
console.log(getCommandAndAncestors(cmd).find((c) => {
|
|
151
|
-
return c.version;
|
|
152
|
-
})?.version);
|
|
153
|
-
process.exitCode = 0;
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/** sets the command summary */
|
|
157
|
-
setSummary(summary) {
|
|
158
|
-
this.summary = summary;
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/** sets command description, joining variadic lines */
|
|
162
|
-
setDescription(...lines) {
|
|
163
|
-
this.description = lines.join("\n");
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
/** sets whether command is hidden from help */
|
|
167
|
-
setHidden(hidden = true) {
|
|
168
|
-
this.hidden = hidden;
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
/** sets the command group for help organization */
|
|
172
|
-
setGroup(group) {
|
|
173
|
-
this.group = group;
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
-
command(name, cb) {
|
|
179
|
-
if (this.arguments.length) {
|
|
180
|
-
throw new Error(`Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined.`);
|
|
181
|
-
}
|
|
182
|
-
const sub = this.createSubcommand(name);
|
|
183
|
-
const inherit = this.options;
|
|
184
|
-
sub.options.push(...inherit);
|
|
185
|
-
const inheritHooks = this.hooks.filter((t) => {
|
|
186
|
-
return inherit.some((i) => {
|
|
187
|
-
return i.name === t.name;
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
sub.hooks.push(...inheritHooks);
|
|
191
|
-
const taken = valuesOf(this.commands).flatMap((c) => {
|
|
192
|
-
return [
|
|
193
|
-
c.name,
|
|
194
|
-
...c.aliases
|
|
195
|
-
];
|
|
196
|
-
});
|
|
197
|
-
if (taken.includes(name)) {
|
|
198
|
-
throw new Error(`Command name "${getCommandAndAncestors(sub).map((c) => {
|
|
199
|
-
return c.name;
|
|
200
|
-
})}" is already used by this command or its aliases: ${taken.join(", ")}`);
|
|
201
|
-
}
|
|
202
|
-
const kebab = kebabCase(name);
|
|
203
|
-
const words = kebab.split("-");
|
|
204
|
-
const initials = words.map((s) => {
|
|
205
|
-
return s[0];
|
|
206
|
-
}).join("");
|
|
207
|
-
if (taken.includes(initials)) {
|
|
208
|
-
const initials2 = words.map((s) => {
|
|
209
|
-
return s[0] + s[1];
|
|
210
|
-
}).join("");
|
|
211
|
-
if (!taken.includes(initials2)) {
|
|
212
|
-
sub.addAliases(initials2);
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
sub.addAliases(initials);
|
|
216
|
-
}
|
|
217
|
-
this.commands[name] = sub;
|
|
218
|
-
return cb ? cb(sub, this) : sub;
|
|
219
|
-
}
|
|
220
|
-
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
221
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
-
addCommand(name, cb) {
|
|
223
|
-
this.command(name, cb);
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
// implementation
|
|
227
|
-
addArgument(usage, options = {}) {
|
|
228
|
-
if (!/^<(.*?)>$|^\[(.*?)]$/.test(usage)) {
|
|
229
|
-
throw new Error(`Invalid argument format: ${usage}`);
|
|
230
|
-
}
|
|
231
|
-
const name = usage.slice(1, -1).replace(/\.{3}$/, "");
|
|
232
|
-
const required = usage.startsWith("<");
|
|
233
|
-
const variadic = usage.slice(0, -1).endsWith("...");
|
|
234
|
-
const prevArg = this.arguments[this.arguments.length - 1];
|
|
235
|
-
if (prevArg?.variadic) {
|
|
236
|
-
throw new Error(`Cannot add argument ${usage} after variadic argument ${prevArg.usage}`);
|
|
237
|
-
}
|
|
238
|
-
if (required && prevArg && !prevArg?.required) {
|
|
239
|
-
throw new Error(`Cannot add required argument ${usage} after optional argument ${prevArg?.usage}`);
|
|
240
|
-
}
|
|
241
|
-
if (required && prevArg?.defaultValue) {
|
|
242
|
-
throw new Error(`Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}`);
|
|
243
|
-
}
|
|
244
|
-
const arg = {
|
|
245
|
-
usage,
|
|
246
|
-
name,
|
|
247
|
-
required,
|
|
248
|
-
variadic,
|
|
249
|
-
...options
|
|
250
|
-
};
|
|
251
|
-
if (variadic && !arg.defaultValue) {
|
|
252
|
-
arg.defaultValue = [];
|
|
253
|
-
}
|
|
254
|
-
this.arguments.push(arg);
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* adds command-line option with type inference. Parses format: `-s, --long [<value>|[value]|<value...>|[value...]]`
|
|
259
|
-
*/
|
|
260
|
-
addOption(flags, opts = {}) {
|
|
261
|
-
const ins = {};
|
|
262
|
-
const { short, long, name, argName } = parseOptionFlags(flags);
|
|
263
|
-
for (const opt of this.options) {
|
|
264
|
-
if (opt.long === long) {
|
|
265
|
-
throw new Error(`Option long name, --${long} already in use by: ${opt.flags}`);
|
|
266
|
-
}
|
|
267
|
-
if (opt.short === short) {
|
|
268
|
-
throw new Error(`Option short name, -${short} already in use by: ${opt.flags}`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
ins.flags = flags;
|
|
272
|
-
ins.short = short;
|
|
273
|
-
ins.long = long;
|
|
274
|
-
ins.name = name;
|
|
275
|
-
ins.description = "";
|
|
276
|
-
if (argName) {
|
|
277
|
-
ins.type = "string";
|
|
278
|
-
ins.argName = argName;
|
|
279
|
-
if (flags.endsWith(">")) {
|
|
280
|
-
if (flags.endsWith("...>")) {
|
|
281
|
-
ins.required = true;
|
|
282
|
-
ins.variadic = true;
|
|
283
|
-
} else {
|
|
284
|
-
ins.required = true;
|
|
285
|
-
}
|
|
286
|
-
} else if (flags.endsWith("]") && flags.endsWith("...]")) {
|
|
287
|
-
ins.variadic = true;
|
|
288
|
-
ins.defaultValue = opts.defaultValue ?? [];
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
ins.type = "boolean";
|
|
292
|
-
}
|
|
293
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
294
|
-
if (value !== void 0) {
|
|
295
|
-
Reflect.set(ins, key, value);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] === "string") {
|
|
299
|
-
ins.required = false;
|
|
300
|
-
ins.flags = ins.flags.replace("<", "[").replace(">", "]");
|
|
301
|
-
if (ins.type === "boolean") {
|
|
302
|
-
ins.defaultValue = /^(t(rue)?|y(es)?|1)$/i.test(process.env[ins.env]);
|
|
303
|
-
} else if (ins.variadic) {
|
|
304
|
-
ins.defaultValue = process.env[ins.env].replace(/\[]/, "").split(",").map((v) => {
|
|
305
|
-
return v.trim();
|
|
306
|
-
});
|
|
307
|
-
} else {
|
|
308
|
-
ins.defaultValue = process.env[ins.env];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
this.options.push(ins);
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* register an action to be invoked when an option is set to true or string value.
|
|
316
|
-
*
|
|
317
|
-
* Hooks execute in addition to or instead of the main action handler,
|
|
318
|
-
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
319
|
-
* are implemented as hooks.
|
|
320
|
-
*/
|
|
321
|
-
addOptionHook(optionName, action) {
|
|
322
|
-
const def = findOption(this, optionName);
|
|
323
|
-
if (!def.group && /process\.exitCode ?= ?.+;?\s*}$/.test(action.toString())) {
|
|
324
|
-
def.group = "Command Options";
|
|
325
|
-
}
|
|
326
|
-
this.hooks.push({
|
|
327
|
-
name: optionName,
|
|
328
|
-
predicate: setName(`has${upperFirst(optionName)}`, ({ opts }) => {
|
|
329
|
-
return opts[optionName] !== void 0 && opts[optionName] !== false && !(Array.isArray(opts[optionName]) && opts[optionName].length === 0);
|
|
330
|
-
}),
|
|
331
|
-
action: setName(optionName, action)
|
|
332
|
-
});
|
|
333
|
-
return this;
|
|
334
|
-
}
|
|
335
|
-
/** parses command-line arguments with subcommand support and type-safe validation. */
|
|
336
|
-
parseArgv(argv = process.argv.slice(2)) {
|
|
337
|
-
const sub = findCommand(this, argv[0]);
|
|
338
|
-
if (sub) {
|
|
339
|
-
return sub.parseArgv(argv.slice(1));
|
|
340
|
-
}
|
|
341
|
-
argv = normalizeArgv(argv, this.options);
|
|
342
|
-
const parsed = parseArgs({
|
|
343
|
-
args: argv,
|
|
344
|
-
options: Object.fromEntries(this.options.map((o) => {
|
|
345
|
-
return [
|
|
346
|
-
o.name,
|
|
347
|
-
{
|
|
348
|
-
type: o.type,
|
|
349
|
-
short: o.short,
|
|
350
|
-
default: o.defaultValue,
|
|
351
|
-
multiple: !!o.variadic
|
|
352
|
-
}
|
|
353
|
-
];
|
|
354
|
-
})),
|
|
355
|
-
allowPositionals: true,
|
|
356
|
-
tokens: true,
|
|
357
|
-
strict: false,
|
|
358
|
-
allowNegative: true
|
|
359
|
-
});
|
|
360
|
-
collectVariadicOptionValues(parsed, this.options);
|
|
361
|
-
mergeOptionDefaults(parsed.values, this.options);
|
|
362
|
-
parsed.values = objSortKeys(parsed.values, (a, b) => {
|
|
363
|
-
return a[1] === false ? 1 : b[1] === false ? -1 : a[1] === true ? 1 : b[1] === true ? -1 : 0;
|
|
364
|
-
});
|
|
365
|
-
const args = resolveArguments(parsed.positionals, this.arguments);
|
|
366
|
-
const opts = filterObject(parsed.values, (value) => {
|
|
367
|
-
return value !== void 0;
|
|
368
|
-
});
|
|
369
|
-
const errors = validateParsed(args, parsed.values, this.arguments, this.options);
|
|
370
|
-
const path = getCommandAncestors(this).map((c) => {
|
|
371
|
-
return c.name;
|
|
372
|
-
});
|
|
373
|
-
const data = {
|
|
374
|
-
path,
|
|
375
|
-
name: this.name,
|
|
376
|
-
argv,
|
|
377
|
-
args,
|
|
378
|
-
opts,
|
|
379
|
-
errors,
|
|
380
|
-
cmd: this
|
|
381
|
-
};
|
|
382
|
-
const hooks = this.hooks.filter((t) => {
|
|
383
|
-
return t.predicate(data);
|
|
384
|
-
});
|
|
385
|
-
const execute = /* @__PURE__ */ __name(async () => {
|
|
386
|
-
for (const hook of hooks) {
|
|
387
|
-
await hook.action(data);
|
|
388
|
-
if (process.exitCode !== void 0) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
await timer([
|
|
393
|
-
[
|
|
394
|
-
...path,
|
|
395
|
-
this.name
|
|
396
|
-
].join(" "),
|
|
397
|
-
this.description
|
|
398
|
-
], async (logger) => {
|
|
399
|
-
if (errors) {
|
|
400
|
-
errors.forEach((msg) => {
|
|
401
|
-
return logger.error(colors.red(msg));
|
|
402
|
-
});
|
|
403
|
-
process.exitCode = 1;
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
if (this.action) {
|
|
407
|
-
return await this.action(...args, opts, {
|
|
408
|
-
...data,
|
|
409
|
-
args,
|
|
410
|
-
opts,
|
|
411
|
-
cmd: this,
|
|
412
|
-
logger
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
console.log(this.renderHelp());
|
|
416
|
-
});
|
|
417
|
-
}, "execute");
|
|
418
|
-
return {
|
|
419
|
-
...data,
|
|
420
|
-
hooks,
|
|
421
|
-
execute
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
426
|
-
* The handler receives parsed arguments and options with correct typings.
|
|
427
|
-
*/
|
|
428
|
-
setAction(fn) {
|
|
429
|
-
this.action = setName(this.name, fn);
|
|
430
|
-
return this;
|
|
431
|
-
}
|
|
432
|
-
/** returns a new Command instance. Override this method in subclasses. */
|
|
433
|
-
createSubcommand(name) {
|
|
434
|
-
return new Command(name, this);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
_ts_decorate([
|
|
438
|
-
lazyProp,
|
|
439
|
-
_ts_metadata("design:type", typeof Help === "undefined" ? Object : Help),
|
|
440
|
-
_ts_metadata("design:paramtypes", [])
|
|
441
|
-
], Command.prototype, "help", null);
|
|
442
|
-
|
|
443
|
-
export { Command };
|