@clerc/core 0.12.5 → 0.13.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 +1 -1
- package/dist/index.js +14 -10
- package/dist/index.mjs +14 -10
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -338,6 +338,6 @@ interface ParsedParameter {
|
|
|
338
338
|
spread: boolean;
|
|
339
339
|
}
|
|
340
340
|
declare function parseParameters(parameters: string[]): ParsedParameter[];
|
|
341
|
-
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): undefined;
|
|
341
|
+
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): Error | undefined;
|
|
342
342
|
|
|
343
343
|
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandWithHandler, CommonCommandExistsError, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, MakeEventMap, MultipleCommandsMatchedError, NameNotSetError, NoSuchCommandError, ParentCommandExistsError, Plugin, PossibleInputKind, SingleCommand, SingleCommandAliasError, SingleCommandError, SingleCommandType, SubcommandExistsError, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
|
package/dist/index.js
CHANGED
|
@@ -187,16 +187,14 @@ function mapParametersToArguments(mapping, parameters, cliArguments) {
|
|
|
187
187
|
const { name, required, spread } = parameters[i];
|
|
188
188
|
const camelCaseName = camelCase(name);
|
|
189
189
|
if (camelCaseName in mapping) {
|
|
190
|
-
|
|
190
|
+
return new Error(`Invalid parameter: ${stringify(name)} is used more than once.`);
|
|
191
191
|
}
|
|
192
192
|
const value = spread ? cliArguments.slice(i) : cliArguments[i];
|
|
193
193
|
if (spread) {
|
|
194
194
|
i = parameters.length;
|
|
195
195
|
}
|
|
196
196
|
if (required && (!value || spread && value.length === 0)) {
|
|
197
|
-
|
|
198
|
-
`);
|
|
199
|
-
return process.exit(1);
|
|
197
|
+
return new Error(`Error: Missing required parameter ${stringify(name)}`);
|
|
200
198
|
}
|
|
201
199
|
mapping[camelCaseName] = value;
|
|
202
200
|
}
|
|
@@ -322,7 +320,9 @@ const _Clerc = class {
|
|
|
322
320
|
const name = resolveParametersBeforeFlag(argv, __privateGet(this, _isSingleCommand, isSingleCommand_get));
|
|
323
321
|
const stringName = name.join(" ");
|
|
324
322
|
const getCommand = () => __privateGet(this, _isSingleCommand, isSingleCommand_get) ? __privateGet(this, _commands)[SingleCommand] : resolveCommand(__privateGet(this, _commands), name);
|
|
323
|
+
const mapErrors = [];
|
|
325
324
|
const getContext = () => {
|
|
325
|
+
mapErrors.length = 0;
|
|
326
326
|
const command = getCommand();
|
|
327
327
|
const isCommandResolved = !!command;
|
|
328
328
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
@@ -336,22 +336,22 @@ const _Clerc = class {
|
|
|
336
336
|
commandParameters = commandParameters.slice(0, hasEof);
|
|
337
337
|
const eofArguments = parsed._["--"];
|
|
338
338
|
parameters = parameters.slice(0, -eofArguments.length || void 0);
|
|
339
|
-
mapParametersToArguments(
|
|
339
|
+
mapErrors.push(mapParametersToArguments(
|
|
340
340
|
mapping,
|
|
341
341
|
parseParameters(commandParameters),
|
|
342
342
|
parameters
|
|
343
|
-
);
|
|
344
|
-
mapParametersToArguments(
|
|
343
|
+
));
|
|
344
|
+
mapErrors.push(mapParametersToArguments(
|
|
345
345
|
mapping,
|
|
346
346
|
parseParameters(eofParameters),
|
|
347
347
|
eofArguments
|
|
348
|
-
);
|
|
348
|
+
));
|
|
349
349
|
} else {
|
|
350
|
-
mapParametersToArguments(
|
|
350
|
+
mapErrors.push(mapParametersToArguments(
|
|
351
351
|
mapping,
|
|
352
352
|
parseParameters(commandParameters),
|
|
353
353
|
parameters
|
|
354
|
-
);
|
|
354
|
+
));
|
|
355
355
|
}
|
|
356
356
|
const mergedFlags = { ...parsed.flags, ...parsed.unknownFlags };
|
|
357
357
|
const context = {
|
|
@@ -371,6 +371,10 @@ const _Clerc = class {
|
|
|
371
371
|
fn: () => {
|
|
372
372
|
const command = getCommand();
|
|
373
373
|
const handlerContext = getContext();
|
|
374
|
+
const errors = mapErrors.filter(Boolean);
|
|
375
|
+
if (errors.length > 0) {
|
|
376
|
+
throw errors[0];
|
|
377
|
+
}
|
|
374
378
|
if (!command) {
|
|
375
379
|
throw new NoSuchCommandError(stringName);
|
|
376
380
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -187,16 +187,14 @@ function mapParametersToArguments(mapping, parameters, cliArguments) {
|
|
|
187
187
|
const { name, required, spread } = parameters[i];
|
|
188
188
|
const camelCaseName = camelCase(name);
|
|
189
189
|
if (camelCaseName in mapping) {
|
|
190
|
-
|
|
190
|
+
return new Error(`Invalid parameter: ${stringify(name)} is used more than once.`);
|
|
191
191
|
}
|
|
192
192
|
const value = spread ? cliArguments.slice(i) : cliArguments[i];
|
|
193
193
|
if (spread) {
|
|
194
194
|
i = parameters.length;
|
|
195
195
|
}
|
|
196
196
|
if (required && (!value || spread && value.length === 0)) {
|
|
197
|
-
|
|
198
|
-
`);
|
|
199
|
-
return process.exit(1);
|
|
197
|
+
return new Error(`Error: Missing required parameter ${stringify(name)}`);
|
|
200
198
|
}
|
|
201
199
|
mapping[camelCaseName] = value;
|
|
202
200
|
}
|
|
@@ -322,7 +320,9 @@ const _Clerc = class {
|
|
|
322
320
|
const name = resolveParametersBeforeFlag(argv, __privateGet(this, _isSingleCommand, isSingleCommand_get));
|
|
323
321
|
const stringName = name.join(" ");
|
|
324
322
|
const getCommand = () => __privateGet(this, _isSingleCommand, isSingleCommand_get) ? __privateGet(this, _commands)[SingleCommand] : resolveCommand(__privateGet(this, _commands), name);
|
|
323
|
+
const mapErrors = [];
|
|
325
324
|
const getContext = () => {
|
|
325
|
+
mapErrors.length = 0;
|
|
326
326
|
const command = getCommand();
|
|
327
327
|
const isCommandResolved = !!command;
|
|
328
328
|
const parsed = typeFlag((command == null ? void 0 : command.flags) || {}, [...argv]);
|
|
@@ -336,22 +336,22 @@ const _Clerc = class {
|
|
|
336
336
|
commandParameters = commandParameters.slice(0, hasEof);
|
|
337
337
|
const eofArguments = parsed._["--"];
|
|
338
338
|
parameters = parameters.slice(0, -eofArguments.length || void 0);
|
|
339
|
-
mapParametersToArguments(
|
|
339
|
+
mapErrors.push(mapParametersToArguments(
|
|
340
340
|
mapping,
|
|
341
341
|
parseParameters(commandParameters),
|
|
342
342
|
parameters
|
|
343
|
-
);
|
|
344
|
-
mapParametersToArguments(
|
|
343
|
+
));
|
|
344
|
+
mapErrors.push(mapParametersToArguments(
|
|
345
345
|
mapping,
|
|
346
346
|
parseParameters(eofParameters),
|
|
347
347
|
eofArguments
|
|
348
|
-
);
|
|
348
|
+
));
|
|
349
349
|
} else {
|
|
350
|
-
mapParametersToArguments(
|
|
350
|
+
mapErrors.push(mapParametersToArguments(
|
|
351
351
|
mapping,
|
|
352
352
|
parseParameters(commandParameters),
|
|
353
353
|
parameters
|
|
354
|
-
);
|
|
354
|
+
));
|
|
355
355
|
}
|
|
356
356
|
const mergedFlags = { ...parsed.flags, ...parsed.unknownFlags };
|
|
357
357
|
const context = {
|
|
@@ -371,6 +371,10 @@ const _Clerc = class {
|
|
|
371
371
|
fn: () => {
|
|
372
372
|
const command = getCommand();
|
|
373
373
|
const handlerContext = getContext();
|
|
374
|
+
const errors = mapErrors.filter(Boolean);
|
|
375
|
+
if (errors.length > 0) {
|
|
376
|
+
throw errors[0];
|
|
377
|
+
}
|
|
374
378
|
if (!command) {
|
|
375
379
|
throw new NoSuchCommandError(stringName);
|
|
376
380
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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.13.0"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "puild",
|