@gunshi/bone 1.0.0-beta.0 → 1.0.0-beta.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 +5 -29
- package/lib/index.js +47 -7
- package/package.json +6 -6
package/lib/index.d.ts
CHANGED
|
@@ -55,9 +55,6 @@ interface ArgToken {
|
|
|
55
55
|
*/
|
|
56
56
|
inlineValue?: boolean | undefined;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Parser Options.
|
|
60
|
-
*/
|
|
61
58
|
//#endregion
|
|
62
59
|
//#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/resolver.d.ts
|
|
63
60
|
//#region src/resolver.d.ts
|
|
@@ -638,7 +635,7 @@ interface Args {
|
|
|
638
635
|
*
|
|
639
636
|
* @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
|
|
640
637
|
*/
|
|
641
|
-
type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]
|
|
638
|
+
type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]>; }> : {
|
|
642
639
|
[option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
|
|
643
640
|
};
|
|
644
641
|
/**
|
|
@@ -670,7 +667,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
|
|
|
670
667
|
*
|
|
671
668
|
* @internal
|
|
672
669
|
*/
|
|
673
|
-
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg] } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg] } extends (infer P) ? { [K in keyof P]: P[K] } : never;
|
|
670
|
+
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg]; } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg]; } extends (infer P) ? { [K in keyof P]: P[K]; } : never;
|
|
674
671
|
/**
|
|
675
672
|
* Whether an argument with the schema `S` has a value: with a default, with `required: true` or as
|
|
676
673
|
* a required positional argument. For a union of schemas, only when each schema of the union has
|
|
@@ -678,16 +675,6 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
|
|
|
678
675
|
* value, as {@link FilterArgs} does.
|
|
679
676
|
*/
|
|
680
677
|
type IsPresentArg<S extends ArgSchema> = S extends ArgSchema ? true extends (S['default'] extends {} ? true : S['required'] extends true ? true : false) ? true : IsRequiredPositionalArg<S> : never;
|
|
681
|
-
/**
|
|
682
|
-
* Filters the arguments based on their default values.
|
|
683
|
-
*
|
|
684
|
-
* @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
|
|
685
|
-
* @typeParam V - Resolvable argument values.
|
|
686
|
-
* @typeParam K - Key of the {@link ArgSchema | argument schema} to filter by.
|
|
687
|
-
*
|
|
688
|
-
* @internal
|
|
689
|
-
*/
|
|
690
|
-
|
|
691
678
|
type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : MayBeUnrequired<A> extends true ? A['default'] extends {} ? true : false : true : false;
|
|
692
679
|
/**
|
|
693
680
|
* Whether the `required` of `A` may be `false`. An optional `required` of type `boolean`, as in
|
|
@@ -698,10 +685,6 @@ type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positiona
|
|
|
698
685
|
type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] extends [{
|
|
699
686
|
required: unknown;
|
|
700
687
|
}] ? true : boolean | undefined extends A['required'] ? false : true : false;
|
|
701
|
-
/**
|
|
702
|
-
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
703
|
-
*/
|
|
704
|
-
|
|
705
688
|
/**
|
|
706
689
|
* Tracks which arguments were explicitly provided by the user.
|
|
707
690
|
*
|
|
@@ -714,7 +697,7 @@ type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] ex
|
|
|
714
697
|
*
|
|
715
698
|
* @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
|
|
716
699
|
*/
|
|
717
|
-
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
700
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean; };
|
|
718
701
|
//#endregion
|
|
719
702
|
//#region ../gunshi/src/plugin/context.d.ts
|
|
720
703
|
/**
|
|
@@ -848,7 +831,7 @@ type Awaitable<T> = T | Promise<T>;
|
|
|
848
831
|
*
|
|
849
832
|
* @typeParam T - The type to be prettified.
|
|
850
833
|
*/
|
|
851
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
834
|
+
type Prettify<T> = { [K in keyof T]: T[K]; } & {};
|
|
852
835
|
/**
|
|
853
836
|
* Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
|
|
854
837
|
*
|
|
@@ -1649,11 +1632,4 @@ declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiPa
|
|
|
1649
1632
|
*/
|
|
1650
1633
|
declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
1651
1634
|
//#endregion
|
|
1652
|
-
|
|
1653
|
-
/**
|
|
1654
|
-
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
1655
|
-
* @license MIT
|
|
1656
|
-
*/
|
|
1657
|
-
|
|
1658
|
-
//#endregion
|
|
1659
|
-
export { type ArgSchema, type ArgToken, type ArgValues, type Args, Awaitable, CliOptions, Command, CommandCallMode, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandRunner, Commandable, DefaultGunshiParams, ExtendContext, ExtractArgExplicitlyProvided, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, MergeGunshiExtensions, NormalizeToGunshiParams, Prettify, RendererDecorator, RenderingOptions, SubCommandable, ValidationErrorsDecorator, cli };
|
|
1635
|
+
export { type ArgSchema, type ArgToken, type ArgValues, type Args, type Awaitable, type CliOptions, type Command, type CommandCallMode, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandDecorator, type CommandEnvironment, type CommandExamplesFetcher, type CommandLoader, type CommandRunner, type Commandable, type DefaultGunshiParams, type ExtendContext, type ExtractArgExplicitlyProvided, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, type MergeGunshiExtensions, type NormalizeToGunshiParams, type Prettify, type RendererDecorator, type RenderingOptions, type SubCommandable, type ValidationErrorsDecorator, cli };
|
package/lib/index.js
CHANGED
|
@@ -1868,7 +1868,7 @@ async function cliCore(argv, entry, options, plugins, usageOnly = false) {
|
|
|
1868
1868
|
* the merge, so the core says which ones are in effect for this command (#745).
|
|
1869
1869
|
*/
|
|
1870
1870
|
cliOptions.globalOptions = resolveEffectiveGlobalOptions(pluginContext.globalOptions, commandArgs, args);
|
|
1871
|
-
const skipPositional =
|
|
1871
|
+
const skipPositional = resolveSkipPositional(tokens, pluginContext.globalOptions, resolvedCommand, targetDepth);
|
|
1872
1872
|
const diagnostic = selection.diagnostic === true;
|
|
1873
1873
|
const { explicit, values, positionals, rest, error } = diagnostic ? {
|
|
1874
1874
|
explicit: create(),
|
|
@@ -2289,6 +2289,25 @@ function getEntryRoutingCommand(entry, options) {
|
|
|
2289
2289
|
return entry;
|
|
2290
2290
|
}
|
|
2291
2291
|
function getRoutingPositionals(tokens, globalOptions, command) {
|
|
2292
|
+
/**
|
|
2293
|
+
* NOTE(kazupon): an empty argument is never a command name. `getPositionalTokens()` skips it when it
|
|
2294
|
+
* collects the candidates, and the routing of each candidate must skip it too; otherwise the routing
|
|
2295
|
+
* looks for a sub-command named `''`, and fails with `inconsistent-options` (#781).
|
|
2296
|
+
*/
|
|
2297
|
+
return readPositionals(tokens, globalOptions, command).filter((value) => value !== "");
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Read the positional arguments as `resolveArgs()` reads them for a command, empty ones included.
|
|
2301
|
+
*
|
|
2302
|
+
* The schemas are projected down to the metadata that classifies the tokens, so no code of the user,
|
|
2303
|
+
* such as `parse`, runs.
|
|
2304
|
+
*
|
|
2305
|
+
* @param tokens - Tokenized command-line arguments
|
|
2306
|
+
* @param globalOptions - Global option schemas
|
|
2307
|
+
* @param command - The command whose arguments classify the tokens
|
|
2308
|
+
* @returns The positional arguments, in the order that `skipPositional` of args-tokens counts them
|
|
2309
|
+
*/
|
|
2310
|
+
function readPositionals(tokens, globalOptions, command) {
|
|
2292
2311
|
const effective = resolveCommandArgs(globalOptions, getCommandArgs(command));
|
|
2293
2312
|
const routingArgs = create();
|
|
2294
2313
|
for (const [name, schema] of Object.entries(effective)) {
|
|
@@ -2300,15 +2319,36 @@ function getRoutingPositionals(tokens, globalOptions, command) {
|
|
|
2300
2319
|
toKebab: schema.toKebab
|
|
2301
2320
|
};
|
|
2302
2321
|
}
|
|
2303
|
-
/**
|
|
2304
|
-
* NOTE(kazupon): an empty argument is never a command name. `getPositionalTokens()` skips it when it
|
|
2305
|
-
* collects the candidates, and the routing of each candidate must skip it too; otherwise the routing
|
|
2306
|
-
* looks for a sub-command named `''`, and fails with `inconsistent-options` (#781).
|
|
2307
|
-
*/
|
|
2308
2322
|
return resolveArgs(routingArgs, tokens, {
|
|
2309
2323
|
shortGrouping: true,
|
|
2310
2324
|
toKebab: command.toKebab
|
|
2311
|
-
}).positionals
|
|
2325
|
+
}).positionals;
|
|
2326
|
+
}
|
|
2327
|
+
/**
|
|
2328
|
+
* Resolve `skipPositional` of args-tokens: the index of the last positional argument to skip.
|
|
2329
|
+
*
|
|
2330
|
+
* NOTE(kazupon): the command names are the first positional arguments that are not empty, and the
|
|
2331
|
+
* last one is at `depth - 1` only when no empty argument comes before it. `skipPositional` counts every
|
|
2332
|
+
* positional argument, the empty ones too, so `app '' build x` gave `build` to the first positional
|
|
2333
|
+
* argument of `build` (#793). The index is found in the reading of `resolveArgs()`, in which the values
|
|
2334
|
+
* of the options are already taken out, so that an empty value of an option is not counted.
|
|
2335
|
+
*
|
|
2336
|
+
* @param tokens - Tokenized command-line arguments
|
|
2337
|
+
* @param globalOptions - Global option schemas
|
|
2338
|
+
* @param command - The command whose arguments are resolved
|
|
2339
|
+
* @param depth - The number of command names
|
|
2340
|
+
* @returns The index of the last command name among the positional arguments, or `-1` for the entry
|
|
2341
|
+
*/
|
|
2342
|
+
function resolveSkipPositional(tokens, globalOptions, command, depth) {
|
|
2343
|
+
if (depth === 0) return -1;
|
|
2344
|
+
if (!tokens.some((token) => token.kind === "positional" && token.value === "")) return depth - 1;
|
|
2345
|
+
let names = 0;
|
|
2346
|
+
for (const [index, value] of readPositionals(tokens, globalOptions, command).entries()) {
|
|
2347
|
+
if (value === "") continue;
|
|
2348
|
+
names++;
|
|
2349
|
+
if (names === depth) return index;
|
|
2350
|
+
}
|
|
2351
|
+
return depth - 1;
|
|
2312
2352
|
}
|
|
2313
2353
|
function sameCommandPath(left, right) {
|
|
2314
2354
|
return left.length === right.length && left.every((name, index) => name === right[index]);
|
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-beta.
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
+
"@gunshi/definition": "1.0.0-beta.1",
|
|
55
|
+
"@gunshi/plugin-global": "1.0.0-beta.1",
|
|
56
|
+
"@gunshi/plugin-renderer": "1.0.0-beta.1",
|
|
54
57
|
"deno": "^2.7.14",
|
|
58
|
+
"gunshi": "1.0.0-beta.1",
|
|
55
59
|
"jsr": "^0.14.3",
|
|
56
60
|
"jsr-exports-lint": "^0.4.2",
|
|
57
61
|
"publint": "^0.3.20",
|
|
58
|
-
"tsdown": "0.
|
|
59
|
-
"@gunshi/definition": "1.0.0-beta.0",
|
|
60
|
-
"@gunshi/plugin-global": "1.0.0-beta.0",
|
|
61
|
-
"@gunshi/plugin-renderer": "1.0.0-beta.0",
|
|
62
|
-
"gunshi": "1.0.0-beta.0"
|
|
62
|
+
"tsdown": "0.22.14"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsdown",
|