@clerc/core 0.17.3 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -11
- package/dist/index.js +23 -60
- package/dist/index.mjs +23 -60
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ type TypeFlag<Schemas extends Flags> = ParsedFlags<{
|
|
|
69
69
|
[flag in keyof Schemas]: InferFlagType<Schemas[flag]>;
|
|
70
70
|
}>;
|
|
71
71
|
|
|
72
|
+
type CommandType = SingleCommandType | string;
|
|
72
73
|
type FlagOptions = FlagSchema & {
|
|
73
74
|
description?: string;
|
|
74
75
|
};
|
|
@@ -305,15 +306,6 @@ declare class NoSuchCommandError extends Error {
|
|
|
305
306
|
declare class NoCommandGivenError extends Error {
|
|
306
307
|
constructor();
|
|
307
308
|
}
|
|
308
|
-
declare class ParentCommandExistsError extends Error {
|
|
309
|
-
constructor(name: string);
|
|
310
|
-
}
|
|
311
|
-
declare class SubcommandExistsError extends Error {
|
|
312
|
-
constructor(name: string);
|
|
313
|
-
}
|
|
314
|
-
declare class MultipleCommandsMatchedError extends Error {
|
|
315
|
-
constructor(name: string);
|
|
316
|
-
}
|
|
317
309
|
declare class CommandNameConflictError extends Error {
|
|
318
310
|
constructor(n1: string, n2: string);
|
|
319
311
|
}
|
|
@@ -336,7 +328,8 @@ declare function resolveSubcommandsByParent(commands: CommandRecord, parent: str
|
|
|
336
328
|
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[];
|
|
337
329
|
declare function resolveParametersBeforeFlag(argv: string[], isSingleCommand: boolean): string[];
|
|
338
330
|
declare const resolveArgv: () => string[];
|
|
339
|
-
declare function compose(inspectors: Inspector[]): (getCtx: () => InspectorContext) => void;
|
|
331
|
+
declare function compose(inspectors: Inspector[]): (getCtx: () => InspectorContext) => void;
|
|
332
|
+
declare const isInvalidName: (name: CommandType) => boolean;
|
|
340
333
|
|
|
341
334
|
interface ParsedParameter {
|
|
342
335
|
name: string;
|
|
@@ -346,4 +339,4 @@ interface ParsedParameter {
|
|
|
346
339
|
declare function parseParameters(parameters: string[]): ParsedParameter[];
|
|
347
340
|
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): Error | undefined;
|
|
348
341
|
|
|
349
|
-
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandWithHandler, CommonCommandExistsError, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap,
|
|
342
|
+
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, CommonCommandExistsError, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandAliasError, SingleCommandError, SingleCommandType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LiteEmit } from 'lite-emit';
|
|
2
2
|
import { typeFlag } from 'type-flag';
|
|
3
|
-
import {
|
|
3
|
+
import { toArray, arrayStartsWith, camelCase } from '@clerc/utils';
|
|
4
4
|
import { isNode, isDeno } from 'is-platform';
|
|
5
5
|
|
|
6
6
|
class SingleCommandError extends Error {
|
|
@@ -33,21 +33,6 @@ class NoCommandGivenError extends Error {
|
|
|
33
33
|
super("No command given.");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class ParentCommandExistsError extends Error {
|
|
37
|
-
constructor(name) {
|
|
38
|
-
super(`Command "${name}" cannot exist with its parent.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
class SubcommandExistsError extends Error {
|
|
42
|
-
constructor(name) {
|
|
43
|
-
super(`Command "${name}" cannot exist with its subcommand.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
class MultipleCommandsMatchedError extends Error {
|
|
47
|
-
constructor(name) {
|
|
48
|
-
super(`Multiple commands matched: ${name}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
36
|
class CommandNameConflictError extends Error {
|
|
52
37
|
constructor(n1, n2) {
|
|
53
38
|
super(`Command name ${n1} conflicts with ${n2}. Maybe caused by alias.`);
|
|
@@ -78,7 +63,7 @@ function resolveFlattenCommands(commands) {
|
|
|
78
63
|
const commandsMap = /* @__PURE__ */ new Map();
|
|
79
64
|
for (const command of Object.values(commands)) {
|
|
80
65
|
if (command.alias) {
|
|
81
|
-
const aliases =
|
|
66
|
+
const aliases = toArray(command.alias);
|
|
82
67
|
for (const alias of aliases) {
|
|
83
68
|
if (alias in commands) {
|
|
84
69
|
throw new CommandNameConflictError(commands[alias].name, command.name);
|
|
@@ -94,19 +79,17 @@ function resolveCommand(commands, name) {
|
|
|
94
79
|
if (name === SingleCommand) {
|
|
95
80
|
return commands[SingleCommand];
|
|
96
81
|
}
|
|
97
|
-
const nameArr =
|
|
82
|
+
const nameArr = toArray(name);
|
|
98
83
|
const commandsMap = resolveFlattenCommands(commands);
|
|
99
|
-
|
|
84
|
+
let current;
|
|
85
|
+
let currentName;
|
|
100
86
|
commandsMap.forEach((v, k) => {
|
|
101
|
-
if (arrayStartsWith(nameArr, k)) {
|
|
102
|
-
|
|
87
|
+
if (arrayStartsWith(nameArr, k) && (!currentName || k.length > currentName.length)) {
|
|
88
|
+
current = v;
|
|
89
|
+
currentName = k;
|
|
103
90
|
}
|
|
104
91
|
});
|
|
105
|
-
|
|
106
|
-
const matchedCommandNames = possibleCommands.map((c) => c.name).join(", ");
|
|
107
|
-
throw new MultipleCommandsMatchedError(matchedCommandNames);
|
|
108
|
-
}
|
|
109
|
-
return possibleCommands[0];
|
|
92
|
+
return current;
|
|
110
93
|
}
|
|
111
94
|
function resolveSubcommandsByParent(commands, parent, depth = Infinity) {
|
|
112
95
|
const parentArr = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" ");
|
|
@@ -152,6 +135,7 @@ function compose(inspectors) {
|
|
|
152
135
|
}
|
|
153
136
|
};
|
|
154
137
|
}
|
|
138
|
+
const isInvalidName = (name) => typeof name === "string" && (name.startsWith(" ") || name.endsWith(" "));
|
|
155
139
|
|
|
156
140
|
const { stringify } = JSON;
|
|
157
141
|
function parseParameters(parameters) {
|
|
@@ -228,7 +212,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
228
212
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
229
213
|
return value;
|
|
230
214
|
};
|
|
231
|
-
var _name, _description, _version, _inspectors, _commands,
|
|
215
|
+
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
|
|
232
216
|
const SingleCommand = Symbol("SingleCommand");
|
|
233
217
|
const _Clerc = class {
|
|
234
218
|
constructor() {
|
|
@@ -239,8 +223,8 @@ const _Clerc = class {
|
|
|
239
223
|
__privateAdd(this, _version, "");
|
|
240
224
|
__privateAdd(this, _inspectors, []);
|
|
241
225
|
__privateAdd(this, _commands, {});
|
|
242
|
-
__privateAdd(this, _flattenCommands, {});
|
|
243
226
|
__privateAdd(this, _commandEmitter, new LiteEmit());
|
|
227
|
+
__privateAdd(this, _usedNames, []);
|
|
244
228
|
}
|
|
245
229
|
get _name() {
|
|
246
230
|
return __privateGet(this, _name);
|
|
@@ -281,7 +265,7 @@ const _Clerc = class {
|
|
|
281
265
|
throw new CommandExistsError("SingleCommand");
|
|
282
266
|
}
|
|
283
267
|
}
|
|
284
|
-
if (
|
|
268
|
+
if (isInvalidName(name)) {
|
|
285
269
|
throw new InvalidCommandNameError(name);
|
|
286
270
|
}
|
|
287
271
|
if (__privateGet(this, _isSingleCommand, isSingleCommand_get)) {
|
|
@@ -293,38 +277,17 @@ const _Clerc = class {
|
|
|
293
277
|
if (name === SingleCommand && (isCommandObject ? nameOrCommand : options).alias) {
|
|
294
278
|
throw new SingleCommandAliasError();
|
|
295
279
|
}
|
|
296
|
-
if (name !== SingleCommand) {
|
|
297
|
-
const splitedName = name.split(" ");
|
|
298
|
-
const existedCommandNames = Object.keys(__privateGet(this, _commands)).filter((name2) => typeof name2 === "string").map((name2) => name2.split(" "));
|
|
299
|
-
if (existedCommandNames.some((name2) => arrayStartsWith(splitedName, name2))) {
|
|
300
|
-
throw new ParentCommandExistsError(splitedName.join(" "));
|
|
301
|
-
}
|
|
302
|
-
if (existedCommandNames.some((name2) => arrayStartsWith(name2, splitedName))) {
|
|
303
|
-
throw new SubcommandExistsError(splitedName.join(" "));
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
280
|
const { handler = void 0, ...commandToSave } = isCommandObject ? nameOrCommand : { name, description, ...options };
|
|
307
281
|
const nameList = [commandToSave.name];
|
|
308
|
-
|
|
309
|
-
const aliasList = mustArray(commandToSave.alias);
|
|
310
|
-
nameList.push(...aliasList);
|
|
311
|
-
}
|
|
282
|
+
commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
|
|
312
283
|
for (const name2 of nameList) {
|
|
313
|
-
if (__privateGet(this,
|
|
284
|
+
if (__privateGet(this, _usedNames).includes(name2)) {
|
|
314
285
|
throw new CommandExistsError(name2);
|
|
315
286
|
}
|
|
316
287
|
}
|
|
317
288
|
__privateGet(this, _commands)[name] = commandToSave;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
__privateGet(this, _flattenCommands)[name] = commandToSave;
|
|
322
|
-
if (commandToSave.alias) {
|
|
323
|
-
const aliasList = mustArray(commandToSave.alias);
|
|
324
|
-
aliasList.forEach((alias) => {
|
|
325
|
-
__privateGet(this, _flattenCommands)[alias] = commandToSave;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
289
|
+
__privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
|
|
290
|
+
isCommandObject && handler && this.on(nameOrCommand.name, handler);
|
|
328
291
|
return this;
|
|
329
292
|
}
|
|
330
293
|
on(name, handler) {
|
|
@@ -357,7 +320,7 @@ const _Clerc = class {
|
|
|
357
320
|
const command = getCommand();
|
|
358
321
|
const isCommandResolved = !!command;
|
|
359
322
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
360
|
-
const { _: args, flags } = parsed;
|
|
323
|
+
const { _: args, flags, unknownFlags } = parsed;
|
|
361
324
|
let parameters = __privateGet(this, _isSingleCommand, isSingleCommand_get) || !isCommandResolved ? args : args.slice(command.name.split(" ").length);
|
|
362
325
|
let commandParameters = (command == null ? void 0 : command.parameters) || [];
|
|
363
326
|
const hasEof = commandParameters.indexOf("--");
|
|
@@ -365,7 +328,7 @@ const _Clerc = class {
|
|
|
365
328
|
const mapping = /* @__PURE__ */ Object.create(null);
|
|
366
329
|
if (hasEof > -1 && eofParameters.length > 0) {
|
|
367
330
|
commandParameters = commandParameters.slice(0, hasEof);
|
|
368
|
-
const eofArguments =
|
|
331
|
+
const eofArguments = args["--"];
|
|
369
332
|
parameters = parameters.slice(0, -eofArguments.length || void 0);
|
|
370
333
|
mapErrors.push(mapParametersToArguments(
|
|
371
334
|
mapping,
|
|
@@ -384,7 +347,7 @@ const _Clerc = class {
|
|
|
384
347
|
parameters
|
|
385
348
|
));
|
|
386
349
|
}
|
|
387
|
-
const mergedFlags = { ...
|
|
350
|
+
const mergedFlags = { ...flags, ...unknownFlags };
|
|
388
351
|
const context = {
|
|
389
352
|
name: command == null ? void 0 : command.name,
|
|
390
353
|
resolved: isCommandResolved,
|
|
@@ -392,7 +355,7 @@ const _Clerc = class {
|
|
|
392
355
|
raw: { ...parsed, parameters, mergedFlags },
|
|
393
356
|
parameters: mapping,
|
|
394
357
|
flags,
|
|
395
|
-
unknownFlags
|
|
358
|
+
unknownFlags,
|
|
396
359
|
cli: this
|
|
397
360
|
};
|
|
398
361
|
return context;
|
|
@@ -428,8 +391,8 @@ _description = new WeakMap();
|
|
|
428
391
|
_version = new WeakMap();
|
|
429
392
|
_inspectors = new WeakMap();
|
|
430
393
|
_commands = new WeakMap();
|
|
431
|
-
_flattenCommands = new WeakMap();
|
|
432
394
|
_commandEmitter = new WeakMap();
|
|
395
|
+
_usedNames = new WeakMap();
|
|
433
396
|
_isSingleCommand = new WeakSet();
|
|
434
397
|
isSingleCommand_get = function() {
|
|
435
398
|
return __privateGet(this, _commands)[SingleCommand] !== void 0;
|
|
@@ -444,4 +407,4 @@ const defineHandler = (_cli, _key, handler) => handler;
|
|
|
444
407
|
const defineInspector = (_cli, inspector) => inspector;
|
|
445
408
|
const defineCommand = (command) => command;
|
|
446
409
|
|
|
447
|
-
export { Clerc, CommandExistsError, CommandNameConflictError, CommonCommandExistsError, DescriptionNotSetError, InvalidCommandNameError,
|
|
410
|
+
export { Clerc, CommandExistsError, CommandNameConflictError, CommonCommandExistsError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, SingleCommandAliasError, SingleCommandError, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LiteEmit } from 'lite-emit';
|
|
2
2
|
import { typeFlag } from 'type-flag';
|
|
3
|
-
import {
|
|
3
|
+
import { toArray, arrayStartsWith, camelCase } from '@clerc/utils';
|
|
4
4
|
import { isNode, isDeno } from 'is-platform';
|
|
5
5
|
|
|
6
6
|
class SingleCommandError extends Error {
|
|
@@ -33,21 +33,6 @@ class NoCommandGivenError extends Error {
|
|
|
33
33
|
super("No command given.");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class ParentCommandExistsError extends Error {
|
|
37
|
-
constructor(name) {
|
|
38
|
-
super(`Command "${name}" cannot exist with its parent.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
class SubcommandExistsError extends Error {
|
|
42
|
-
constructor(name) {
|
|
43
|
-
super(`Command "${name}" cannot exist with its subcommand.`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
class MultipleCommandsMatchedError extends Error {
|
|
47
|
-
constructor(name) {
|
|
48
|
-
super(`Multiple commands matched: ${name}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
36
|
class CommandNameConflictError extends Error {
|
|
52
37
|
constructor(n1, n2) {
|
|
53
38
|
super(`Command name ${n1} conflicts with ${n2}. Maybe caused by alias.`);
|
|
@@ -78,7 +63,7 @@ function resolveFlattenCommands(commands) {
|
|
|
78
63
|
const commandsMap = /* @__PURE__ */ new Map();
|
|
79
64
|
for (const command of Object.values(commands)) {
|
|
80
65
|
if (command.alias) {
|
|
81
|
-
const aliases =
|
|
66
|
+
const aliases = toArray(command.alias);
|
|
82
67
|
for (const alias of aliases) {
|
|
83
68
|
if (alias in commands) {
|
|
84
69
|
throw new CommandNameConflictError(commands[alias].name, command.name);
|
|
@@ -94,19 +79,17 @@ function resolveCommand(commands, name) {
|
|
|
94
79
|
if (name === SingleCommand) {
|
|
95
80
|
return commands[SingleCommand];
|
|
96
81
|
}
|
|
97
|
-
const nameArr =
|
|
82
|
+
const nameArr = toArray(name);
|
|
98
83
|
const commandsMap = resolveFlattenCommands(commands);
|
|
99
|
-
|
|
84
|
+
let current;
|
|
85
|
+
let currentName;
|
|
100
86
|
commandsMap.forEach((v, k) => {
|
|
101
|
-
if (arrayStartsWith(nameArr, k)) {
|
|
102
|
-
|
|
87
|
+
if (arrayStartsWith(nameArr, k) && (!currentName || k.length > currentName.length)) {
|
|
88
|
+
current = v;
|
|
89
|
+
currentName = k;
|
|
103
90
|
}
|
|
104
91
|
});
|
|
105
|
-
|
|
106
|
-
const matchedCommandNames = possibleCommands.map((c) => c.name).join(", ");
|
|
107
|
-
throw new MultipleCommandsMatchedError(matchedCommandNames);
|
|
108
|
-
}
|
|
109
|
-
return possibleCommands[0];
|
|
92
|
+
return current;
|
|
110
93
|
}
|
|
111
94
|
function resolveSubcommandsByParent(commands, parent, depth = Infinity) {
|
|
112
95
|
const parentArr = parent === "" ? [] : Array.isArray(parent) ? parent : parent.split(" ");
|
|
@@ -152,6 +135,7 @@ function compose(inspectors) {
|
|
|
152
135
|
}
|
|
153
136
|
};
|
|
154
137
|
}
|
|
138
|
+
const isInvalidName = (name) => typeof name === "string" && (name.startsWith(" ") || name.endsWith(" "));
|
|
155
139
|
|
|
156
140
|
const { stringify } = JSON;
|
|
157
141
|
function parseParameters(parameters) {
|
|
@@ -228,7 +212,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
228
212
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
229
213
|
return value;
|
|
230
214
|
};
|
|
231
|
-
var _name, _description, _version, _inspectors, _commands,
|
|
215
|
+
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _isSingleCommand, isSingleCommand_get, _hasCommands, hasCommands_get;
|
|
232
216
|
const SingleCommand = Symbol("SingleCommand");
|
|
233
217
|
const _Clerc = class {
|
|
234
218
|
constructor() {
|
|
@@ -239,8 +223,8 @@ const _Clerc = class {
|
|
|
239
223
|
__privateAdd(this, _version, "");
|
|
240
224
|
__privateAdd(this, _inspectors, []);
|
|
241
225
|
__privateAdd(this, _commands, {});
|
|
242
|
-
__privateAdd(this, _flattenCommands, {});
|
|
243
226
|
__privateAdd(this, _commandEmitter, new LiteEmit());
|
|
227
|
+
__privateAdd(this, _usedNames, []);
|
|
244
228
|
}
|
|
245
229
|
get _name() {
|
|
246
230
|
return __privateGet(this, _name);
|
|
@@ -281,7 +265,7 @@ const _Clerc = class {
|
|
|
281
265
|
throw new CommandExistsError("SingleCommand");
|
|
282
266
|
}
|
|
283
267
|
}
|
|
284
|
-
if (
|
|
268
|
+
if (isInvalidName(name)) {
|
|
285
269
|
throw new InvalidCommandNameError(name);
|
|
286
270
|
}
|
|
287
271
|
if (__privateGet(this, _isSingleCommand, isSingleCommand_get)) {
|
|
@@ -293,38 +277,17 @@ const _Clerc = class {
|
|
|
293
277
|
if (name === SingleCommand && (isCommandObject ? nameOrCommand : options).alias) {
|
|
294
278
|
throw new SingleCommandAliasError();
|
|
295
279
|
}
|
|
296
|
-
if (name !== SingleCommand) {
|
|
297
|
-
const splitedName = name.split(" ");
|
|
298
|
-
const existedCommandNames = Object.keys(__privateGet(this, _commands)).filter((name2) => typeof name2 === "string").map((name2) => name2.split(" "));
|
|
299
|
-
if (existedCommandNames.some((name2) => arrayStartsWith(splitedName, name2))) {
|
|
300
|
-
throw new ParentCommandExistsError(splitedName.join(" "));
|
|
301
|
-
}
|
|
302
|
-
if (existedCommandNames.some((name2) => arrayStartsWith(name2, splitedName))) {
|
|
303
|
-
throw new SubcommandExistsError(splitedName.join(" "));
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
280
|
const { handler = void 0, ...commandToSave } = isCommandObject ? nameOrCommand : { name, description, ...options };
|
|
307
281
|
const nameList = [commandToSave.name];
|
|
308
|
-
|
|
309
|
-
const aliasList = mustArray(commandToSave.alias);
|
|
310
|
-
nameList.push(...aliasList);
|
|
311
|
-
}
|
|
282
|
+
commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
|
|
312
283
|
for (const name2 of nameList) {
|
|
313
|
-
if (__privateGet(this,
|
|
284
|
+
if (__privateGet(this, _usedNames).includes(name2)) {
|
|
314
285
|
throw new CommandExistsError(name2);
|
|
315
286
|
}
|
|
316
287
|
}
|
|
317
288
|
__privateGet(this, _commands)[name] = commandToSave;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
__privateGet(this, _flattenCommands)[name] = commandToSave;
|
|
322
|
-
if (commandToSave.alias) {
|
|
323
|
-
const aliasList = mustArray(commandToSave.alias);
|
|
324
|
-
aliasList.forEach((alias) => {
|
|
325
|
-
__privateGet(this, _flattenCommands)[alias] = commandToSave;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
289
|
+
__privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
|
|
290
|
+
isCommandObject && handler && this.on(nameOrCommand.name, handler);
|
|
328
291
|
return this;
|
|
329
292
|
}
|
|
330
293
|
on(name, handler) {
|
|
@@ -357,7 +320,7 @@ const _Clerc = class {
|
|
|
357
320
|
const command = getCommand();
|
|
358
321
|
const isCommandResolved = !!command;
|
|
359
322
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
360
|
-
const { _: args, flags } = parsed;
|
|
323
|
+
const { _: args, flags, unknownFlags } = parsed;
|
|
361
324
|
let parameters = __privateGet(this, _isSingleCommand, isSingleCommand_get) || !isCommandResolved ? args : args.slice(command.name.split(" ").length);
|
|
362
325
|
let commandParameters = (command == null ? void 0 : command.parameters) || [];
|
|
363
326
|
const hasEof = commandParameters.indexOf("--");
|
|
@@ -365,7 +328,7 @@ const _Clerc = class {
|
|
|
365
328
|
const mapping = /* @__PURE__ */ Object.create(null);
|
|
366
329
|
if (hasEof > -1 && eofParameters.length > 0) {
|
|
367
330
|
commandParameters = commandParameters.slice(0, hasEof);
|
|
368
|
-
const eofArguments =
|
|
331
|
+
const eofArguments = args["--"];
|
|
369
332
|
parameters = parameters.slice(0, -eofArguments.length || void 0);
|
|
370
333
|
mapErrors.push(mapParametersToArguments(
|
|
371
334
|
mapping,
|
|
@@ -384,7 +347,7 @@ const _Clerc = class {
|
|
|
384
347
|
parameters
|
|
385
348
|
));
|
|
386
349
|
}
|
|
387
|
-
const mergedFlags = { ...
|
|
350
|
+
const mergedFlags = { ...flags, ...unknownFlags };
|
|
388
351
|
const context = {
|
|
389
352
|
name: command == null ? void 0 : command.name,
|
|
390
353
|
resolved: isCommandResolved,
|
|
@@ -392,7 +355,7 @@ const _Clerc = class {
|
|
|
392
355
|
raw: { ...parsed, parameters, mergedFlags },
|
|
393
356
|
parameters: mapping,
|
|
394
357
|
flags,
|
|
395
|
-
unknownFlags
|
|
358
|
+
unknownFlags,
|
|
396
359
|
cli: this
|
|
397
360
|
};
|
|
398
361
|
return context;
|
|
@@ -428,8 +391,8 @@ _description = new WeakMap();
|
|
|
428
391
|
_version = new WeakMap();
|
|
429
392
|
_inspectors = new WeakMap();
|
|
430
393
|
_commands = new WeakMap();
|
|
431
|
-
_flattenCommands = new WeakMap();
|
|
432
394
|
_commandEmitter = new WeakMap();
|
|
395
|
+
_usedNames = new WeakMap();
|
|
433
396
|
_isSingleCommand = new WeakSet();
|
|
434
397
|
isSingleCommand_get = function() {
|
|
435
398
|
return __privateGet(this, _commands)[SingleCommand] !== void 0;
|
|
@@ -444,4 +407,4 @@ const defineHandler = (_cli, _key, handler) => handler;
|
|
|
444
407
|
const defineInspector = (_cli, inspector) => inspector;
|
|
445
408
|
const defineCommand = (command) => command;
|
|
446
409
|
|
|
447
|
-
export { Clerc, CommandExistsError, CommandNameConflictError, CommonCommandExistsError, DescriptionNotSetError, InvalidCommandNameError,
|
|
410
|
+
export { Clerc, CommandExistsError, CommandNameConflictError, CommonCommandExistsError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, SingleCommandAliasError, SingleCommandError, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc core",
|
|
6
6
|
"keywords": [
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"is-platform": "^0.2.0",
|
|
51
51
|
"lite-emit": "^1.4.0",
|
|
52
52
|
"type-flag": "^3.0.0",
|
|
53
|
-
"@clerc/utils": "0.
|
|
53
|
+
"@clerc/utils": "0.19.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "puild",
|