@clerc/core 0.19.0 → 0.20.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 +5 -14
- package/dist/index.js +23 -49
- package/dist/index.mjs +23 -49
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -121,7 +121,7 @@ type Raw<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> =
|
|
|
121
121
|
interface HandlerContext<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> {
|
|
122
122
|
name: N extends keyof C ? N : N | undefined;
|
|
123
123
|
resolved: N extends keyof C ? true : boolean;
|
|
124
|
-
|
|
124
|
+
hasSingleCommand: boolean;
|
|
125
125
|
raw: Raw<C, N>;
|
|
126
126
|
parameters: TransformParameters<C, N>;
|
|
127
127
|
unknownFlags: ParsedFlags["unknownFlags"];
|
|
@@ -288,18 +288,9 @@ declare const defineHandler: <C extends Clerc<{}>, K extends keyof C["_commands"
|
|
|
288
288
|
declare const defineInspector: <C extends Clerc<{}>>(_cli: C, inspector: Inspector<C["_commands"]>) => Inspector<C["_commands"]>;
|
|
289
289
|
declare const defineCommand: <N extends string | typeof SingleCommand, O extends CommandOptions<[...P], A, F>, P extends string[] = string[], A extends MaybeArray<string> = MaybeArray<string>, F extends Dict<FlagOptions> = Dict<FlagOptions>>(command: CommandWithHandler<N, O & CommandOptions<[...P], A, F>>) => CommandWithHandler<N, O & CommandOptions<[...P], A, F>>;
|
|
290
290
|
|
|
291
|
-
declare class SingleCommandError extends Error {
|
|
292
|
-
constructor();
|
|
293
|
-
}
|
|
294
|
-
declare class SingleCommandAliasError extends Error {
|
|
295
|
-
constructor();
|
|
296
|
-
}
|
|
297
291
|
declare class CommandExistsError extends Error {
|
|
298
292
|
constructor(name: string);
|
|
299
293
|
}
|
|
300
|
-
declare class CommonCommandExistsError extends Error {
|
|
301
|
-
constructor();
|
|
302
|
-
}
|
|
303
294
|
declare class NoSuchCommandError extends Error {
|
|
304
295
|
constructor(name: string);
|
|
305
296
|
}
|
|
@@ -322,11 +313,11 @@ declare class InvalidCommandNameError extends Error {
|
|
|
322
313
|
constructor(name: string);
|
|
323
314
|
}
|
|
324
315
|
|
|
325
|
-
declare function resolveFlattenCommands(commands: CommandRecord): Map<string[], CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>>;
|
|
326
|
-
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command | undefined;
|
|
316
|
+
declare function resolveFlattenCommands(commands: CommandRecord): Map<string[] | typeof SingleCommand, CommandAlias<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>>;
|
|
317
|
+
declare function resolveCommand(commands: CommandRecord, name: string | string[] | SingleCommandType): Command<string | SingleCommandType> | undefined;
|
|
327
318
|
declare function resolveSubcommandsByParent(commands: CommandRecord, parent: string | string[], depth?: number): Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[];
|
|
328
319
|
declare const resolveRootCommands: (commands: CommandRecord) => Command<string, CommandOptions<string[], _clerc_utils.MaybeArray<string>, _clerc_utils.Dict<FlagOptions>>>[];
|
|
329
|
-
declare function resolveParametersBeforeFlag(argv: string[]
|
|
320
|
+
declare function resolveParametersBeforeFlag(argv: string[]): string[];
|
|
330
321
|
declare const resolveArgv: () => string[];
|
|
331
322
|
declare function compose(inspectors: Inspector[]): (getCtx: () => InspectorContext) => void;
|
|
332
323
|
declare const isInvalidName: (name: CommandType) => boolean;
|
|
@@ -339,4 +330,4 @@ interface ParsedParameter {
|
|
|
339
330
|
declare function parseParameters(parameters: string[]): ParsedParameter[];
|
|
340
331
|
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): Error | undefined;
|
|
341
332
|
|
|
342
|
-
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler,
|
|
333
|
+
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, SingleCommand, SingleCommandType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.js
CHANGED
|
@@ -3,26 +3,11 @@ import { typeFlag } from 'type-flag';
|
|
|
3
3
|
import { toArray, arrayStartsWith, camelCase } from '@clerc/utils';
|
|
4
4
|
import { isNode, isDeno } from 'is-platform';
|
|
5
5
|
|
|
6
|
-
class SingleCommandError extends Error {
|
|
7
|
-
constructor() {
|
|
8
|
-
super("Single command mode enabled.");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
class SingleCommandAliasError extends Error {
|
|
12
|
-
constructor() {
|
|
13
|
-
super("Single command cannot have alias.");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
6
|
class CommandExistsError extends Error {
|
|
17
7
|
constructor(name) {
|
|
18
8
|
super(`Command "${name}" exists.`);
|
|
19
9
|
}
|
|
20
10
|
}
|
|
21
|
-
class CommonCommandExistsError extends Error {
|
|
22
|
-
constructor() {
|
|
23
|
-
super("Common command exists.");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
11
|
class NoSuchCommandError extends Error {
|
|
27
12
|
constructor(name) {
|
|
28
13
|
super(`No such command: ${name}`);
|
|
@@ -61,6 +46,9 @@ class InvalidCommandNameError extends Error {
|
|
|
61
46
|
|
|
62
47
|
function resolveFlattenCommands(commands) {
|
|
63
48
|
const commandsMap = /* @__PURE__ */ new Map();
|
|
49
|
+
if (commands[SingleCommand]) {
|
|
50
|
+
commandsMap.set(SingleCommand, commands[SingleCommand]);
|
|
51
|
+
}
|
|
64
52
|
for (const command of Object.values(commands)) {
|
|
65
53
|
if (command.alias) {
|
|
66
54
|
const aliases = toArray(command.alias);
|
|
@@ -84,7 +72,12 @@ function resolveCommand(commands, name) {
|
|
|
84
72
|
let current;
|
|
85
73
|
let currentName;
|
|
86
74
|
commandsMap.forEach((v, k) => {
|
|
87
|
-
if (
|
|
75
|
+
if (k === SingleCommand) {
|
|
76
|
+
current = commandsMap.get(SingleCommand);
|
|
77
|
+
currentName = SingleCommand;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (arrayStartsWith(nameArr, k) && (!currentName || currentName === SingleCommand || k.length > currentName.length)) {
|
|
88
81
|
current = v;
|
|
89
82
|
currentName = k;
|
|
90
83
|
}
|
|
@@ -99,10 +92,7 @@ function resolveSubcommandsByParent(commands, parent, depth = Infinity) {
|
|
|
99
92
|
});
|
|
100
93
|
}
|
|
101
94
|
const resolveRootCommands = (commands) => resolveSubcommandsByParent(commands, "", 1);
|
|
102
|
-
function resolveParametersBeforeFlag(argv
|
|
103
|
-
if (isSingleCommand) {
|
|
104
|
-
return [];
|
|
105
|
-
}
|
|
95
|
+
function resolveParametersBeforeFlag(argv) {
|
|
106
96
|
const parameters = [];
|
|
107
97
|
for (const arg of argv) {
|
|
108
98
|
if (arg.startsWith("-")) {
|
|
@@ -212,12 +202,10 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
212
202
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
213
203
|
return value;
|
|
214
204
|
};
|
|
215
|
-
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames,
|
|
205
|
+
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _hasSingleCommand;
|
|
216
206
|
const SingleCommand = Symbol("SingleCommand");
|
|
217
207
|
const _Clerc = class {
|
|
218
208
|
constructor() {
|
|
219
|
-
__privateAdd(this, _isSingleCommand);
|
|
220
|
-
__privateAdd(this, _hasCommands);
|
|
221
209
|
__privateAdd(this, _name, "");
|
|
222
210
|
__privateAdd(this, _description, "");
|
|
223
211
|
__privateAdd(this, _version, "");
|
|
@@ -225,6 +213,7 @@ const _Clerc = class {
|
|
|
225
213
|
__privateAdd(this, _commands, {});
|
|
226
214
|
__privateAdd(this, _commandEmitter, new LiteEmit());
|
|
227
215
|
__privateAdd(this, _usedNames, []);
|
|
216
|
+
__privateAdd(this, _hasSingleCommand, false);
|
|
228
217
|
}
|
|
229
218
|
get _name() {
|
|
230
219
|
return __privateGet(this, _name);
|
|
@@ -256,27 +245,16 @@ const _Clerc = class {
|
|
|
256
245
|
__privateSet(this, _version, version);
|
|
257
246
|
return this;
|
|
258
247
|
}
|
|
259
|
-
command(nameOrCommand, description, options) {
|
|
248
|
+
command(nameOrCommand, description, options = {}) {
|
|
260
249
|
const checkIsCommandObject = (nameOrCommand2) => !(typeof nameOrCommand2 === "string" || nameOrCommand2 === SingleCommand);
|
|
261
250
|
const isCommandObject = checkIsCommandObject(nameOrCommand);
|
|
262
251
|
const name = !isCommandObject ? nameOrCommand : nameOrCommand.name;
|
|
263
252
|
if (__privateGet(this, _commands)[name]) {
|
|
264
|
-
|
|
265
|
-
throw new CommandExistsError("SingleCommand");
|
|
266
|
-
}
|
|
253
|
+
throw new CommandExistsError(typeof name === "symbol" ? "" : name);
|
|
267
254
|
}
|
|
268
255
|
if (isInvalidName(name)) {
|
|
269
256
|
throw new InvalidCommandNameError(name);
|
|
270
257
|
}
|
|
271
|
-
if (__privateGet(this, _isSingleCommand, isSingleCommand_get)) {
|
|
272
|
-
throw new SingleCommandError();
|
|
273
|
-
}
|
|
274
|
-
if (name === SingleCommand && __privateGet(this, _hasCommands, hasCommands_get)) {
|
|
275
|
-
throw new CommonCommandExistsError();
|
|
276
|
-
}
|
|
277
|
-
if (name === SingleCommand && (isCommandObject ? nameOrCommand : options).alias) {
|
|
278
|
-
throw new SingleCommandAliasError();
|
|
279
|
-
}
|
|
280
258
|
const { handler = void 0, ...commandToSave } = isCommandObject ? nameOrCommand : { name, description, ...options };
|
|
281
259
|
const nameList = [commandToSave.name];
|
|
282
260
|
commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
|
|
@@ -285,6 +263,9 @@ const _Clerc = class {
|
|
|
285
263
|
throw new CommandExistsError(name2);
|
|
286
264
|
}
|
|
287
265
|
}
|
|
266
|
+
if (nameList.includes(SingleCommand)) {
|
|
267
|
+
__privateSet(this, _hasSingleCommand, true);
|
|
268
|
+
}
|
|
288
269
|
__privateGet(this, _commands)[name] = commandToSave;
|
|
289
270
|
__privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
|
|
290
271
|
isCommandObject && handler && this.on(nameOrCommand.name, handler);
|
|
@@ -311,9 +292,9 @@ const _Clerc = class {
|
|
|
311
292
|
if (!__privateGet(this, _version)) {
|
|
312
293
|
throw new VersionNotSetError();
|
|
313
294
|
}
|
|
314
|
-
const name = resolveParametersBeforeFlag(argv
|
|
295
|
+
const name = resolveParametersBeforeFlag(argv);
|
|
315
296
|
const stringName = name.join(" ");
|
|
316
|
-
const getCommand = () =>
|
|
297
|
+
const getCommand = () => resolveCommand(__privateGet(this, _commands), name);
|
|
317
298
|
const mapErrors = [];
|
|
318
299
|
const getContext = () => {
|
|
319
300
|
mapErrors.length = 0;
|
|
@@ -321,7 +302,7 @@ const _Clerc = class {
|
|
|
321
302
|
const isCommandResolved = !!command;
|
|
322
303
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
323
304
|
const { _: args, flags, unknownFlags } = parsed;
|
|
324
|
-
let parameters =
|
|
305
|
+
let parameters = !isCommandResolved || command.name === SingleCommand ? args : args.slice(command.name.split(" ").length);
|
|
325
306
|
let commandParameters = (command == null ? void 0 : command.parameters) || [];
|
|
326
307
|
const hasEof = commandParameters.indexOf("--");
|
|
327
308
|
const eofParameters = commandParameters.slice(hasEof + 1) || [];
|
|
@@ -351,7 +332,7 @@ const _Clerc = class {
|
|
|
351
332
|
const context = {
|
|
352
333
|
name: command == null ? void 0 : command.name,
|
|
353
334
|
resolved: isCommandResolved,
|
|
354
|
-
|
|
335
|
+
hasSingleCommand: __privateGet(this, _hasSingleCommand),
|
|
355
336
|
raw: { ...parsed, parameters, mergedFlags },
|
|
356
337
|
parameters: mapping,
|
|
357
338
|
flags,
|
|
@@ -393,18 +374,11 @@ _inspectors = new WeakMap();
|
|
|
393
374
|
_commands = new WeakMap();
|
|
394
375
|
_commandEmitter = new WeakMap();
|
|
395
376
|
_usedNames = new WeakMap();
|
|
396
|
-
|
|
397
|
-
isSingleCommand_get = function() {
|
|
398
|
-
return __privateGet(this, _commands)[SingleCommand] !== void 0;
|
|
399
|
-
};
|
|
400
|
-
_hasCommands = new WeakSet();
|
|
401
|
-
hasCommands_get = function() {
|
|
402
|
-
return Object.keys(__privateGet(this, _commands)).length > 0;
|
|
403
|
-
};
|
|
377
|
+
_hasSingleCommand = new WeakMap();
|
|
404
378
|
|
|
405
379
|
const definePlugin = (p) => p;
|
|
406
380
|
const defineHandler = (_cli, _key, handler) => handler;
|
|
407
381
|
const defineInspector = (_cli, inspector) => inspector;
|
|
408
382
|
const defineCommand = (command) => command;
|
|
409
383
|
|
|
410
|
-
export { Clerc, CommandExistsError, CommandNameConflictError,
|
|
384
|
+
export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.mjs
CHANGED
|
@@ -3,26 +3,11 @@ import { typeFlag } from 'type-flag';
|
|
|
3
3
|
import { toArray, arrayStartsWith, camelCase } from '@clerc/utils';
|
|
4
4
|
import { isNode, isDeno } from 'is-platform';
|
|
5
5
|
|
|
6
|
-
class SingleCommandError extends Error {
|
|
7
|
-
constructor() {
|
|
8
|
-
super("Single command mode enabled.");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
class SingleCommandAliasError extends Error {
|
|
12
|
-
constructor() {
|
|
13
|
-
super("Single command cannot have alias.");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
6
|
class CommandExistsError extends Error {
|
|
17
7
|
constructor(name) {
|
|
18
8
|
super(`Command "${name}" exists.`);
|
|
19
9
|
}
|
|
20
10
|
}
|
|
21
|
-
class CommonCommandExistsError extends Error {
|
|
22
|
-
constructor() {
|
|
23
|
-
super("Common command exists.");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
11
|
class NoSuchCommandError extends Error {
|
|
27
12
|
constructor(name) {
|
|
28
13
|
super(`No such command: ${name}`);
|
|
@@ -61,6 +46,9 @@ class InvalidCommandNameError extends Error {
|
|
|
61
46
|
|
|
62
47
|
function resolveFlattenCommands(commands) {
|
|
63
48
|
const commandsMap = /* @__PURE__ */ new Map();
|
|
49
|
+
if (commands[SingleCommand]) {
|
|
50
|
+
commandsMap.set(SingleCommand, commands[SingleCommand]);
|
|
51
|
+
}
|
|
64
52
|
for (const command of Object.values(commands)) {
|
|
65
53
|
if (command.alias) {
|
|
66
54
|
const aliases = toArray(command.alias);
|
|
@@ -84,7 +72,12 @@ function resolveCommand(commands, name) {
|
|
|
84
72
|
let current;
|
|
85
73
|
let currentName;
|
|
86
74
|
commandsMap.forEach((v, k) => {
|
|
87
|
-
if (
|
|
75
|
+
if (k === SingleCommand) {
|
|
76
|
+
current = commandsMap.get(SingleCommand);
|
|
77
|
+
currentName = SingleCommand;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (arrayStartsWith(nameArr, k) && (!currentName || currentName === SingleCommand || k.length > currentName.length)) {
|
|
88
81
|
current = v;
|
|
89
82
|
currentName = k;
|
|
90
83
|
}
|
|
@@ -99,10 +92,7 @@ function resolveSubcommandsByParent(commands, parent, depth = Infinity) {
|
|
|
99
92
|
});
|
|
100
93
|
}
|
|
101
94
|
const resolveRootCommands = (commands) => resolveSubcommandsByParent(commands, "", 1);
|
|
102
|
-
function resolveParametersBeforeFlag(argv
|
|
103
|
-
if (isSingleCommand) {
|
|
104
|
-
return [];
|
|
105
|
-
}
|
|
95
|
+
function resolveParametersBeforeFlag(argv) {
|
|
106
96
|
const parameters = [];
|
|
107
97
|
for (const arg of argv) {
|
|
108
98
|
if (arg.startsWith("-")) {
|
|
@@ -212,12 +202,10 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
212
202
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
213
203
|
return value;
|
|
214
204
|
};
|
|
215
|
-
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames,
|
|
205
|
+
var _name, _description, _version, _inspectors, _commands, _commandEmitter, _usedNames, _hasSingleCommand;
|
|
216
206
|
const SingleCommand = Symbol("SingleCommand");
|
|
217
207
|
const _Clerc = class {
|
|
218
208
|
constructor() {
|
|
219
|
-
__privateAdd(this, _isSingleCommand);
|
|
220
|
-
__privateAdd(this, _hasCommands);
|
|
221
209
|
__privateAdd(this, _name, "");
|
|
222
210
|
__privateAdd(this, _description, "");
|
|
223
211
|
__privateAdd(this, _version, "");
|
|
@@ -225,6 +213,7 @@ const _Clerc = class {
|
|
|
225
213
|
__privateAdd(this, _commands, {});
|
|
226
214
|
__privateAdd(this, _commandEmitter, new LiteEmit());
|
|
227
215
|
__privateAdd(this, _usedNames, []);
|
|
216
|
+
__privateAdd(this, _hasSingleCommand, false);
|
|
228
217
|
}
|
|
229
218
|
get _name() {
|
|
230
219
|
return __privateGet(this, _name);
|
|
@@ -256,27 +245,16 @@ const _Clerc = class {
|
|
|
256
245
|
__privateSet(this, _version, version);
|
|
257
246
|
return this;
|
|
258
247
|
}
|
|
259
|
-
command(nameOrCommand, description, options) {
|
|
248
|
+
command(nameOrCommand, description, options = {}) {
|
|
260
249
|
const checkIsCommandObject = (nameOrCommand2) => !(typeof nameOrCommand2 === "string" || nameOrCommand2 === SingleCommand);
|
|
261
250
|
const isCommandObject = checkIsCommandObject(nameOrCommand);
|
|
262
251
|
const name = !isCommandObject ? nameOrCommand : nameOrCommand.name;
|
|
263
252
|
if (__privateGet(this, _commands)[name]) {
|
|
264
|
-
|
|
265
|
-
throw new CommandExistsError("SingleCommand");
|
|
266
|
-
}
|
|
253
|
+
throw new CommandExistsError(typeof name === "symbol" ? "" : name);
|
|
267
254
|
}
|
|
268
255
|
if (isInvalidName(name)) {
|
|
269
256
|
throw new InvalidCommandNameError(name);
|
|
270
257
|
}
|
|
271
|
-
if (__privateGet(this, _isSingleCommand, isSingleCommand_get)) {
|
|
272
|
-
throw new SingleCommandError();
|
|
273
|
-
}
|
|
274
|
-
if (name === SingleCommand && __privateGet(this, _hasCommands, hasCommands_get)) {
|
|
275
|
-
throw new CommonCommandExistsError();
|
|
276
|
-
}
|
|
277
|
-
if (name === SingleCommand && (isCommandObject ? nameOrCommand : options).alias) {
|
|
278
|
-
throw new SingleCommandAliasError();
|
|
279
|
-
}
|
|
280
258
|
const { handler = void 0, ...commandToSave } = isCommandObject ? nameOrCommand : { name, description, ...options };
|
|
281
259
|
const nameList = [commandToSave.name];
|
|
282
260
|
commandToSave.alias && nameList.push(...toArray(commandToSave.alias));
|
|
@@ -285,6 +263,9 @@ const _Clerc = class {
|
|
|
285
263
|
throw new CommandExistsError(name2);
|
|
286
264
|
}
|
|
287
265
|
}
|
|
266
|
+
if (nameList.includes(SingleCommand)) {
|
|
267
|
+
__privateSet(this, _hasSingleCommand, true);
|
|
268
|
+
}
|
|
288
269
|
__privateGet(this, _commands)[name] = commandToSave;
|
|
289
270
|
__privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
|
|
290
271
|
isCommandObject && handler && this.on(nameOrCommand.name, handler);
|
|
@@ -311,9 +292,9 @@ const _Clerc = class {
|
|
|
311
292
|
if (!__privateGet(this, _version)) {
|
|
312
293
|
throw new VersionNotSetError();
|
|
313
294
|
}
|
|
314
|
-
const name = resolveParametersBeforeFlag(argv
|
|
295
|
+
const name = resolveParametersBeforeFlag(argv);
|
|
315
296
|
const stringName = name.join(" ");
|
|
316
|
-
const getCommand = () =>
|
|
297
|
+
const getCommand = () => resolveCommand(__privateGet(this, _commands), name);
|
|
317
298
|
const mapErrors = [];
|
|
318
299
|
const getContext = () => {
|
|
319
300
|
mapErrors.length = 0;
|
|
@@ -321,7 +302,7 @@ const _Clerc = class {
|
|
|
321
302
|
const isCommandResolved = !!command;
|
|
322
303
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
323
304
|
const { _: args, flags, unknownFlags } = parsed;
|
|
324
|
-
let parameters =
|
|
305
|
+
let parameters = !isCommandResolved || command.name === SingleCommand ? args : args.slice(command.name.split(" ").length);
|
|
325
306
|
let commandParameters = (command == null ? void 0 : command.parameters) || [];
|
|
326
307
|
const hasEof = commandParameters.indexOf("--");
|
|
327
308
|
const eofParameters = commandParameters.slice(hasEof + 1) || [];
|
|
@@ -351,7 +332,7 @@ const _Clerc = class {
|
|
|
351
332
|
const context = {
|
|
352
333
|
name: command == null ? void 0 : command.name,
|
|
353
334
|
resolved: isCommandResolved,
|
|
354
|
-
|
|
335
|
+
hasSingleCommand: __privateGet(this, _hasSingleCommand),
|
|
355
336
|
raw: { ...parsed, parameters, mergedFlags },
|
|
356
337
|
parameters: mapping,
|
|
357
338
|
flags,
|
|
@@ -393,18 +374,11 @@ _inspectors = new WeakMap();
|
|
|
393
374
|
_commands = new WeakMap();
|
|
394
375
|
_commandEmitter = new WeakMap();
|
|
395
376
|
_usedNames = new WeakMap();
|
|
396
|
-
|
|
397
|
-
isSingleCommand_get = function() {
|
|
398
|
-
return __privateGet(this, _commands)[SingleCommand] !== void 0;
|
|
399
|
-
};
|
|
400
|
-
_hasCommands = new WeakSet();
|
|
401
|
-
hasCommands_get = function() {
|
|
402
|
-
return Object.keys(__privateGet(this, _commands)).length > 0;
|
|
403
|
-
};
|
|
377
|
+
_hasSingleCommand = new WeakMap();
|
|
404
378
|
|
|
405
379
|
const definePlugin = (p) => p;
|
|
406
380
|
const defineHandler = (_cli, _key, handler) => handler;
|
|
407
381
|
const defineInspector = (_cli, inspector) => inspector;
|
|
408
382
|
const defineCommand = (command) => command;
|
|
409
383
|
|
|
410
|
-
export { Clerc, CommandExistsError, CommandNameConflictError,
|
|
384
|
+
export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, SingleCommand, 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.20.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.20.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "puild",
|