@gunshi/bone 0.34.0 → 0.35.1
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.d.ts +22 -3
- package/lib/index.js +53 -29
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
|
|
2
2
|
//#region src/parser.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Entry point of argument parser.
|
|
@@ -55,13 +55,13 @@ interface ArgToken {
|
|
|
55
55
|
* Parser Options.
|
|
56
56
|
*/
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
58
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/resolver.d.ts
|
|
59
59
|
//#region src/resolver.d.ts
|
|
60
60
|
/**
|
|
61
61
|
* An argument schema definition for command-line argument parsing.
|
|
62
62
|
*
|
|
63
63
|
* This schema is similar to the schema of Node.js `util.parseArgs` but with extended features:
|
|
64
|
-
* - Additional `required` and `
|
|
64
|
+
* - Additional `required`, `description`, and `hidden` properties
|
|
65
65
|
* - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom'
|
|
66
66
|
* - Simplified `default` property (single type, not union types)
|
|
67
67
|
*
|
|
@@ -166,6 +166,25 @@ interface ArgSchema {
|
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
168
|
description?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Hide the argument from generated help or usage output.
|
|
171
|
+
*
|
|
172
|
+
* This is metadata for renderers. It does not affect parsing, validation,
|
|
173
|
+
* required checks, defaults, conflicts, or resolved values.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* Hidden compatibility option:
|
|
177
|
+
* ```ts
|
|
178
|
+
* {
|
|
179
|
+
* legacy: {
|
|
180
|
+
* type: 'string',
|
|
181
|
+
* hidden: true,
|
|
182
|
+
* description: 'Deprecated compatibility option'
|
|
183
|
+
* }
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
hidden?: boolean;
|
|
169
188
|
/**
|
|
170
189
|
* Marks the argument as required.
|
|
171
190
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/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)
|
|
@@ -203,7 +203,7 @@ function hasOptionValue(value) {
|
|
|
203
203
|
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
204
204
|
}
|
|
205
205
|
//#endregion
|
|
206
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
206
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/utils.js
|
|
207
207
|
/**
|
|
208
208
|
* Entry point of utils.
|
|
209
209
|
*
|
|
@@ -225,7 +225,7 @@ function kebabnize(str) {
|
|
|
225
225
|
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
226
226
|
}
|
|
227
227
|
//#endregion
|
|
228
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
228
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/resolver.js
|
|
229
229
|
/**
|
|
230
230
|
* Entry point of argument options resolver.
|
|
231
231
|
*
|
|
@@ -387,37 +387,53 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
387
387
|
explicit[rawArg] = false;
|
|
388
388
|
if (schema.type === "positional") {
|
|
389
389
|
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
390
|
-
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
391
|
-
const availablePositionals = Math.max(positionalTokens.length - positionalsCount, 0);
|
|
392
390
|
if (schema.multiple) {
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
391
|
+
const availablePositionals = Math.max(positionalTokens.length - positionalsCount, 0);
|
|
392
|
+
if (availablePositionals > 0) {
|
|
393
|
+
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
394
|
+
const positionalsToConsume = Math.max(availablePositionals - requiredPositionals, 0);
|
|
395
|
+
if (positionalsToConsume > 0) {
|
|
396
|
+
const endPositionals = positionalsCount + positionalsToConsume;
|
|
397
|
+
if (typeof schema.parse === "function") {
|
|
398
|
+
const parsed = [];
|
|
399
|
+
for (let i = positionalsCount; i < endPositionals; i++) {
|
|
400
|
+
const p = positionalTokens[i];
|
|
401
|
+
try {
|
|
402
|
+
parsed.push(schema.parse(p.value));
|
|
403
|
+
} catch (error) {
|
|
404
|
+
errors.push(error);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
values[rawArg] = parsed;
|
|
408
|
+
} else {
|
|
409
|
+
const valuesArray = [];
|
|
410
|
+
for (let i = positionalsCount; i < endPositionals; i++) valuesArray.push(positionalTokens[i].value);
|
|
411
|
+
values[rawArg] = valuesArray;
|
|
402
412
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
explicit[rawArg] = true;
|
|
413
|
+
positionalsCount = endPositionals;
|
|
414
|
+
explicit[rawArg] = true;
|
|
415
|
+
} else if (schema.required) errors.push(createRequireError(arg, schema));
|
|
407
416
|
} else if (schema.required) errors.push(createRequireError(arg, schema));
|
|
408
417
|
} else {
|
|
409
418
|
const positional = positionalTokens[positionalsCount];
|
|
410
|
-
if (
|
|
411
|
-
if (
|
|
412
|
-
values
|
|
413
|
-
|
|
414
|
-
|
|
419
|
+
if (shouldRequireMissingSinglePositional(schema)) {
|
|
420
|
+
if (positional != null) {
|
|
421
|
+
resolveSinglePositionalValue(values, errors, rawArg, schema, positional);
|
|
422
|
+
explicit[rawArg] = true;
|
|
423
|
+
positionalsCount++;
|
|
424
|
+
} else errors.push(createRequireError(arg, schema));
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (positional != null) {
|
|
428
|
+
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
429
|
+
if (Math.max(positionalTokens.length - positionalsCount, 0) > requiredPositionals) {
|
|
430
|
+
resolveSinglePositionalValue(values, errors, rawArg, schema, positional);
|
|
431
|
+
explicit[rawArg] = true;
|
|
432
|
+
positionalsCount++;
|
|
433
|
+
continue;
|
|
415
434
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
positionalsCount++;
|
|
419
|
-
} else if (shouldRequireMissingSinglePositional(schema)) errors.push(createRequireError(arg, schema));
|
|
420
|
-
else if (hasDefault(schema)) values[rawArg] = schema.default;
|
|
435
|
+
}
|
|
436
|
+
if (hasDefault(schema)) values[rawArg] = schema.default;
|
|
421
437
|
}
|
|
422
438
|
continue;
|
|
423
439
|
}
|
|
@@ -486,6 +502,14 @@ function parse(token, option, schema) {
|
|
|
486
502
|
function createRequireError(option, schema) {
|
|
487
503
|
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`, option, "required", schema);
|
|
488
504
|
}
|
|
505
|
+
function resolveSinglePositionalValue(values, errors, rawArg, schema, positional) {
|
|
506
|
+
if (typeof schema.parse === "function") try {
|
|
507
|
+
values[rawArg] = schema.parse(positional.value);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
errors.push(error);
|
|
510
|
+
}
|
|
511
|
+
else values[rawArg] = positional.value;
|
|
512
|
+
}
|
|
489
513
|
function hasDefault(schema) {
|
|
490
514
|
return schema.default != null;
|
|
491
515
|
}
|
|
@@ -559,7 +583,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
|
559
583
|
return [];
|
|
560
584
|
}
|
|
561
585
|
//#endregion
|
|
562
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.
|
|
586
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/index.js
|
|
563
587
|
/**
|
|
564
588
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
565
589
|
* @license MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/bone",
|
|
3
3
|
"description": "gunshi minimum",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.35.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"jsr-exports-lint": "^0.4.2",
|
|
57
57
|
"publint": "^0.3.20",
|
|
58
58
|
"tsdown": "0.21.0",
|
|
59
|
-
"@gunshi/definition": "0.
|
|
60
|
-
"@gunshi/plugin-
|
|
61
|
-
"gunshi": "0.
|
|
62
|
-
"
|
|
59
|
+
"@gunshi/definition": "0.35.1",
|
|
60
|
+
"@gunshi/plugin-global": "0.35.1",
|
|
61
|
+
"@gunshi/plugin-renderer": "0.35.1",
|
|
62
|
+
"gunshi": "0.35.1"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsdown",
|