@gunshi/bone 1.0.0-rc.3 → 1.0.0-rc.5
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/README.md +0 -6
- package/lib/index.d.ts +14 -14
- package/lib/index.js +27 -16
- package/package.json +6 -11
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[![Version][npm-version-src]][npm-version-href]
|
|
4
4
|
[![InstallSize][install-size-src]][install-size-src]
|
|
5
|
-
[![JSR][jsr-src]][jsr-href]
|
|
6
5
|
|
|
7
6
|
> gunshi minimum
|
|
8
7
|
|
|
@@ -35,9 +34,6 @@ pnpm add @gunshi/bone
|
|
|
35
34
|
## yarn
|
|
36
35
|
yarn add @gunshi/bone
|
|
37
36
|
|
|
38
|
-
## deno
|
|
39
|
-
deno add jsr:@gunshi/bone
|
|
40
|
-
|
|
41
37
|
## bun
|
|
42
38
|
bun add @gunshi/bone
|
|
43
39
|
```
|
|
@@ -74,6 +70,4 @@ await cli(process.argv.slice(2), entry, {
|
|
|
74
70
|
|
|
75
71
|
[npm-version-src]: https://img.shields.io/npm/v/@gunshi/bone?style=flat
|
|
76
72
|
[npm-version-href]: https://npmjs.com/package/@gunshi/bone@alpha
|
|
77
|
-
[jsr-src]: https://jsr.io/badges/@gunshi/bone
|
|
78
|
-
[jsr-href]: https://jsr.io/@gunshi/bone
|
|
79
73
|
[install-size-src]: https://pkg-size.dev/badge/install/57026
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
2
|
-
//#region src/parser.d.ts
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/parser-DvPxBZG9.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Entry point of argument parser.
|
|
5
4
|
*
|
|
@@ -56,8 +55,7 @@ interface ArgToken {
|
|
|
56
55
|
inlineValue?: boolean | undefined;
|
|
57
56
|
}
|
|
58
57
|
//#endregion
|
|
59
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
60
|
-
//#region src/resolver.d.ts
|
|
58
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/resolver.d.ts
|
|
61
59
|
/**
|
|
62
60
|
* An argument schema definition for command-line argument parsing.
|
|
63
61
|
*
|
|
@@ -419,9 +417,9 @@ interface ArgSchema {
|
|
|
419
417
|
*/
|
|
420
418
|
toKebab?: true;
|
|
421
419
|
/**
|
|
422
|
-
* Names of other
|
|
420
|
+
* Names of other arguments that conflict with this argument.
|
|
423
421
|
*
|
|
424
|
-
* When this
|
|
422
|
+
* When this argument is used together with any of the conflicting arguments, the error is an
|
|
425
423
|
* `ArgResolveError` with type 'conflict' and the code `err:arg:conflict`
|
|
426
424
|
* ({@link ArgsValidationErrorKeys}.conflict). Its `values` has the `displayName` and `name` of
|
|
427
425
|
* the argument whose `conflicts` names the other one, and the `conflictDisplayName` and
|
|
@@ -431,9 +429,8 @@ interface ArgSchema {
|
|
|
431
429
|
*
|
|
432
430
|
* A positional argument can be on either side, such as `[file]` and `--stdin`. It conflicts when
|
|
433
431
|
* it is given, and it is shown by its name, such as `'file'` (in kebab-case with `toKebab`), as
|
|
434
|
-
* in its other errors. The message
|
|
435
|
-
* `
|
|
436
|
-
* `Optional argument '--stdin' conflicts with 'file'`.
|
|
432
|
+
* in its other errors. The message names the argument given as `name` first:
|
|
433
|
+
* `'file' conflicts with '--stdin'` or `'--stdin' conflicts with 'file'`.
|
|
437
434
|
*
|
|
438
435
|
* Conflicts only need to be defined on one side - if option A defines a conflict
|
|
439
436
|
* with option B, the conflict is automatically detected when both are used,
|
|
@@ -472,7 +469,7 @@ interface ArgSchema {
|
|
|
472
469
|
* }
|
|
473
470
|
* }
|
|
474
471
|
* // Usage: --summer --autumn reports an error
|
|
475
|
-
* // Error: "
|
|
472
|
+
* // Error: "'--summer' conflicts with '--autumn'"
|
|
476
473
|
* ```
|
|
477
474
|
*
|
|
478
475
|
* @example
|
|
@@ -512,7 +509,7 @@ interface ArgSchema {
|
|
|
512
509
|
* toKebab: true // Accessible as --autumn-season
|
|
513
510
|
* }
|
|
514
511
|
* }
|
|
515
|
-
* // Error: "
|
|
512
|
+
* // Error: "'--summer-season' conflicts with '--autumn-season'"
|
|
516
513
|
* ```
|
|
517
514
|
*/
|
|
518
515
|
conflicts?: string | string[];
|
|
@@ -1615,7 +1612,8 @@ type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiP
|
|
|
1615
1612
|
//#endregion
|
|
1616
1613
|
//#region ../gunshi/src/cli/bone.d.ts
|
|
1617
1614
|
/**
|
|
1618
|
-
* Run the command.
|
|
1615
|
+
* Run the command, without the built-in plugins: `--help` and `--version` print nothing, unless you add the plugins.
|
|
1616
|
+
* To have them, use `cli` from `gunshi`.
|
|
1619
1617
|
*
|
|
1620
1618
|
* @typeParam A - The type of {@linkcode Args | arguments} defined in the command and cli options.
|
|
1621
1619
|
*
|
|
@@ -1629,7 +1627,8 @@ declare function cli<A extends Args = Args, G extends GunshiParams = {
|
|
|
1629
1627
|
extensions: {};
|
|
1630
1628
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1631
1629
|
/**
|
|
1632
|
-
* Run the command.
|
|
1630
|
+
* Run the command, without the built-in plugins: `--help` and `--version` print nothing, unless you add the plugins.
|
|
1631
|
+
* To have them, use `cli` from `gunshi`.
|
|
1633
1632
|
*
|
|
1634
1633
|
* @typeParam E - An {@linkcode ExtendContext} type to specify the shape of command and cli options.
|
|
1635
1634
|
*
|
|
@@ -1643,7 +1642,8 @@ declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiPa
|
|
|
1643
1642
|
extensions: E;
|
|
1644
1643
|
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1645
1644
|
/**
|
|
1646
|
-
* Run the command.
|
|
1645
|
+
* Run the command, without the built-in plugins: `--help` and `--version` print nothing, unless you add the plugins.
|
|
1646
|
+
* To have them, use `cli` from `gunshi`.
|
|
1647
1647
|
*
|
|
1648
1648
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
1649
1649
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/parser.js
|
|
2
2
|
/**
|
|
3
3
|
* forked from `nodejs/node` (`pkgjs/parseargs`)
|
|
4
4
|
* repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
|
|
@@ -201,7 +201,7 @@ function hasLongOptionPrefix(arg) {
|
|
|
201
201
|
return arg.startsWith(LONG_OPTION_PREFIX) && arg.length > 2;
|
|
202
202
|
}
|
|
203
203
|
//#endregion
|
|
204
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
204
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/utils.js
|
|
205
205
|
/**
|
|
206
206
|
* Entry point of utils.
|
|
207
207
|
*
|
|
@@ -232,7 +232,7 @@ function formatChoices(choices) {
|
|
|
232
232
|
return choices.map((value) => JSON.stringify(value)).join(", ");
|
|
233
233
|
}
|
|
234
234
|
//#endregion
|
|
235
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
235
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/resolver-Cx5Pw6-S.js
|
|
236
236
|
/**
|
|
237
237
|
* Internal definitions shared by the modules of `args-tokens`.
|
|
238
238
|
*
|
|
@@ -718,7 +718,7 @@ function parseSchemaValue(value, rawArg, option, schema) {
|
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
720
|
function createRequireError(rawArg, option, schema) {
|
|
721
|
-
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `
|
|
721
|
+
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Option ${createOptionDisplayName(option, schema)} is required`, option, "required", schema, {
|
|
722
722
|
code: schema.type === "positional" ? ArgsValidationErrorKeys.requiredPositional : ArgsValidationErrorKeys.requiredOption,
|
|
723
723
|
values: schema.type === "positional" ? {
|
|
724
724
|
displayName: createArgumentDisplayName(option, schema),
|
|
@@ -840,7 +840,7 @@ function isNumeric(str) {
|
|
|
840
840
|
return str.trim() !== "" && !isNaN(str);
|
|
841
841
|
}
|
|
842
842
|
function createTypeError(rawArg, option, schema, actual, expected = schema.type) {
|
|
843
|
-
return new ArgResolveError(`
|
|
843
|
+
return new ArgResolveError(`Invalid value for ${createOptionDisplayName(option, schema)}: expected ${expected}`, option, "type", schema, {
|
|
844
844
|
code: ArgsValidationErrorKeys.invalidType,
|
|
845
845
|
values: {
|
|
846
846
|
displayName: createOptionDisplayName(option, schema),
|
|
@@ -870,7 +870,7 @@ function createMissingValueError(rawArg, option, schema, next) {
|
|
|
870
870
|
const suggestion = next === void 0 || !acceptsSuggestedValue(schema, next) ? void 0 : `--${option}=${next}`;
|
|
871
871
|
const hint = suggestion === void 0 ? "" : ` (to pass '${next}' as its value, write '${suggestion}')`;
|
|
872
872
|
const choices = schema.choices ?? [];
|
|
873
|
-
return new ArgResolveError(`
|
|
873
|
+
return new ArgResolveError(`Option ${displayName} requires a value${hint}`, option, "type", schema, {
|
|
874
874
|
code: ArgsValidationErrorKeys.missingValue,
|
|
875
875
|
values: {
|
|
876
876
|
displayName,
|
|
@@ -989,7 +989,7 @@ function hasPureParseBrand(parse) {
|
|
|
989
989
|
function createUnexpectedValueError(rawArg, option, schema, token) {
|
|
990
990
|
const rawName = token.rawName;
|
|
991
991
|
const displayName = `'${rawName}'`;
|
|
992
|
-
return new ArgResolveError(`
|
|
992
|
+
return new ArgResolveError(`Option ${displayName} does not take a value`, option, "type", schema, {
|
|
993
993
|
code: ArgsValidationErrorKeys.unexpectedValue,
|
|
994
994
|
values: {
|
|
995
995
|
displayName,
|
|
@@ -1001,7 +1001,7 @@ function createUnexpectedValueError(rawArg, option, schema, token) {
|
|
|
1001
1001
|
}
|
|
1002
1002
|
function createChoiceError(rawArg, option, schema, actual) {
|
|
1003
1003
|
const choices = schema.choices ?? [];
|
|
1004
|
-
return new ArgResolveError(`
|
|
1004
|
+
return new ArgResolveError(`Invalid value for ${createOptionDisplayName(option, schema)}: expected one of ${formatChoices(choices)}`, option, "type", schema, {
|
|
1005
1005
|
code: ArgsValidationErrorKeys.invalidChoice,
|
|
1006
1006
|
values: {
|
|
1007
1007
|
displayName: createOptionDisplayName(option, schema),
|
|
@@ -1027,7 +1027,7 @@ function createChoiceError(rawArg, option, schema, actual) {
|
|
|
1027
1027
|
function createDefaultChoiceError(rawArg, option, schema) {
|
|
1028
1028
|
const choices = schema.choices ?? [];
|
|
1029
1029
|
const displayName = createOptionDisplayName(option, schema);
|
|
1030
|
-
return new ArgResolveError(`
|
|
1030
|
+
return new ArgResolveError(`Invalid default for ${displayName}: ${typeof schema.default === "string" ? JSON.stringify(schema.default) : String(schema.default)} is not one of ${formatChoices(choices)}`, option, "type", schema, {
|
|
1031
1031
|
code: ArgsValidationErrorKeys.invalidDefault,
|
|
1032
1032
|
values: {
|
|
1033
1033
|
displayName,
|
|
@@ -1043,10 +1043,11 @@ function createCustomParseError(error, rawArg, option, schema, value) {
|
|
|
1043
1043
|
const reused = reuseValidationError(error, rawArg, option, schema, value);
|
|
1044
1044
|
if (reused) return reused;
|
|
1045
1045
|
const reason = getErrorReason(error);
|
|
1046
|
-
|
|
1046
|
+
const displayName = createArgumentDisplayName(option, schema);
|
|
1047
|
+
return new ArgsValidationError(`Invalid value for ${displayName}: ${reason}`, {
|
|
1047
1048
|
code: ArgsValidationErrorKeys.customParse,
|
|
1048
1049
|
values: {
|
|
1049
|
-
displayName
|
|
1050
|
+
displayName,
|
|
1050
1051
|
name: rawArg,
|
|
1051
1052
|
reason
|
|
1052
1053
|
},
|
|
@@ -1056,6 +1057,11 @@ function createCustomParseError(error, rawArg, option, schema, value) {
|
|
|
1056
1057
|
/**
|
|
1057
1058
|
* Reuse an {@link ArgsValidationError} thrown from a custom `parse` function, filling in missing values.
|
|
1058
1059
|
*
|
|
1060
|
+
* An error with no `displayName` in its `values`, such as one thrown by the combinators, gets the
|
|
1061
|
+
* argument before its message, as a custom parse error does:
|
|
1062
|
+
* `Invalid value for '--port': Expected an integer, got 'abc'`. An error that names its argument keeps
|
|
1063
|
+
* its message.
|
|
1064
|
+
*
|
|
1059
1065
|
* @param error - The value thrown from `parse`
|
|
1060
1066
|
* @param rawArg - The argument key in the schema
|
|
1061
1067
|
* @param option - The option name used on the command line
|
|
@@ -1075,9 +1081,13 @@ function reuseValidationError(error, rawArg, option, schema, value) {
|
|
|
1075
1081
|
}
|
|
1076
1082
|
function augmentValidationError(error, rawArg, option, schema, value) {
|
|
1077
1083
|
const values = error.values;
|
|
1084
|
+
const named = values.displayName != null;
|
|
1078
1085
|
values.name ??= rawArg;
|
|
1079
1086
|
values.displayName ??= createArgumentDisplayName(option, schema);
|
|
1080
1087
|
if ((error.code === ArgsValidationErrorKeys.invalidType || error.code === ArgsValidationErrorKeys.invalidChoice) && values.actual == null) values.actual = value;
|
|
1088
|
+
if (!named) try {
|
|
1089
|
+
error.message = `Invalid value for ${String(values.displayName)}: ${error.message}`;
|
|
1090
|
+
} catch {}
|
|
1081
1091
|
}
|
|
1082
1092
|
function getErrorReason(error) {
|
|
1083
1093
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -1092,8 +1102,8 @@ function createOptionDisplayName(option, schema) {
|
|
|
1092
1102
|
* Create the error for two arguments that conflict.
|
|
1093
1103
|
*
|
|
1094
1104
|
* An option is shown as it was written, such as `'-p'` or `'--no-color'`, and a positional argument
|
|
1095
|
-
* by its name, such as `'file'`, as in the message. The message
|
|
1096
|
-
*
|
|
1105
|
+
* by its name, such as `'file'`, as in the message. The message names first the argument whose
|
|
1106
|
+
* `conflicts` names the other one.
|
|
1097
1107
|
*
|
|
1098
1108
|
* @param rawArg - The argument key of the argument whose `conflicts` names the other one
|
|
1099
1109
|
* @param option - The name of that argument used on the command line
|
|
@@ -1107,7 +1117,7 @@ function createOptionDisplayName(option, schema) {
|
|
|
1107
1117
|
function createConflictError(rawArg, option, schema, actualName, conflictingArg, conflictingActualName) {
|
|
1108
1118
|
const displayName = `'${actualName}'`;
|
|
1109
1119
|
const conflictDisplayName = `'${conflictingActualName}'`;
|
|
1110
|
-
return new ArgResolveError(`${
|
|
1120
|
+
return new ArgResolveError(`${displayName} conflicts with ${conflictDisplayName}`, option, "conflict", schema, {
|
|
1111
1121
|
code: ArgsValidationErrorKeys.conflict,
|
|
1112
1122
|
values: {
|
|
1113
1123
|
displayName,
|
|
@@ -1134,7 +1144,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
|
1134
1144
|
return [];
|
|
1135
1145
|
}
|
|
1136
1146
|
//#endregion
|
|
1137
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.
|
|
1147
|
+
//#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/index.js
|
|
1138
1148
|
/**
|
|
1139
1149
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
1140
1150
|
* @license MIT
|
|
@@ -2548,7 +2558,8 @@ async function executeCommand(cmd, ctx, decorators) {
|
|
|
2548
2558
|
* @license MIT
|
|
2549
2559
|
*/
|
|
2550
2560
|
/**
|
|
2551
|
-
* Run the command.
|
|
2561
|
+
* Run the command, without the built-in plugins: `--help` and `--version` print nothing, unless you add the plugins.
|
|
2562
|
+
* To have them, use `cli` from `gunshi`.
|
|
2552
2563
|
*
|
|
2553
2564
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
2554
2565
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/bone",
|
|
3
3
|
"description": "gunshi minimum",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -51,19 +51,14 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@gunshi/definition": "1.0.0-rc.
|
|
55
|
-
"@gunshi/plugin-global": "1.0.0-rc.
|
|
56
|
-
"@gunshi/plugin-renderer": "1.0.0-rc.
|
|
57
|
-
"
|
|
58
|
-
"gunshi": "1.0.0-rc.3",
|
|
59
|
-
"jsr": "^0.14.3",
|
|
60
|
-
"jsr-exports-lint": "^0.4.2",
|
|
54
|
+
"@gunshi/definition": "1.0.0-rc.5",
|
|
55
|
+
"@gunshi/plugin-global": "1.0.0-rc.5",
|
|
56
|
+
"@gunshi/plugin-renderer": "1.0.0-rc.5",
|
|
57
|
+
"gunshi": "1.0.0-rc.5",
|
|
61
58
|
"publint": "^0.3.20",
|
|
62
59
|
"tsdown": "0.22.14"
|
|
63
60
|
},
|
|
64
61
|
"scripts": {
|
|
65
|
-
"build": "tsdown"
|
|
66
|
-
"lint:jsr": "jsr publish --dry-run --allow-dirty",
|
|
67
|
-
"typecheck:deno": "deno check --import-map=../../importmap.json ./src"
|
|
62
|
+
"build": "tsdown"
|
|
68
63
|
}
|
|
69
64
|
}
|