gunshi 0.14.3 → 0.14.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.
@@ -1,4 +1,4 @@
1
- import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey } from "./renderer-B2JVfepJ.js";
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-DGPRTLmr.js";
2
2
  import { parseArgs, resolveArgs } from "args-tokens";
3
3
 
4
4
  //#region src/locales/en-US.json
@@ -210,7 +210,7 @@ function resolveArgOptions(options) {
210
210
  }
211
211
  function resolveCommandOptions(options, entry) {
212
212
  const subCommands = new Map(options.subCommands);
213
- if (typeof entry === "object" && entry.name) subCommands.set(entry.name, entry);
213
+ if (typeof entry === "object" && entry.name && options.subCommands) subCommands.set(entry.name, entry);
214
214
  const resolvedOptions = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands });
215
215
  return resolvedOptions;
216
216
  }
@@ -0,0 +1,13 @@
1
+ import { Command } from "./types.d-GVRYnEFw.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues as ArgValues$1 } from "args-tokens";
3
+
4
+ //#region src/definition.d.ts
5
+ /**
6
+ * Define a {@link Command | command} with type inference
7
+ * @param definition A {@link Command | command} definition
8
+ * @returns A {@link Command | command} definition with type inference
9
+ */
10
+ declare function define<Options extends ArgOptions = ArgOptions>(definition: Command<Options>): Command<Options>;
11
+
12
+ //#endregion
13
+ export { ArgOptionSchema, ArgOptions$1 as ArgOptions, ArgValues$1 as ArgValues, define as define$1 };
@@ -1,21 +1,4 @@
1
- import { ArgOptions } from 'args-tokens';
2
- export { ArgOptionSchema, ArgOptions, ArgValues } from 'args-tokens';
3
- import { C as Command } from './types.d-Dw5e-IT1.js';
1
+ import "./types.d-GVRYnEFw.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgValues, define$1 as define } from "./definition.d-TBObezo_.js";
4
3
 
5
- /**
6
- * The entry for command deifinition.
7
- * @example
8
- * ```js
9
- * import { define } from 'gunshi/definition'
10
- * ```
11
- * @module
12
- */
13
-
14
- /**
15
- * Define a {@link Command | command} with type inference
16
- * @param definition A {@link Command | command} definition
17
- * @returns A {@link Command | command} definition with type inference
18
- */
19
- declare function define<Options extends ArgOptions = ArgOptions>(definition: Command<Options>): Command<Options>;
20
-
21
- export { define };
4
+ export { ArgOptionSchema, ArgOptions, ArgValues, define };
package/lib/definition.js CHANGED
@@ -1,3 +1,3 @@
1
- import { define } from "./definition-by5EpPkZ.js";
1
+ import { define } from "./definition-BAm6f1St.js";
2
2
 
3
3
  export { define };
@@ -1,13 +1,15 @@
1
- import { ArgOptions } from 'args-tokens';
2
- import { C as Command, a as CommandOptions } from './types.d-Dw5e-IT1.js';
1
+ import { Command, CommandOptions } from "./types.d-GVRYnEFw.js";
2
+ import { ArgOptions } from "args-tokens";
3
3
 
4
+ //#region src/generator.d.ts
4
5
  /**
5
- * Generate the command usage.
6
- * @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
7
- * @param entry - A {@link Command | entry command}
8
- * @param opts - A {@link CommandOptions | command options}
9
- * @returns A rendered usage.
10
- */
6
+ * Generate the command usage.
7
+ * @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
8
+ * @param entry - A {@link Command | entry command}
9
+ * @param opts - A {@link CommandOptions | command options}
10
+ * @returns A rendered usage.
11
+ */
11
12
  declare function generate<Options extends ArgOptions = ArgOptions>(command: string | null, entry: Command<Options>, opts?: CommandOptions<Options>): Promise<string>;
12
13
 
13
- export { generate };
14
+ //#endregion
15
+ export { generate };
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
- import { create } from "./renderer-B2JVfepJ.js";
2
- import { cli } from "./cli-BlZyQHmk.js";
1
+ import { create } from "./renderer-DGPRTLmr.js";
2
+ import { cli } from "./cli-JT5dcEoE.js";
3
3
 
4
4
  //#region src/generator.ts
5
5
  async function generate(command, entry, opts = {}) {
package/lib/index.d.ts CHANGED
@@ -1,25 +1,27 @@
1
- import { ArgOptions } from 'args-tokens';
2
- export { ArgOptionSchema, ArgOptions, ArgValues, parseArgs, resolveArgs } from 'args-tokens';
3
- import { C as Command, b as CommandRunner, a as CommandOptions, T as TranslationAdapter, c as TranslationAdapterFactoryOptions } from './types.d-Dw5e-IT1.js';
4
- export { f as CommandBuiltinKeys, d as CommandBuiltinOptionsKeys, e as CommandBuiltinResourceKeys, i as CommandContext, h as CommandEnvironment, g as CommandOptionKeys, j as CommandResource, k as CommandResourceFetcher, m as Commandable, D as DEFAULT_LOCALE, G as GenerateNamespacedKey, L as LazyCommand, R as RemovedIndex, l as TranslationAdapterFactory } from './types.d-Dw5e-IT1.js';
5
- export { define } from './definition.js';
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-GVRYnEFw.js";
2
+ import { define$1 as define } from "./definition.d-TBObezo_.js";
3
+ import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, parseArgs, resolveArgs } from "args-tokens";
6
4
 
5
+ //#region src/cli.d.ts
7
6
  /**
8
- * Run the command.
9
- * @param args Command line arguments
10
- * @param entry A {@link Command | entry command} or an {@link CommandRunner | inline command runner}
11
- * @param opts A {@link CommandOptions | command options}
12
- * @returns A rendered usage or undefined. if you will use {@link CommandOptions.usageSilent} option, it will return rendered usage string.
13
- */
14
- declare function cli<Options extends ArgOptions = ArgOptions>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
7
+ * Run the command.
8
+ * @param args Command line arguments
9
+ * @param entry A {@link Command | entry command} or an {@link CommandRunner | inline command runner}
10
+ * @param opts A {@link CommandOptions | command options}
11
+ * @returns A rendered usage or undefined. if you will use {@link CommandOptions.usageSilent} option, it will return rendered usage string.
12
+ */
13
+ declare function cli<Options extends ArgOptions$1 = ArgOptions$1>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
15
14
 
15
+ //#endregion
16
+ //#region src/translation.d.ts
16
17
  declare class DefaultTranslation implements TranslationAdapter {
17
- #private;
18
- constructor(options: TranslationAdapterFactoryOptions);
19
- getResource(locale: string): Record<string, string> | undefined;
20
- setResource(locale: string, resource: Record<string, string>): void;
21
- getMessage(locale: string, key: string): string | undefined;
22
- translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
18
+ #private;
19
+ constructor(options: TranslationAdapterFactoryOptions);
20
+ getResource(locale: string): Record<string, string> | undefined;
21
+ setResource(locale: string, resource: Record<string, string>): void;
22
+ getMessage(locale: string, key: string): string | undefined;
23
+ translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
23
24
  }
24
25
 
25
- export { Command, CommandOptions, CommandRunner, DefaultTranslation, TranslationAdapter, TranslationAdapterFactoryOptions, cli };
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 };
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { define } from "./definition-by5EpPkZ.js";
2
- import { DEFAULT_LOCALE } from "./renderer-B2JVfepJ.js";
3
- import { DefaultTranslation, cli } from "./cli-BlZyQHmk.js";
1
+ import { define } from "./definition-BAm6f1St.js";
2
+ import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./renderer-DGPRTLmr.js";
3
+ import { DefaultTranslation, cli } from "./cli-JT5dcEoE.js";
4
4
  import { parseArgs, resolveArgs } from "args-tokens";
5
5
 
6
6
  export { DEFAULT_LOCALE, DefaultTranslation, cli, define, parseArgs, resolveArgs };
@@ -266,4 +266,4 @@ function renderValidationErrors(_ctx, error) {
266
266
  }
267
267
 
268
268
  //#endregion
269
- export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey };
269
+ export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey };
package/lib/renderer.d.ts CHANGED
@@ -1,26 +1,32 @@
1
- import { ArgOptions } from 'args-tokens';
2
- import { i as CommandContext } from './types.d-Dw5e-IT1.js';
1
+ import { CommandContext } from "./types.d-GVRYnEFw.js";
2
+ import { ArgOptions } from "args-tokens";
3
3
 
4
+ //#region src/renderer/header.d.ts
4
5
  /**
5
- * Render the header.
6
- * @param ctx A {@link CommandContext | command context}
7
- * @returns A rendered header.
8
- */
6
+ * Render the header.
7
+ * @param ctx A {@link CommandContext | command context}
8
+ * @returns A rendered header.
9
+ */
9
10
  declare function renderHeader<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
10
11
 
12
+ //#endregion
13
+ //#region src/renderer/usage.d.ts
11
14
  /**
12
- * Render the usage.
13
- * @param ctx A {@link CommandContext | command context}
14
- * @returns A rendered usage.
15
- */
15
+ * Render the usage.
16
+ * @param ctx A {@link CommandContext | command context}
17
+ * @returns A rendered usage.
18
+ */
16
19
  declare function renderUsage<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
17
20
 
21
+ //#endregion
22
+ //#region src/renderer/validation.d.ts
18
23
  /**
19
- * Render the validation errors.
20
- * @param ctx A {@link CommandContext | command context}
21
- * @param error An {@link AggregateError} of option in `args-token` validation
22
- * @returns A rendered validation error.
23
- */
24
+ * Render the validation errors.
25
+ * @param ctx A {@link CommandContext | command context}
26
+ * @param error An {@link AggregateError} of option in `args-token` validation
27
+ * @returns A rendered validation error.
28
+ */
24
29
  declare function renderValidationErrors<Options extends ArgOptions = ArgOptions>(_ctx: CommandContext<Options>, error: AggregateError): Promise<string>;
25
30
 
26
- export { renderHeader, renderUsage, renderValidationErrors };
31
+ //#endregion
32
+ export { renderHeader, renderUsage, renderValidationErrors };
package/lib/renderer.js CHANGED
@@ -1,3 +1,3 @@
1
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-B2JVfepJ.js";
1
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-DGPRTLmr.js";
2
2
 
3
3
  export { renderHeader, renderUsage, renderValidationErrors };
@@ -0,0 +1,396 @@
1
+ import { ArgOptions, ArgToken, ArgValues } from "args-tokens";
2
+
3
+ //#region rolldown:runtime
4
+
5
+
6
+
7
+ //#endregion
8
+ //#region src/constants.d.ts
9
+
10
+ declare namespace constants_d_exports {
11
+ export { BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, COMMAND_BUILTIN_RESOURCE_KEYS, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, OPTION_PREFIX, }
12
+ }
13
+ /**
14
+ * The default locale string, which format is BCP 47 language tag.
15
+ */
16
+ declare const DEFAULT_LOCALE = "en-US";
17
+ declare const BUILT_IN_PREFIX = "_";
18
+ declare const OPTION_PREFIX = "Option";
19
+ declare const BUILT_IN_KEY_SEPARATOR = ":";
20
+ declare const NOOP: () => void;
21
+ type CommonOptionType = {
22
+ readonly help: {
23
+ readonly type: 'boolean';
24
+ readonly short: 'h';
25
+ readonly description: string;
26
+ };
27
+ readonly version: {
28
+ readonly type: 'boolean';
29
+ readonly short: 'v';
30
+ readonly description: string;
31
+ };
32
+ };
33
+ declare const COMMON_OPTIONS: CommonOptionType;
34
+ declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<ArgOptions>;
35
+ declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE"];
36
+
37
+ //#endregion
38
+ //#region src/types.d.ts
39
+ type Awaitable<T> = T | Promise<T>;
40
+ type RemoveIndexSignature<T> = {
41
+ [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
42
+ };
43
+ /**
44
+ * Remove index signature from object or record type.
45
+ */
46
+ type RemovedIndex<T> = RemoveIndexSignature<{
47
+ [K in keyof T]: T[K];
48
+ }>;
49
+ /**
50
+ * Generate a namespaced key.
51
+ */
52
+ type GenerateNamespacedKey<Key extends string, Prefixed extends string = typeof BUILT_IN_PREFIX> = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
53
+ /**
54
+ * Command i18n built-in options keys.
55
+ */
56
+ type CommandBuiltinOptionsKeys = keyof (typeof constants_d_exports)['COMMON_OPTIONS'];
57
+ /**
58
+ * Command i18n built-in resource keys.
59
+ */
60
+ type CommandBuiltinResourceKeys = (typeof constants_d_exports)['COMMAND_BUILTIN_RESOURCE_KEYS'][number];
61
+ /**
62
+ * Command i18n built-in keys.
63
+ * The command i18n built-in keys are used to {@link CommandContext.translate | translate} function.
64
+ */
65
+ type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinOptionsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | 'description' | 'examples';
66
+ /**
67
+ * Command i18n option keys.
68
+ * The command i18n option keys are used to {@link CommandContext.translate | translate} function.
69
+ */
70
+ type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>;
71
+ /**
72
+ * Command environment.
73
+ */
74
+ interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
75
+ /**
76
+ * Current working directory.
77
+ * @see {@link CommandOptions.cwd}
78
+ */
79
+ cwd: string | undefined;
80
+ /**
81
+ * Command name.
82
+ * @see {@link CommandOptions.name}
83
+ */
84
+ name: string | undefined;
85
+ /**
86
+ * Command description.
87
+ * @see {@link CommandOptions.description}
88
+ *
89
+ */
90
+ description: string | undefined;
91
+ /**
92
+ * Command version.
93
+ * @see {@link CommandOptions.version}
94
+ */
95
+ version: string | undefined;
96
+ /**
97
+ * Left margin of the command output.
98
+ * @default 2
99
+ * @see {@link CommandOptions.leftMargin}
100
+ */
101
+ leftMargin: number;
102
+ /**
103
+ * Middle margin of the command output.
104
+ * @default 10
105
+ * @see {@link CommandOptions.middleMargin}
106
+ */
107
+ middleMargin: number;
108
+ /**
109
+ * Whether to display the usage option type.
110
+ * @default false
111
+ * @see {@link CommandOptions.usageOptionType}
112
+ */
113
+ usageOptionType: boolean;
114
+ /**
115
+ * Whether to display the command usage.
116
+ * @default false
117
+ * @see {@link}
118
+ */
119
+ usageSilent: boolean;
120
+ /**
121
+ * Sub commands.
122
+ * @see {@link CommandOptions.subCommands}
123
+ */
124
+ subCommands: Map<string, Command<any> | LazyCommand<any>> | undefined;
125
+ /**
126
+ * Render function the command usage.
127
+ */
128
+ renderUsage: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
129
+ /**
130
+ * Render function the header section in the command usage.
131
+ */
132
+ renderHeader: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
133
+ /**
134
+ * Render function the validation errors.
135
+ */
136
+ renderValidationErrors: ((ctx: CommandContext<Options>, error: AggregateError) => Promise<string>) | null | undefined;
137
+ }
138
+ /**
139
+ * Command options.
140
+ */
141
+ interface CommandOptions<Options extends ArgOptions = ArgOptions> {
142
+ /**
143
+ * Current working directory.
144
+ */
145
+ cwd?: string;
146
+ /**
147
+ * Command program name.
148
+ */
149
+ name?: string;
150
+ /**
151
+ * Command program description.
152
+ *
153
+ */
154
+ description?: string;
155
+ /**
156
+ * Command program version.
157
+ */
158
+ version?: string;
159
+ /**
160
+ * Command program locale.
161
+ */
162
+ locale?: string | Intl.Locale;
163
+ /**
164
+ * Sub commands.
165
+ */
166
+ subCommands?: Map<string, Command<any> | LazyCommand<any>>;
167
+ /**
168
+ * Left margin of the command output.
169
+ */
170
+ leftMargin?: number;
171
+ /**
172
+ * Middle margin of the command output.
173
+ */
174
+ middleMargin?: number;
175
+ /**
176
+ * Whether to display the usage option type.
177
+ */
178
+ usageOptionType?: boolean;
179
+ /**
180
+ * Whether to display the command usage.
181
+ */
182
+ usageSilent?: boolean;
183
+ /**
184
+ * Render function the command usage.
185
+ */
186
+ renderUsage?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
187
+ /**
188
+ * Render function the header section in the command usage.
189
+ */
190
+ renderHeader?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
191
+ /**
192
+ * Render function the validation errors.
193
+ */
194
+ renderValidationErrors?: ((ctx: Readonly<CommandContext<Options>>, error: AggregateError) => Promise<string>) | null;
195
+ /**
196
+ * Translation adapter factory.
197
+ */
198
+ translationAdapterFactory?: TranslationAdapterFactory;
199
+ }
200
+ /**
201
+ * Command context.
202
+ * Command context is the context of the command execution.
203
+ */
204
+ interface CommandContext<Options extends ArgOptions = ArgOptions, Values = ArgValues<Options>> {
205
+ /**
206
+ * Command name, that is the command that is executed.
207
+ * The command name is same {@link CommandEnvironment.name}.
208
+ */
209
+ name: string | undefined;
210
+ /**
211
+ * Command description, that is the description of the command that is executed.
212
+ * The command description is same {@link CommandEnvironment.description}.
213
+ */
214
+ description: string | undefined;
215
+ /**
216
+ * Command locale, that is the locale of the command that is executed.
217
+ */
218
+ locale: Intl.Locale;
219
+ /**
220
+ * Command environment, that is the environment of the command that is executed.
221
+ * The command environment is same {@link CommandEnvironment}.
222
+ */
223
+ env: Readonly<CommandEnvironment<Options>>;
224
+ /**
225
+ * Command options, that is the options of the command that is executed.
226
+ * The command options is same {@link Command.options}.
227
+ */
228
+ options: Options;
229
+ /**
230
+ * Command values, that is the values of the command that is executed.
231
+ * Resolve values with `resolveArgs` from command arguments and {@link Command.options}.
232
+ */
233
+ values: Values;
234
+ /**
235
+ * Command positionals arguments, that is the positionals of the command that is executed.
236
+ * Resolve positionals with `resolveArgs` from command arguments.
237
+ */
238
+ positionals: string[];
239
+ /**
240
+ * Original command line arguments.
241
+ * This argument is passed from `cli` function.
242
+ */
243
+ _: string[];
244
+ /**
245
+ * Argument tokens, that is parsed by `parseArgs` function.
246
+ */
247
+ tokens: ArgToken[];
248
+ /**
249
+ * Whether the currently executing command has been executed with the sub-command name omitted.
250
+ */
251
+ omitted: boolean;
252
+ /**
253
+ * Output a message.
254
+ * If {@link CommandEnvironment.usageSilent} is true, the message is not output.
255
+ * @param message an output message, @see {@link console.log}
256
+ * @param optionalParams an optional parameters, @see {@link console.log}
257
+ */
258
+ log: (message?: any, ...optionalParams: any[]) => void;
259
+ /**
260
+ * Load sub-commands.
261
+ * The loaded commands are cached and returned when called again.
262
+ * @returns loaded commands.
263
+ */
264
+ loadCommands: () => Promise<Command<Options>[]>;
265
+ /**
266
+ * Translate function.
267
+ * @param key the key to be translated
268
+ * @param values the values to be formatted
269
+ * @returns A translated string.
270
+ */
271
+ translate: <T extends string = CommandBuiltinKeys, O = CommandOptionKeys<Options>, Key = CommandBuiltinKeys | O | T>(key: Key, values?: Record<string, unknown>) => string;
272
+ }
273
+ /**
274
+ * Command interface.
275
+ */
276
+ interface Command<Options extends ArgOptions = ArgOptions> {
277
+ /**
278
+ * Command name.
279
+ * It's used to find command line arguments to execute from sub commands, and it's recommended to specify.
280
+ */
281
+ name?: string;
282
+ /**
283
+ * Command description.
284
+ * It's used to describe the command in usage and it's recommended to specify.
285
+ */
286
+ description?: string;
287
+ /**
288
+ * Command options.
289
+ * Each option can include a description property to describe the option in usage.
290
+ */
291
+ options?: Options;
292
+ /**
293
+ * Command examples.
294
+ * examples of how to use the command.
295
+ */
296
+ examples?: string;
297
+ /**
298
+ * Command runner. it's the command to be executed
299
+ */
300
+ run: CommandRunner<Options>;
301
+ /**
302
+ * Command resource fetcher.
303
+ */
304
+ resource?: CommandResourceFetcher<Options>;
305
+ }
306
+ /**
307
+ * Command resource.
308
+ */
309
+ type CommandResource<Options extends ArgOptions = ArgOptions> = {
310
+ /**
311
+ * Command description.
312
+ */
313
+ description: string;
314
+ /**
315
+ * Examples usage.
316
+ */
317
+ examples: string;
318
+ } & {
319
+ [Option in GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>]: string;
320
+ } & {
321
+ [key: string]: string;
322
+ };
323
+ /**
324
+ * Command resource fetcher.
325
+ * @param ctx A {@link CommandContext | command context}
326
+ * @returns A fetched {@link CommandResource | command resource}.
327
+ */
328
+ type CommandResourceFetcher<Options extends ArgOptions = ArgOptions, Values = ArgValues<Options>> = (ctx: Readonly<CommandContext<Options, Values>>) => Promise<CommandResource<Options>>;
329
+ /**
330
+ * Translation adapter factory.
331
+ */
332
+ type TranslationAdapterFactory = (options: TranslationAdapterFactoryOptions) => TranslationAdapter;
333
+ /**
334
+ * Translation adapter factory options.
335
+ */
336
+ interface TranslationAdapterFactoryOptions {
337
+ /**
338
+ * A locale.
339
+ */
340
+ locale: string;
341
+ /**
342
+ * A fallback locale.
343
+ */
344
+ fallbackLocale: string;
345
+ }
346
+ /**
347
+ * Translation adapter.
348
+ * This adapter is used to custom message formatter like {@link https://github.com/intlify/vue-i18n/blob/master/spec/syntax.ebnf | Intlify message format}, {@link https://github.com/tc39/proposal-intl-messageformat | `Intl.MessageFormat` (MF2)}, and etc.
349
+ * This adapter will support localization with your preferred message format.
350
+ */
351
+ interface TranslationAdapter<MessageResource = string> {
352
+ /**
353
+ * Get a resource of locale.
354
+ * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
355
+ * @returns A resource of locale. if resource not found, return `undefined`.
356
+ */
357
+ getResource(locale: string): Record<string, string> | undefined;
358
+ /**
359
+ * Set a resource of locale.
360
+ * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
361
+ * @param resource A resource of locale
362
+ */
363
+ setResource(locale: string, resource: Record<string, string>): void;
364
+ /**
365
+ * Get a message of locale.
366
+ * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
367
+ * @param key A key of message resource
368
+ * @returns A message of locale. if message not found, return `undefined`.
369
+ */
370
+ getMessage(locale: string, key: string): MessageResource | undefined;
371
+ /**
372
+ * Translate a message.
373
+ * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
374
+ * @param key A key of message resource
375
+ * @param values A values to be resolved in the message
376
+ * @returns A translated message, if message is not translated, return `undefined`.
377
+ */
378
+ translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
379
+ }
380
+ /**
381
+ * Command runner.
382
+ * @param ctx A {@link CommandContext | command context}
383
+ */
384
+ type CommandRunner<Options extends ArgOptions = ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Awaitable<void>;
385
+ /**
386
+ * Lazy command interface.
387
+ * Lazy command that's not loaded until it is executed.
388
+ */
389
+ type LazyCommand<Options extends ArgOptions = ArgOptions> = () => Awaitable<Command<Options>>;
390
+ /**
391
+ * Define a command type.
392
+ */
393
+ type Commandable<Options extends ArgOptions> = Command<Options> | LazyCommand<Options>;
394
+
395
+ //#endregion
396
+ export { Command, CommandBuiltinKeys, CommandBuiltinOptionsKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandOptionKeys, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, 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.14.3",
4
+ "version": "0.14.5",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -76,7 +76,7 @@
76
76
  "devDependencies": {
77
77
  "@eslint/markdown": "^6.3.0",
78
78
  "@intlify/core": "next",
79
- "@kazupon/eslint-config": "^0.27.0",
79
+ "@kazupon/eslint-config": "^0.29.0",
80
80
  "@kazupon/prettier-config": "^0.1.1",
81
81
  "@types/node": "^22.14.0",
82
82
  "@vitest/eslint-plugin": "^1.1.42",
@@ -103,7 +103,8 @@
103
103
  "pkg-pr-new": "^0.0.42",
104
104
  "prettier": "^3.5.3",
105
105
  "publint": "^0.3.11",
106
- "tsdown": "0.6.10",
106
+ "tsdown": "^0.9.1",
107
+ "tsdown-jsr-exports-lint": "^0.1.4",
107
108
  "typedoc": "^0.28.2",
108
109
  "typedoc-plugin-markdown": "^4.6.2",
109
110
  "typedoc-vitepress-theme": "^1.1.2",
@@ -111,7 +112,7 @@
111
112
  "typescript-eslint": "^8.29.1",
112
113
  "vitepress": "^1.6.3",
113
114
  "vitepress-plugin-group-icons": "^1.4.1",
114
- "vitepress-plugin-llms": "^0.0.22",
115
+ "vitepress-plugin-llms": "^1.0.0",
115
116
  "vitest": "^3.1.1",
116
117
  "vue": "^3.5.13"
117
118
  },
@@ -1,412 +0,0 @@
1
- import { ArgOptions, ArgValues, ArgToken } from 'args-tokens';
2
-
3
- /**
4
- * The default locale string, which format is BCP 47 language tag.
5
- */
6
- declare const DEFAULT_LOCALE = "en-US";
7
- declare const BUILT_IN_PREFIX = "_";
8
- declare const OPTION_PREFIX = "Option";
9
- declare const BUILT_IN_KEY_SEPARATOR = ":";
10
- declare const NOOP: () => void;
11
- type CommonOptionType = {
12
- readonly help: {
13
- readonly type: "boolean"
14
- readonly short: "h"
15
- readonly description: string
16
- }
17
- readonly version: {
18
- readonly type: "boolean"
19
- readonly short: "v"
20
- readonly description: string
21
- }
22
- };
23
- declare const COMMON_OPTIONS: CommonOptionType;
24
- declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<ArgOptions>;
25
- declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE"];
26
-
27
- declare const __constants_ts_BUILT_IN_KEY_SEPARATOR: typeof BUILT_IN_KEY_SEPARATOR;
28
- declare const __constants_ts_BUILT_IN_PREFIX: typeof BUILT_IN_PREFIX;
29
- declare const __constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS: typeof COMMAND_BUILTIN_RESOURCE_KEYS;
30
- declare const __constants_ts_COMMAND_OPTIONS_DEFAULT: typeof COMMAND_OPTIONS_DEFAULT;
31
- declare const __constants_ts_COMMON_OPTIONS: typeof COMMON_OPTIONS;
32
- declare const __constants_ts_DEFAULT_LOCALE: typeof DEFAULT_LOCALE;
33
- declare const __constants_ts_NOOP: typeof NOOP;
34
- declare const __constants_ts_OPTION_PREFIX: typeof OPTION_PREFIX;
35
- declare namespace __constants_ts {
36
- export {
37
- __constants_ts_BUILT_IN_KEY_SEPARATOR as BUILT_IN_KEY_SEPARATOR,
38
- __constants_ts_BUILT_IN_PREFIX as BUILT_IN_PREFIX,
39
- __constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS as COMMAND_BUILTIN_RESOURCE_KEYS,
40
- __constants_ts_COMMAND_OPTIONS_DEFAULT as COMMAND_OPTIONS_DEFAULT,
41
- __constants_ts_COMMON_OPTIONS as COMMON_OPTIONS,
42
- __constants_ts_DEFAULT_LOCALE as DEFAULT_LOCALE,
43
- __constants_ts_NOOP as NOOP,
44
- __constants_ts_OPTION_PREFIX as OPTION_PREFIX,
45
- };
46
- }
47
-
48
- type Awaitable<T> = T | Promise<T>;
49
- type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K] : T[K] };
50
- /**
51
- * Remove index signature from object or record type.
52
- */
53
- type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T] : T[K] }>;
54
- /**
55
- * Generate a namespaced key.
56
- */
57
- type GenerateNamespacedKey<
58
- Key extends string,
59
- Prefixed extends string = typeof BUILT_IN_PREFIX
60
- > = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
61
- /**
62
- * Command i18n built-in options keys.
63
- */
64
- type CommandBuiltinOptionsKeys = keyof (typeof __constants_ts)["COMMON_OPTIONS"];
65
- /**
66
- * Command i18n built-in resource keys.
67
- */
68
- type CommandBuiltinResourceKeys = (typeof __constants_ts)["COMMAND_BUILTIN_RESOURCE_KEYS"][number];
69
- /**
70
- * Command i18n built-in keys.
71
- * The command i18n built-in keys are used to {@link CommandContext.translate | translate} function.
72
- */
73
- type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinOptionsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | "description" | "examples";
74
- /**
75
- * Command i18n option keys.
76
- * The command i18n option keys are used to {@link CommandContext.translate | translate} function.
77
- */
78
- type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>;
79
- /**
80
- * Command environment.
81
- */
82
- interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
83
- /**
84
- * Current working directory.
85
- * @see {@link CommandOptions.cwd}
86
- */
87
- cwd: string | undefined;
88
- /**
89
- * Command name.
90
- * @see {@link CommandOptions.name}
91
- */
92
- name: string | undefined;
93
- /**
94
- * Command description.
95
- * @see {@link CommandOptions.description}
96
- *
97
- */
98
- description: string | undefined;
99
- /**
100
- * Command version.
101
- * @see {@link CommandOptions.version}
102
- */
103
- version: string | undefined;
104
- /**
105
- * Left margin of the command output.
106
- * @default 2
107
- * @see {@link CommandOptions.leftMargin}
108
- */
109
- leftMargin: number;
110
- /**
111
- * Middle margin of the command output.
112
- * @default 10
113
- * @see {@link CommandOptions.middleMargin}
114
- */
115
- middleMargin: number;
116
- /**
117
- * Whether to display the usage option type.
118
- * @default false
119
- * @see {@link CommandOptions.usageOptionType}
120
- */
121
- usageOptionType: boolean;
122
- /**
123
- * Whether to display the command usage.
124
- * @default false
125
- * @see {@link}
126
- */
127
- usageSilent: boolean;
128
- /**
129
- * Sub commands.
130
- * @see {@link CommandOptions.subCommands}
131
- */
132
- subCommands: Map<string, Command<any> | LazyCommand<any>> | undefined;
133
- /**
134
- * Render function the command usage.
135
- */
136
- renderUsage: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
137
- /**
138
- * Render function the header section in the command usage.
139
- */
140
- renderHeader: ((ctx: CommandContext<Options>) => Promise<string>) | null | undefined;
141
- /**
142
- * Render function the validation errors.
143
- */
144
- renderValidationErrors: ((ctx: CommandContext<Options>, error: AggregateError) => Promise<string>) | null | undefined;
145
- }
146
- /**
147
- * Command options.
148
- */
149
- interface CommandOptions<Options extends ArgOptions = ArgOptions> {
150
- /**
151
- * Current working directory.
152
- */
153
- cwd?: string;
154
- /**
155
- * Command program name.
156
- */
157
- name?: string;
158
- /**
159
- * Command program description.
160
- *
161
- */
162
- description?: string;
163
- /**
164
- * Command program version.
165
- */
166
- version?: string;
167
- /**
168
- * Command program locale.
169
- */
170
- locale?: string | Intl.Locale;
171
- /**
172
- * Sub commands.
173
- */
174
- subCommands?: Map<string, Command<any> | LazyCommand<any>>;
175
- /**
176
- * Left margin of the command output.
177
- */
178
- leftMargin?: number;
179
- /**
180
- * Middle margin of the command output.
181
- */
182
- middleMargin?: number;
183
- /**
184
- * Whether to display the usage option type.
185
- */
186
- usageOptionType?: boolean;
187
- /**
188
- * Whether to display the command usage.
189
- */
190
- usageSilent?: boolean;
191
- /**
192
- * Render function the command usage.
193
- */
194
- renderUsage?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
195
- /**
196
- * Render function the header section in the command usage.
197
- */
198
- renderHeader?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
199
- /**
200
- * Render function the validation errors.
201
- */
202
- renderValidationErrors?: ((ctx: Readonly<CommandContext<Options>>, error: AggregateError) => Promise<string>) | null;
203
- /**
204
- * Translation adapter factory.
205
- */
206
- translationAdapterFactory?: TranslationAdapterFactory;
207
- }
208
- /**
209
- * Command context.
210
- * Command context is the context of the command execution.
211
- */
212
- interface CommandContext<
213
- Options extends ArgOptions = ArgOptions,
214
- Values = ArgValues<Options>
215
- > {
216
- /**
217
- * Command name, that is the command that is executed.
218
- * The command name is same {@link CommandEnvironment.name}.
219
- */
220
- name: string | undefined;
221
- /**
222
- * Command description, that is the description of the command that is executed.
223
- * The command description is same {@link CommandEnvironment.description}.
224
- */
225
- description: string | undefined;
226
- /**
227
- * Command locale, that is the locale of the command that is executed.
228
- */
229
- locale: Intl.Locale;
230
- /**
231
- * Command environment, that is the environment of the command that is executed.
232
- * The command environment is same {@link CommandEnvironment}.
233
- */
234
- env: Readonly<CommandEnvironment<Options>>;
235
- /**
236
- * Command options, that is the options of the command that is executed.
237
- * The command options is same {@link Command.options}.
238
- */
239
- options: Options;
240
- /**
241
- * Command values, that is the values of the command that is executed.
242
- * Resolve values with `resolveArgs` from command arguments and {@link Command.options}.
243
- */
244
- values: Values;
245
- /**
246
- * Command positionals arguments, that is the positionals of the command that is executed.
247
- * Resolve positionals with `resolveArgs` from command arguments.
248
- */
249
- positionals: string[];
250
- /**
251
- * Original command line arguments.
252
- * This argument is passed from `cli` function.
253
- */
254
- _: string[];
255
- /**
256
- * Argument tokens, that is parsed by `parseArgs` function.
257
- */
258
- tokens: ArgToken[];
259
- /**
260
- * Whether the currently executing command has been executed with the sub-command name omitted.
261
- */
262
- omitted: boolean;
263
- /**
264
- * Output a message.
265
- * If {@link CommandEnvironment.usageSilent} is true, the message is not output.
266
- * @param message an output message, @see {@link console.log}
267
- * @param optionalParams an optional parameters, @see {@link console.log}
268
- */
269
- log: (message?: any, ...optionalParams: any[]) => void;
270
- /**
271
- * Load sub-commands.
272
- * The loaded commands are cached and returned when called again.
273
- * @returns loaded commands.
274
- */
275
- loadCommands: () => Promise<Command<Options>[]>;
276
- /**
277
- * Translate function.
278
- * @param key the key to be translated
279
- * @param values the values to be formatted
280
- * @returns A translated string.
281
- */
282
- translate: <
283
- T extends string = CommandBuiltinKeys,
284
- O = CommandOptionKeys<Options>,
285
- Key = CommandBuiltinKeys | O | T
286
- >(key: Key, values?: Record<string, unknown>) => string;
287
- }
288
- /**
289
- * Command interface.
290
- */
291
- interface Command<Options extends ArgOptions = ArgOptions> {
292
- /**
293
- * Command name.
294
- * It's used to find command line arguments to execute from sub commands, and it's recommended to specify.
295
- */
296
- name?: string;
297
- /**
298
- * Command description.
299
- * It's used to describe the command in usage and it's recommended to specify.
300
- */
301
- description?: string;
302
- /**
303
- * Command options.
304
- * Each option can include a description property to describe the option in usage.
305
- */
306
- options?: Options;
307
- /**
308
- * Command examples.
309
- * examples of how to use the command.
310
- */
311
- examples?: string;
312
- /**
313
- * Command runner. it's the command to be executed
314
- */
315
- run: CommandRunner<Options>;
316
- /**
317
- * Command resource fetcher.
318
- */
319
- resource?: CommandResourceFetcher<Options>;
320
- }
321
- /**
322
- * Command resource.
323
- */
324
- type CommandResource<Options extends ArgOptions = ArgOptions> = {
325
- /**
326
- * Command description.
327
- */
328
- description: string
329
- /**
330
- * Examples usage.
331
- */
332
- examples: string
333
- } & { [Option in GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>] : string } & {
334
- [key: string]: string
335
- };
336
- /**
337
- * Command resource fetcher.
338
- * @param ctx A {@link CommandContext | command context}
339
- * @returns A fetched {@link CommandResource | command resource}.
340
- */
341
- type CommandResourceFetcher<
342
- Options extends ArgOptions = ArgOptions,
343
- Values = ArgValues<Options>
344
- > = (ctx: Readonly<CommandContext<Options, Values>>) => Promise<CommandResource<Options>>;
345
- /**
346
- * Translation adapter factory.
347
- */
348
- type TranslationAdapterFactory = (options: TranslationAdapterFactoryOptions) => TranslationAdapter;
349
- /**
350
- * Translation adapter factory options.
351
- */
352
- interface TranslationAdapterFactoryOptions {
353
- /**
354
- * A locale.
355
- */
356
- locale: string;
357
- /**
358
- * A fallback locale.
359
- */
360
- fallbackLocale: string;
361
- }
362
- /**
363
- * Translation adapter.
364
- * This adapter is used to custom message formatter like {@link https://github.com/intlify/vue-i18n/blob/master/spec/syntax.ebnf | Intlify message format}, {@link https://github.com/tc39/proposal-intl-messageformat | `Intl.MessageFormat` (MF2)}, and etc.
365
- * This adapter will support localization with your preferred message format.
366
- */
367
- interface TranslationAdapter<MessageResource = string> {
368
- /**
369
- * Get a resource of locale.
370
- * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
371
- * @returns A resource of locale. if resource not found, return `undefined`.
372
- */
373
- getResource(locale: string): Record<string, string> | undefined;
374
- /**
375
- * Set a resource of locale.
376
- * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
377
- * @param resource A resource of locale
378
- */
379
- setResource(locale: string, resource: Record<string, string>): void;
380
- /**
381
- * Get a message of locale.
382
- * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
383
- * @param key A key of message resource
384
- * @returns A message of locale. if message not found, return `undefined`.
385
- */
386
- getMessage(locale: string, key: string): MessageResource | undefined;
387
- /**
388
- * Translate a message.
389
- * @param locale A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
390
- * @param key A key of message resource
391
- * @param values A values to be resolved in the message
392
- * @returns A translated message, if message is not translated, return `undefined`.
393
- */
394
- translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
395
- }
396
- /**
397
- * Command runner.
398
- * @param ctx A {@link CommandContext | command context}
399
- */
400
- type CommandRunner<Options extends ArgOptions = ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Awaitable<void>;
401
- /**
402
- * Lazy command interface.
403
- * Lazy command that's not loaded until it is executed.
404
- */
405
- type LazyCommand<Options extends ArgOptions = ArgOptions> = () => Awaitable<Command<Options>>;
406
- /**
407
- * Define a command type.
408
- */
409
- type Commandable<Options extends ArgOptions> = Command<Options> | LazyCommand<Options>;
410
-
411
- export { DEFAULT_LOCALE as D };
412
- export type { Command as C, GenerateNamespacedKey as G, LazyCommand as L, RemovedIndex as R, TranslationAdapter as T, CommandOptions as a, CommandRunner as b, TranslationAdapterFactoryOptions as c, CommandBuiltinOptionsKeys as d, CommandBuiltinResourceKeys as e, CommandBuiltinKeys as f, CommandOptionKeys as g, CommandEnvironment as h, CommandContext as i, CommandResource as j, CommandResourceFetcher as k, TranslationAdapterFactory as l, Commandable as m };