gunshi 0.14.5 → 0.15.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/lib/{cli-JT5dcEoE.js → cli--6qYDY8U.js} +10 -3
- package/lib/{definition.d-TBObezo_.d.ts → definition.d-DD_GraLw.d.ts} +1 -1
- package/lib/definition.d.ts +2 -2
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +2 -2
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/locales/en-US.json +1 -0
- package/lib/locales/ja-JP.json +1 -0
- package/lib/{renderer-DGPRTLmr.js → renderer-BeuJazdk.js} +20 -5
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +1 -1
- package/lib/{types.d-GVRYnEFw.d.ts → types.d-zAq1WIpD.d.ts} +11 -4
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey } from "./renderer-
|
|
1
|
+
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey } from "./renderer-BeuJazdk.js";
|
|
2
2
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
3
3
|
|
|
4
4
|
//#region src/locales/en-US.json
|
|
@@ -9,6 +9,7 @@ var USAGE = "USAGE";
|
|
|
9
9
|
var OPTIONS = "OPTIONS";
|
|
10
10
|
var EXAMPLES = "EXAMPLES";
|
|
11
11
|
var FORMORE = "For more info, run any command with the `--help` flag:";
|
|
12
|
+
var NEGATABLE = "Negatable of";
|
|
12
13
|
var help = "Display this help message";
|
|
13
14
|
var version = "Display this version";
|
|
14
15
|
var en_US_default = {
|
|
@@ -19,6 +20,7 @@ var en_US_default = {
|
|
|
19
20
|
OPTIONS,
|
|
20
21
|
EXAMPLES,
|
|
21
22
|
FORMORE,
|
|
23
|
+
NEGATABLE,
|
|
22
24
|
help,
|
|
23
25
|
version
|
|
24
26
|
};
|
|
@@ -60,7 +62,7 @@ var DefaultTranslation = class {
|
|
|
60
62
|
//#endregion
|
|
61
63
|
//#region src/context.ts
|
|
62
64
|
const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
|
|
63
|
-
async function createCommandContext({ options, values, positionals, args, tokens, command, commandOptions, omitted = false }) {
|
|
65
|
+
async function createCommandContext({ options, values, positionals, rest, args, tokens, command, commandOptions, omitted = false }) {
|
|
64
66
|
/**
|
|
65
67
|
* normailize the options schema and values, to avoid prototype pollution
|
|
66
68
|
*/
|
|
@@ -121,6 +123,7 @@ async function createCommandContext({ options, values, positionals, args, tokens
|
|
|
121
123
|
options: _options,
|
|
122
124
|
values,
|
|
123
125
|
positionals,
|
|
126
|
+
rest,
|
|
124
127
|
_: args,
|
|
125
128
|
tokens,
|
|
126
129
|
log: commandOptions.usageSilent ? NOOP : log,
|
|
@@ -175,12 +178,16 @@ async function cli(args, entry, opts = {}) {
|
|
|
175
178
|
const [name, command] = await resolveCommand(subCommand, entry, resolvedCommandOptions);
|
|
176
179
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
177
180
|
const options = resolveArgOptions(command.options);
|
|
178
|
-
const { values, positionals, error } = resolveArgs(options, tokens
|
|
181
|
+
const { values, positionals, rest, error } = resolveArgs(options, tokens, {
|
|
182
|
+
optionGrouping: true,
|
|
183
|
+
allowNegative: true
|
|
184
|
+
});
|
|
179
185
|
const omitted = !subCommand;
|
|
180
186
|
const ctx = await createCommandContext({
|
|
181
187
|
options,
|
|
182
188
|
values,
|
|
183
189
|
positionals,
|
|
190
|
+
rest,
|
|
184
191
|
args,
|
|
185
192
|
tokens,
|
|
186
193
|
omitted,
|
package/lib/definition.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./types.d-
|
|
2
|
-
import { ArgOptionSchema, ArgOptions, ArgValues, define$1 as define } from "./definition.d-
|
|
1
|
+
import "./types.d-zAq1WIpD.js";
|
|
2
|
+
import { ArgOptionSchema, ArgOptions, ArgValues, define$1 as define } from "./definition.d-DD_GraLw.js";
|
|
3
3
|
|
|
4
4
|
export { ArgOptionSchema, ArgOptions, ArgValues, define };
|
package/lib/generator.d.ts
CHANGED
package/lib/generator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { create } from "./renderer-
|
|
2
|
-
import { cli } from "./cli
|
|
1
|
+
import { create } from "./renderer-BeuJazdk.js";
|
|
2
|
+
import { cli } from "./cli--6qYDY8U.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generator.ts
|
|
5
5
|
async function generate(command, entry, opts = {}) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types.d-
|
|
2
|
-
import { define$1 as define } from "./definition.d-
|
|
1
|
+
import { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types.d-zAq1WIpD.js";
|
|
2
|
+
import { define$1 as define } from "./definition.d-DD_GraLw.js";
|
|
3
3
|
import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, parseArgs, resolveArgs } from "args-tokens";
|
|
4
4
|
|
|
5
5
|
//#region src/cli.d.ts
|
|
@@ -24,4 +24,4 @@ declare class DefaultTranslation implements TranslationAdapter {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
|
-
export { ArgOptionSchema, ArgOptions, ArgValues, Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, parseArgs, resolveArgs };
|
|
27
|
+
export { ArgOptionSchema, ArgOptions, ArgValues, Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, parseArgs, resolveArgs };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { define } from "./definition-BAm6f1St.js";
|
|
2
|
-
import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./renderer-
|
|
3
|
-
import { DefaultTranslation, cli } from "./cli
|
|
2
|
+
import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./renderer-BeuJazdk.js";
|
|
3
|
+
import { DefaultTranslation, cli } from "./cli--6qYDY8U.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
export { DEFAULT_LOCALE, DefaultTranslation, cli, define, parseArgs, resolveArgs };
|
package/lib/locales/en-US.json
CHANGED
package/lib/locales/ja-JP.json
CHANGED
|
@@ -224,6 +224,11 @@ function hasAllDefaultOptions(ctx) {
|
|
|
224
224
|
function generateOptionsSymbols(ctx) {
|
|
225
225
|
return hasOptions(ctx) ? hasAllDefaultOptions(ctx) ? `[${ctx.translate(resolveBuiltInKey("OPTIONS"))}]` : `<${ctx.translate(resolveBuiltInKey("OPTIONS"))}>` : "";
|
|
226
226
|
}
|
|
227
|
+
function makeShortLongOptionPair(schema, name) {
|
|
228
|
+
let key = `--${name}`;
|
|
229
|
+
if (schema.short) key = `-${schema.short}, ${key}`;
|
|
230
|
+
return key;
|
|
231
|
+
}
|
|
227
232
|
/**
|
|
228
233
|
* Get options pairs for usage
|
|
229
234
|
* @param ctx A {@link CommandContext | command context}
|
|
@@ -231,13 +236,17 @@ function generateOptionsSymbols(ctx) {
|
|
|
231
236
|
*/
|
|
232
237
|
function getOptionsPairs(ctx) {
|
|
233
238
|
return Object.entries(ctx.options).reduce((acc, [name, value]) => {
|
|
234
|
-
let key =
|
|
235
|
-
if (value.short) key = `-${value.short}, ${key}`;
|
|
239
|
+
let key = makeShortLongOptionPair(value, name);
|
|
236
240
|
if (value.type !== "boolean") key = value.default ? `${key} [${name}]` : `${key} <${name}>`;
|
|
237
241
|
acc[name] = key;
|
|
242
|
+
if (value.type === "boolean" && !(name === "help" || name === "version")) acc[`no-${name}`] = `--no-${name}`;
|
|
238
243
|
return acc;
|
|
239
244
|
}, create());
|
|
240
245
|
}
|
|
246
|
+
const resolveNegatableKey = (key) => key.split("no-")[1];
|
|
247
|
+
function resolveNegatableType(key, ctx) {
|
|
248
|
+
return ctx.options[key.startsWith("no-") ? resolveNegatableKey(key) : key].type;
|
|
249
|
+
}
|
|
241
250
|
/**
|
|
242
251
|
* Generate options usage
|
|
243
252
|
* @param ctx A {@link CommandContext | command context}
|
|
@@ -246,10 +255,16 @@ function getOptionsPairs(ctx) {
|
|
|
246
255
|
*/
|
|
247
256
|
async function generateOptionsUsage(ctx, optionsPairs) {
|
|
248
257
|
const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
|
|
249
|
-
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key, _]) => ctx.
|
|
258
|
+
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key, _]) => resolveNegatableType(key, ctx).length)) : 0;
|
|
250
259
|
const usages = await Promise.all(Object.entries(optionsPairs).map(([key, value]) => {
|
|
251
|
-
|
|
252
|
-
|
|
260
|
+
let rawDesc = ctx.translate(resolveOptionKey(key));
|
|
261
|
+
if (!rawDesc && key.startsWith("no-")) {
|
|
262
|
+
const name = resolveNegatableKey(key);
|
|
263
|
+
const schema = ctx.options[name];
|
|
264
|
+
const optionKey = makeShortLongOptionPair(schema, name);
|
|
265
|
+
rawDesc = `${ctx.translate(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
|
|
266
|
+
}
|
|
267
|
+
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
|
|
253
268
|
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
|
|
254
269
|
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}`;
|
|
255
270
|
return `${option.padStart(ctx.env.leftMargin + option.length)}`;
|
package/lib/renderer.d.ts
CHANGED
package/lib/renderer.js
CHANGED
|
@@ -32,7 +32,7 @@ type CommonOptionType = {
|
|
|
32
32
|
};
|
|
33
33
|
declare const COMMON_OPTIONS: CommonOptionType;
|
|
34
34
|
declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<ArgOptions>;
|
|
35
|
-
declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE"];
|
|
35
|
+
declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE"];
|
|
36
36
|
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/types.d.ts
|
|
@@ -46,6 +46,9 @@ type RemoveIndexSignature<T> = {
|
|
|
46
46
|
type RemovedIndex<T> = RemoveIndexSignature<{
|
|
47
47
|
[K in keyof T]: T[K];
|
|
48
48
|
}>;
|
|
49
|
+
type KeyOfArgOptions<Options extends ArgOptions> = keyof Options | {
|
|
50
|
+
[K in keyof Options]: Options[K]['type'] extends 'boolean' ? `no-${Extract<K, string>}` : never;
|
|
51
|
+
}[keyof Options];
|
|
49
52
|
/**
|
|
50
53
|
* Generate a namespaced key.
|
|
51
54
|
*/
|
|
@@ -67,7 +70,7 @@ type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinOptionsKeys> | Gen
|
|
|
67
70
|
* Command i18n option keys.
|
|
68
71
|
* The command i18n option keys are used to {@link CommandContext.translate | translate} function.
|
|
69
72
|
*/
|
|
70
|
-
type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<
|
|
73
|
+
type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<KeyOfArgOptions<RemovedIndex<Options>>, typeof OPTION_PREFIX>;
|
|
71
74
|
/**
|
|
72
75
|
* Command environment.
|
|
73
76
|
*/
|
|
@@ -236,6 +239,10 @@ interface CommandContext<Options extends ArgOptions = ArgOptions, Values = ArgVa
|
|
|
236
239
|
* Resolve positionals with `resolveArgs` from command arguments.
|
|
237
240
|
*/
|
|
238
241
|
positionals: string[];
|
|
242
|
+
/**
|
|
243
|
+
* Command rest arguments, that is the remaining argument not resolved by the optional command option delimiter `--`.
|
|
244
|
+
*/
|
|
245
|
+
rest: string[];
|
|
239
246
|
/**
|
|
240
247
|
* Original command line arguments.
|
|
241
248
|
* This argument is passed from `cli` function.
|
|
@@ -316,7 +323,7 @@ type CommandResource<Options extends ArgOptions = ArgOptions> = {
|
|
|
316
323
|
*/
|
|
317
324
|
examples: string;
|
|
318
325
|
} & {
|
|
319
|
-
[Option in GenerateNamespacedKey<
|
|
326
|
+
[Option in GenerateNamespacedKey<KeyOfArgOptions<RemovedIndex<Options>>, typeof OPTION_PREFIX>]: string;
|
|
320
327
|
} & {
|
|
321
328
|
[key: string]: string;
|
|
322
329
|
};
|
|
@@ -393,4 +400,4 @@ type LazyCommand<Options extends ArgOptions = ArgOptions> = () => Awaitable<Comm
|
|
|
393
400
|
type Commandable<Options extends ArgOptions> = Command<Options> | LazyCommand<Options>;
|
|
394
401
|
|
|
395
402
|
//#endregion
|
|
396
|
-
export { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
|
403
|
+
export { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgOptions, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gunshi",
|
|
3
3
|
"description": "Modern javascript command-line library",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"args-tokens": "^0.
|
|
74
|
+
"args-tokens": "^0.15.1"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@eslint/markdown": "^6.3.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"knip": "^5.50.2",
|
|
101
101
|
"lint-staged": "^15.5.0",
|
|
102
102
|
"messageformat": "4.0.0-10",
|
|
103
|
-
"pkg-pr-new": "^0.0.
|
|
103
|
+
"pkg-pr-new": "^0.0.43",
|
|
104
104
|
"prettier": "^3.5.3",
|
|
105
105
|
"publint": "^0.3.11",
|
|
106
106
|
"tsdown": "^0.9.1",
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
"lint:knip": "knip",
|
|
154
154
|
"lint:prettier": "prettier . --check",
|
|
155
155
|
"release": "bumpp --commit \"release: v%s\" --all --push --tag",
|
|
156
|
-
"test": "vitest run",
|
|
156
|
+
"test": "vitest --typecheck run",
|
|
157
157
|
"typecheck": "pnpm run --stream --color \"/^typecheck:/\"",
|
|
158
158
|
"typecheck:deno": "deno check --all ./src",
|
|
159
159
|
"typecheck:tsc": "tsc --noEmit"
|