gunshi 0.12.0 → 0.14.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/README.md CHANGED
@@ -32,8 +32,6 @@ Gunshi is designed to simplify the creation of modern command-line interfaces:
32
32
 
33
33
  ## 💿 Installation
34
34
 
35
- ### 🐢 Node
36
-
37
35
  ```sh
38
36
  # npm
39
37
  npm install --save gunshi
@@ -43,41 +41,16 @@ pnpm add gunshi
43
41
 
44
42
  ## yarn
45
43
  yarn add gunshi
46
- ```
47
-
48
- ### 🦕 Deno
49
44
 
50
- ```sh
45
+ ## deno
51
46
  deno add jsr:@kazupon/gunshi
52
- ```
53
47
 
54
- ### 🥟 Bun
55
-
56
- ```sh
48
+ ## bun
57
49
  bun add gunshi
58
50
  ```
59
51
 
60
52
  ## 🚀 Usage
61
53
 
62
- ### 📏 Simple API
63
-
64
- Gunshi has a simple API that is a facade:
65
-
66
- ```js
67
- import { cli } from 'gunshi'
68
-
69
- const args = process.argv.slice(2)
70
- // run a simple command
71
- await cli(args, () => {
72
- // something logic ...
73
- console.log('Hello from Gunshi!', args)
74
- })
75
- ```
76
-
77
- ### ⚙️ Declarative Configuration
78
-
79
- Configure commands declaratively:
80
-
81
54
  ```js
82
55
  import { cli } from 'gunshi'
83
56
 
@@ -121,289 +94,7 @@ await cli(process.argv.slice(2), command, {
121
94
  })
122
95
  ```
123
96
 
124
- For more detailed examples, check out the [playground/declarative](https://github.com/kazupon/gunshi/tree/main/playground/declarative) in the repository.
125
-
126
- ### 🛡️ Type-Safe Arguments
127
-
128
- Gunshi provides type-safe argument parsing with TypeScript:
129
-
130
- ```ts
131
- import { cli } from 'gunshi'
132
- import type { ArgOptions, Command, CommandContext } from 'gunshi'
133
-
134
- // type-safe arguments parsing example
135
- // this demonstrates how to define and use typed command options with `satisfies`
136
-
137
- // define 'type-safe' command options with types
138
- const options = {
139
- // define string option with short alias
140
- name: {
141
- type: 'string',
142
- short: 'n'
143
- },
144
- // define number option with default value
145
- age: {
146
- type: 'number',
147
- short: 'a',
148
- default: 25
149
- },
150
- // define boolean flag
151
- verbose: {
152
- type: 'boolean',
153
- short: 'v'
154
- }
155
- } satisfies ArgOptions
156
-
157
- // define 'type-safe' command
158
- const command = {
159
- name: 'type-safe',
160
- options,
161
- run: (ctx: CommandContext<UserOptions, UserValues>) => {
162
- const { name, age, verbose } = ctx.values
163
- console.log(`Hello, ${name || 'World'}! You are ${age} years old.`)
164
- }
165
- } satisfies Command<typeof options>
166
-
167
- await cli(process.argv.slice(2), command)
168
- ```
169
-
170
- For more detailed examples, check out the [playground/type-safe](https://github.com/kazupon/gunshi/tree/main/playground/type-safe) in the repository.
171
-
172
- ### 🧩 Composable Sub-commands
173
-
174
- Run a CLI with composable sub-commands:
175
-
176
- ```js
177
- import { cli } from 'gunshi'
178
-
179
- // define 'create' command
180
- const createCommand = {
181
- name: 'create',
182
- description: 'Create a new resource',
183
- options: {
184
- name: { type: 'string', short: 'n' }
185
- },
186
- run: ctx => {
187
- console.log(`Creating resource: ${ctx.values.name}`)
188
- }
189
- }
190
-
191
- // define 'list' command
192
- const listCommand = {
193
- name: 'list',
194
- description: 'List all resources',
195
- run: () => {
196
- console.log('Listing all resources...')
197
- }
198
- }
199
-
200
- // prepare a Map of sub-commands
201
- const subCommands = new Map()
202
- subCommands.set('create', createCommand)
203
- subCommands.set('list', listCommand)
204
-
205
- // define the main ('resource-manager') command
206
- const mainCommand = {
207
- name: 'resource-manager',
208
- description: 'Manage resources',
209
- run: () => {
210
- console.log('Use one of the sub-commands: create, list')
211
- }
212
- }
213
-
214
- // run the CLI with composable sub-commands
215
- await cli(process.argv.slice(2), mainCommand, {
216
- name: 'my-app',
217
- version: '1.0.0',
218
- subCommands
219
- })
220
- ```
221
-
222
- For more detailed examples, check out the [playground/composable](https://github.com/kazupon/gunshi/tree/main/playground/composable) in the repository.
223
-
224
- ### ⏳ Lazy & Async Command Loading
225
-
226
- Load commands lazily and execute them asynchronously:
227
-
228
- ```js
229
- import { cli } from 'gunshi'
230
-
231
- // define a command that will be loaded lazily
232
- const lazyCommand = async () => {
233
- // simulate async loading
234
- await new Promise(resolve => setTimeout(resolve, 1000))
235
-
236
- // return the actual command
237
- return {
238
- name: 'lazy',
239
- description: 'A command that is loaded lazily',
240
- run: async ctx => {
241
- // async execution
242
- await new Promise(resolve => setTimeout(resolve, 500))
243
- console.log('Command executed!')
244
- }
245
- }
246
- }
247
-
248
- // prepare a Map of sub-commands with lazy-loaded commands
249
- const subCommands = new Map()
250
- subCommands.set('lazy', lazyCommand)
251
-
252
- // run the CLI with lazy-loaded commands
253
- await cli(
254
- process.argv.slice(2),
255
- { name: 'main', run: () => {} },
256
- {
257
- name: 'my-app',
258
- subCommands
259
- }
260
- )
261
- ```
262
-
263
- For more detailed examples, check out the [playground/lazy-async](https://github.com/kazupon/gunshi/tree/main/playground/lazy-async) in the repository.
264
-
265
- ### 📜 Auto Usage Generation
266
-
267
- Gunshi automatically generates usage information:
268
-
269
- ```js
270
- import { cli } from 'gunshi'
271
-
272
- const command = {
273
- name: 'app',
274
- description: 'My application',
275
- options: {
276
- path: {
277
- type: 'string',
278
- short: 'p',
279
- description: 'File or directory path'
280
- },
281
- recursive: {
282
- type: 'boolean',
283
- short: 'r',
284
- description: 'Operate recursively on directories'
285
- },
286
- operation: {
287
- type: 'string',
288
- short: 'o',
289
- required: true,
290
- description: 'Operation to perform (list, copy, move, delete)'
291
- }
292
- },
293
- // define examples
294
- examples: '# Example\n$ my-app --operation list --path ./src',
295
- run: ctx => {
296
- // command implementation
297
- }
298
- }
299
-
300
- // run with --help to see the automatically generated usage information
301
- await cli(process.argv.slice(2), command, {
302
- name: 'my-app',
303
- version: '1.0.0'
304
- })
305
- ```
306
-
307
- For more detailed examples, check out the [playground/auto-usage](https://github.com/kazupon/gunshi/tree/main/playground/auto-usage) in the repository.
308
-
309
- ### 🎨 Custom Usage Generation
310
-
311
- Customize the usage message generation:
312
-
313
- ```js
314
- import { cli } from 'gunshi'
315
-
316
- // define custom header renderer
317
- const customHeaderRenderer = ctx => {
318
- return Promise.resolve(`
319
- ╔═══════════════════════╗
320
- ║ ${ctx.env.name.toUpperCase()} ║
321
- ╚═══════════════════════╝
322
- ${ctx.env.description}
323
- Version: ${ctx.env.version}
324
- `)
325
- }
326
-
327
- // define custom usage renderer
328
- const customUsageRenderer = ctx => {
329
- const lines = []
330
- lines.push('USAGE:')
331
- lines.push(` $ ${ctx.env.name} [options]`)
332
- lines.push('')
333
- lines.push('OPTIONS:')
334
-
335
- for (const [key, option] of Object.entries(ctx.options || Object.create(null))) {
336
- const shortFlag = option.short ? `-${option.short}, ` : ' '
337
- lines.push(` ${shortFlag}--${key.padEnd(10)} ${ctx.translate(key)}`)
338
- }
339
-
340
- return Promise.resolve(lines.join('\n'))
341
- }
342
-
343
- // run with custom renderers
344
- await cli(
345
- process.argv.slice(2),
346
- { name: 'app', run: () => {} },
347
- {
348
- name: 'my-app',
349
- version: '1.0.0',
350
- description: 'My application',
351
- renderHeader: customHeaderRenderer,
352
- renderUsage: customUsageRenderer
353
- }
354
- )
355
- ```
356
-
357
- For more detailed examples, check out the [playground/custom-usage](https://github.com/kazupon/gunshi/tree/main/playground/custom-usage) in the repository.
358
-
359
- ### 🌍 Internationalization
360
-
361
- Support internationalization:
362
-
363
- ```js
364
- import { cli } from 'gunshi'
365
- import enUS from './locales/en-US.json' with { type: 'json' }
366
-
367
- const command = {
368
- name: 'greeter',
369
- options: {
370
- name: {
371
- type: 'string',
372
- short: 'n'
373
- },
374
- formal: {
375
- type: 'boolean',
376
- short: 'f'
377
- }
378
- },
379
- // resource fetcher for translations
380
- resource: async ctx => {
381
- if (ctx.locale.toString() === 'ja-JP') {
382
- const resource = await import('./locales/ja-JP.json', { with: { type: 'json' } })
383
- return resource.default
384
- }
385
-
386
- // default to English
387
- return enUS
388
- },
389
- run: ctx => {
390
- const { name = 'World', formal } = ctx.values
391
- const greeting = formal ? ctx.translate('formal_greeting') : ctx.translate('informal_greeting')
392
- console.log(`${greeting}, ${name}!`)
393
- }
394
- }
395
-
396
- // run with locale support
397
- await cli(process.argv.slice(2), command, {
398
- name: 'my-app',
399
- version: '1.0.0',
400
- // set the locale via an environment variable
401
- // if Node v21 or later is used, you can use the built-in `navigator.language` instead)
402
- locale: new Intl.Locale(process.env.MY_LOCALE || 'en-US')
403
- })
404
- ```
405
-
406
- For more detailed examples, check out the [playground/i18n](https://github.com/kazupon/gunshi/tree/main/playground/i18n) in the repository.
97
+ About more details and usage, see [documentations](https://gunshi.dev)
407
98
 
408
99
  ## 💁‍♀️ Showcases
409
100
 
@@ -423,6 +114,16 @@ This project is inspired and powered by:
423
114
 
424
115
  Thank you!
425
116
 
117
+ ## 🤝 Sponsors
118
+
119
+ The development of Gunish is supported by my OSS sponsors!
120
+
121
+ <p align="center">
122
+ <a href="https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg">
123
+ <img src='https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg'/>
124
+ </a>
125
+ </p>
126
+
426
127
  ## ©️ License
427
128
 
428
129
  [MIT](http://opensource.org/licenses/MIT)
@@ -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 } from "./renderer-DAUAIZxV.js";
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";
2
2
  import { parseArgs, resolveArgs } from "args-tokens";
3
3
 
4
4
  //#region src/locales/en-US.json
@@ -60,7 +60,7 @@ var DefaultTranslation = class {
60
60
  //#endregion
61
61
  //#region src/context.ts
62
62
  const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
63
- async function createCommandContext({ options, values, positionals, command, commandOptions, omitted = false }) {
63
+ async function createCommandContext({ options, values, positionals, args, tokens, command, commandOptions, omitted = false }) {
64
64
  /**
65
65
  * normailize the options schema and values, to avoid prototype pollution
66
66
  */
@@ -121,6 +121,8 @@ async function createCommandContext({ options, values, positionals, command, com
121
121
  options: _options,
122
122
  values,
123
123
  positionals,
124
+ _: args,
125
+ tokens,
124
126
  log: commandOptions.usageSilent ? NOOP : log,
125
127
  loadCommands,
126
128
  translate
@@ -133,7 +135,7 @@ async function createCommandContext({ options, values, positionals, command, com
133
135
  return [key, description];
134
136
  });
135
137
  const defaultCommandResource = loadedOptionsResources.reduce((res, [key, value]) => {
136
- res[key] = value;
138
+ res[resolveOptionKey(key)] = value;
137
139
  return res;
138
140
  }, create());
139
141
  defaultCommandResource.description = command.description || "";
@@ -179,6 +181,8 @@ async function cli(args, entry, opts = {}) {
179
181
  options,
180
182
  values,
181
183
  positionals,
184
+ args,
185
+ tokens,
182
186
  omitted,
183
187
  command,
184
188
  commandOptions: resolvedCommandOptions
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/definition.ts
3
+ function define(definition) {
4
+ return definition;
5
+ }
6
+
7
+ //#endregion
8
+ export { define };
@@ -0,0 +1,8 @@
1
+ import { Command } from "./types.d-CftFdhAF.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues as ArgValues$1 } from "args-tokens";
3
+
4
+ //#region lib/.tsdown-types-es/definition.d.ts
5
+ declare function define<Options extends ArgOptions = ArgOptions>(definition: Command<Options>): Command<Options>;
6
+
7
+ //#endregion
8
+ export { ArgOptionSchema, ArgOptions$1 as ArgOptions, ArgValues$1 as ArgValues, define };
@@ -0,0 +1,4 @@
1
+ import "./types.d-CftFdhAF.js";
2
+ import { ArgOptionSchema, ArgOptions, ArgValues, define } from "./definition.d-CFbYyc6i.js";
3
+
4
+ export { ArgOptionSchema, ArgOptions, ArgValues, define };
@@ -0,0 +1,3 @@
1
+ import { define } from "./definition-by5EpPkZ.js";
2
+
3
+ export { define };
@@ -1,13 +1,8 @@
1
- import { ArgOptions } from 'args-tokens';
2
- import { C as Command, a as CommandOptions } from './types.d-DIY9YbHU.js';
1
+ import { Command, CommandOptions } from "./types.d-CftFdhAF.js";
2
+ import { ArgOptions } from "args-tokens";
3
3
 
4
- /**
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
- */
4
+ //#region lib/.tsdown-types-es/generator.d.ts
11
5
  declare function generate<Options extends ArgOptions = ArgOptions>(command: string | null, entry: Command<Options>, opts?: CommandOptions<Options>): Promise<string>;
12
6
 
13
- export { generate };
7
+ //#endregion
8
+ export { generate };
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
- import { create } from "./renderer-DAUAIZxV.js";
2
- import { cli } from "./cli-C-y15OeH.js";
1
+ import { create } from "./renderer-B2JVfepJ.js";
2
+ import { cli } from "./cli-DsMmOiVc.js";
3
3
 
4
4
  //#region src/generator.ts
5
5
  async function generate(command, entry, opts = {}) {
package/lib/index.d.ts CHANGED
@@ -1,17 +1,12 @@
1
- import { ArgOptions } from 'args-tokens';
2
- export { ArgOptionSchema, ArgOptions, ArgValues } from 'args-tokens';
3
- import { C as Command, b as CommandRunner, a as CommandOptions, T as TranslationAdapter, c as TranslationAdapterFactoryOptions } from './types.d-DIY9YbHU.js';
4
- export { f as CommandBuiltinKeys, d as CommandBuiltinOptionsKeys, e as CommandBuiltinResourceKeys, h as CommandContext, g as CommandEnvironment, i as CommandResource, j as CommandResourceFetcher, l as Commandable, D as DEFAULT_LOCALE, G as GenerateNamespacedKey, L as LazyCommand, k as TranslationAdapterFactory } from './types.d-DIY9YbHU.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-CftFdhAF.js";
2
+ import { define } from "./definition.d-CFbYyc6i.js";
3
+ import { ArgOptionSchema, ArgOptions, ArgOptions as ArgOptions$1, ArgValues, parseArgs, resolveArgs } from "args-tokens";
5
4
 
6
- /**
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 = ArgOptions>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
5
+ //#region lib/.tsdown-types-es/cli.d.ts
6
+ declare function cli<Options extends ArgOptions$1 = ArgOptions$1>(args: string[], entry: Command<Options> | CommandRunner<Options>, opts?: CommandOptions<Options>): Promise<string | undefined>;
14
7
 
8
+ //#endregion
9
+ //#region lib/.tsdown-types-es/translation.d.ts
15
10
  declare class DefaultTranslation implements TranslationAdapter {
16
11
  #private;
17
12
  constructor(options: TranslationAdapterFactoryOptions);
@@ -21,4 +16,5 @@ declare class DefaultTranslation implements TranslationAdapter {
21
16
  translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
22
17
  }
23
18
 
24
- export { Command, CommandOptions, CommandRunner, DefaultTranslation, TranslationAdapter, TranslationAdapterFactoryOptions, cli };
19
+ //#endregion
20
+ 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,4 +1,6 @@
1
- import { DEFAULT_LOCALE } from "./renderer-DAUAIZxV.js";
2
- import { DefaultTranslation, cli } from "./cli-C-y15OeH.js";
1
+ import { define } from "./definition-by5EpPkZ.js";
2
+ import { DEFAULT_LOCALE } from "./renderer-B2JVfepJ.js";
3
+ import { DefaultTranslation, cli } from "./cli-DsMmOiVc.js";
4
+ import { parseArgs, resolveArgs } from "args-tokens";
3
5
 
4
- export { DEFAULT_LOCALE, DefaultTranslation, cli };
6
+ export { DEFAULT_LOCALE, DefaultTranslation, cli, define, parseArgs, resolveArgs };
@@ -1,26 +1,16 @@
1
- import { ArgOptions } from 'args-tokens';
2
- import { h as CommandContext } from '../types.d-DIY9YbHU.js';
1
+ import { CommandContext } from "../types.d-CftFdhAF.js";
2
+ import { ArgOptions } from "args-tokens";
3
3
 
4
- /**
5
- * Render the header.
6
- * @param ctx A {@link CommandContext | command context}
7
- * @returns A rendered header.
8
- */
4
+ //#region lib/.tsdown-types-es/renderer/header.d.ts
9
5
  declare function renderHeader<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
10
6
 
11
- /**
12
- * Render the usage.
13
- * @param ctx A {@link CommandContext | command context}
14
- * @returns A rendered usage.
15
- */
7
+ //#endregion
8
+ //#region lib/.tsdown-types-es/renderer/usage.d.ts
16
9
  declare function renderUsage<Options extends ArgOptions = ArgOptions>(ctx: Readonly<CommandContext<Options>>): Promise<string>;
17
10
 
18
- /**
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
- */
11
+ //#endregion
12
+ //#region lib/.tsdown-types-es/renderer/validation.d.ts
24
13
  declare function renderValidationErrors<Options extends ArgOptions = ArgOptions>(_ctx: CommandContext<Options>, error: AggregateError): Promise<string>;
25
14
 
26
- export { renderHeader, renderUsage, renderValidationErrors };
15
+ //#endregion
16
+ export { renderHeader, renderUsage, renderValidationErrors };
@@ -1,3 +1,3 @@
1
- import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-DAUAIZxV.js";
1
+ import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-B2JVfepJ.js";
2
2
 
3
3
  export { renderHeader, renderUsage, renderValidationErrors };
@@ -2,6 +2,7 @@
2
2
  //#region src/constants.ts
3
3
  const DEFAULT_LOCALE = "en-US";
4
4
  const BUILT_IN_PREFIX = "_";
5
+ const OPTION_PREFIX = "Option";
5
6
  const BUILT_IN_KEY_SEPARATOR = ":";
6
7
  const NOOP = () => {};
7
8
  const COMMON_OPTIONS = {
@@ -42,6 +43,9 @@ async function resolveLazyCommand(cmd, name) {
42
43
  function resolveBuiltInKey(key) {
43
44
  return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
44
45
  }
46
+ function resolveOptionKey(key) {
47
+ return `${OPTION_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
48
+ }
45
49
  function mapResourceWithBuiltinKey(resource) {
46
50
  return Object.entries(resource).reduce((acc, [key, value]) => {
47
51
  acc[resolveBuiltInKey(key)] = value;
@@ -244,7 +248,7 @@ async function generateOptionsUsage(ctx, optionsPairs) {
244
248
  const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
245
249
  const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key, _]) => ctx.options[key].type.length)) : 0;
246
250
  const usages = await Promise.all(Object.entries(optionsPairs).map(([key, value]) => {
247
- const rawDesc = ctx.translate(key);
251
+ const rawDesc = ctx.translate(resolveOptionKey(key));
248
252
  const optionsSchema = ctx.env.usageOptionType ? `[${ctx.options[key].type}] ` : "";
249
253
  const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
250
254
  const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}`;
@@ -262,4 +266,4 @@ function renderValidationErrors(_ctx, error) {
262
266
  }
263
267
 
264
268
  //#endregion
265
- export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand };
269
+ export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, renderHeader, renderUsage, renderValidationErrors, resolveLazyCommand, resolveOptionKey };
@@ -1,71 +1,24 @@
1
- import { ArgOptions, ArgValues } from 'args-tokens';
1
+ import { ArgOptions, ArgToken, ArgValues } from "args-tokens";
2
2
 
3
- /**
4
- * The default locale string, which format is BCP 47 language tag.
5
- */
3
+ //#region lib/.tsdown-types-es/constants.d.ts
6
4
  declare const DEFAULT_LOCALE = "en-US";
7
5
  declare const BUILT_IN_PREFIX = "_";
6
+ declare const OPTION_PREFIX = "Option";
8
7
  declare const BUILT_IN_KEY_SEPARATOR = ":";
9
- declare const NOOP: () => void;
10
- type CommonOptionType = {
11
- readonly help: {
12
- readonly type: "boolean"
13
- readonly short: "h"
14
- readonly description: string
15
- }
16
- readonly version: {
17
- readonly type: "boolean"
18
- readonly short: "v"
19
- readonly description: string
20
- }
21
- };
22
- declare const COMMON_OPTIONS: CommonOptionType;
23
- declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<ArgOptions>;
24
- declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "OPTIONS", "EXAMPLES", "FORMORE"];
25
-
26
- declare const __constants_ts_BUILT_IN_KEY_SEPARATOR: typeof BUILT_IN_KEY_SEPARATOR;
27
- declare const __constants_ts_BUILT_IN_PREFIX: typeof BUILT_IN_PREFIX;
28
- declare const __constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS: typeof COMMAND_BUILTIN_RESOURCE_KEYS;
29
- declare const __constants_ts_COMMAND_OPTIONS_DEFAULT: typeof COMMAND_OPTIONS_DEFAULT;
30
- declare const __constants_ts_COMMON_OPTIONS: typeof COMMON_OPTIONS;
31
- declare const __constants_ts_DEFAULT_LOCALE: typeof DEFAULT_LOCALE;
32
- declare const __constants_ts_NOOP: typeof NOOP;
33
- declare namespace __constants_ts {
34
- export {
35
- __constants_ts_BUILT_IN_KEY_SEPARATOR as BUILT_IN_KEY_SEPARATOR,
36
- __constants_ts_BUILT_IN_PREFIX as BUILT_IN_PREFIX,
37
- __constants_ts_COMMAND_BUILTIN_RESOURCE_KEYS as COMMAND_BUILTIN_RESOURCE_KEYS,
38
- __constants_ts_COMMAND_OPTIONS_DEFAULT as COMMAND_OPTIONS_DEFAULT,
39
- __constants_ts_COMMON_OPTIONS as COMMON_OPTIONS,
40
- __constants_ts_DEFAULT_LOCALE as DEFAULT_LOCALE,
41
- __constants_ts_NOOP as NOOP,
42
- };
43
- }
44
8
 
45
- /**
46
- * Define a promise type that can be await from T.
47
- */
9
+ //#endregion
10
+ //#region lib/.tsdown-types-es/types.d.ts
48
11
  type Awaitable<T> = T | Promise<T>;
12
+ type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K] : T[K] };
13
+ type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T] : T[K] }>;
49
14
  type GenerateNamespacedKey<
50
15
  Key extends string,
51
16
  Prefixed extends string = typeof BUILT_IN_PREFIX
52
17
  > = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
53
- /**
54
- * Command i18n built-in options keys.
55
- */
56
- type CommandBuiltinOptionsKeys = keyof (typeof __constants_ts)["COMMON_OPTIONS"];
57
- /**
58
- * Command i18n built-in resource keys.
59
- */
60
- type CommandBuiltinResourceKeys = (typeof __constants_ts)["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
- */
18
+ type CommandBuiltinOptionsKeys = keyof (typeof import("./constants.ts"))["COMMON_OPTIONS"];
19
+ type CommandBuiltinResourceKeys = (typeof import("./constants.ts"))["COMMAND_BUILTIN_RESOURCE_KEYS"][number];
65
20
  type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinOptionsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | "description" | "examples";
66
- /**
67
- * Command environment.
68
- */
21
+ type CommandOptionKeys<Options extends ArgOptions> = GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>;
69
22
  interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
70
23
  /**
71
24
  * Current working directory.
@@ -130,9 +83,6 @@ interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
130
83
  */
131
84
  renderValidationErrors: ((ctx: CommandContext<Options>, error: AggregateError) => Promise<string>) | null | undefined;
132
85
  }
133
- /**
134
- * Command options.
135
- */
136
86
  interface CommandOptions<Options extends ArgOptions = ArgOptions> {
137
87
  /**
138
88
  * Current working directory.
@@ -192,10 +142,6 @@ interface CommandOptions<Options extends ArgOptions = ArgOptions> {
192
142
  */
193
143
  translationAdapterFactory?: TranslationAdapterFactory;
194
144
  }
195
- /**
196
- * Command context.
197
- * Command context is the context of the command execution.
198
- */
199
145
  interface CommandContext<
200
146
  Options extends ArgOptions = ArgOptions,
201
147
  Values = ArgValues<Options>
@@ -235,6 +181,15 @@ interface CommandContext<
235
181
  */
236
182
  positionals: string[];
237
183
  /**
184
+ * Original command line arguments.
185
+ * This argument is passed from `cli` function.
186
+ */
187
+ _: string[];
188
+ /**
189
+ * Argument tokens, that is parsed by `parseArgs` function.
190
+ */
191
+ tokens: ArgToken[];
192
+ /**
238
193
  * Whether the currently executing command has been executed with the sub-command name omitted.
239
194
  */
240
195
  omitted: boolean;
@@ -259,12 +214,10 @@ interface CommandContext<
259
214
  */
260
215
  translate: <
261
216
  T extends string = CommandBuiltinKeys,
262
- Key = CommandBuiltinKeys | keyof Options | T
217
+ O = CommandOptionKeys<Options>,
218
+ Key = CommandBuiltinKeys | O | T
263
219
  >(key: Key, values?: Record<string, unknown>) => string;
264
220
  }
265
- /**
266
- * Command interface.
267
- */
268
221
  interface Command<Options extends ArgOptions = ArgOptions> {
269
222
  /**
270
223
  * Command name.
@@ -295,9 +248,6 @@ interface Command<Options extends ArgOptions = ArgOptions> {
295
248
  */
296
249
  resource?: CommandResourceFetcher<Options>;
297
250
  }
298
- /**
299
- * Command resource.
300
- */
301
251
  type CommandResource<Options extends ArgOptions = ArgOptions> = {
302
252
  /**
303
253
  * Command description.
@@ -307,25 +257,14 @@ type CommandResource<Options extends ArgOptions = ArgOptions> = {
307
257
  * Examples usage.
308
258
  */
309
259
  examples: string
310
- } & { [Option in keyof Options] : string } & {
260
+ } & { [Option in GenerateNamespacedKey<keyof RemovedIndex<Options>, typeof OPTION_PREFIX>] : string } & {
311
261
  [key: string]: string
312
262
  };
313
- /**
314
- * Command resource fetcher.
315
- * @param ctx A {@link CommandContext | command context}
316
- * @returns A fetched {@link CommandResource | command resource}.
317
- */
318
263
  type CommandResourceFetcher<
319
264
  Options extends ArgOptions = ArgOptions,
320
265
  Values = ArgValues<Options>
321
266
  > = (ctx: Readonly<CommandContext<Options, Values>>) => Promise<CommandResource<Options>>;
322
- /**
323
- * Translation adapter factory.
324
- */
325
267
  type TranslationAdapterFactory = (options: TranslationAdapterFactoryOptions) => TranslationAdapter;
326
- /**
327
- * Translation adapter factory options.
328
- */
329
268
  interface TranslationAdapterFactoryOptions {
330
269
  /**
331
270
  * A locale.
@@ -336,11 +275,6 @@ interface TranslationAdapterFactoryOptions {
336
275
  */
337
276
  fallbackLocale: string;
338
277
  }
339
- /**
340
- * Translation adapter.
341
- * 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.
342
- * This adapter will support localization with your preferred message format.
343
- */
344
278
  interface TranslationAdapter<MessageResource = string> {
345
279
  /**
346
280
  * Get a resource of locale.
@@ -370,20 +304,9 @@ interface TranslationAdapter<MessageResource = string> {
370
304
  */
371
305
  translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
372
306
  }
373
- /**
374
- * Command runner.
375
- * @param ctx A {@link CommandContext | command context}
376
- */
377
307
  type CommandRunner<Options extends ArgOptions = ArgOptions> = (ctx: Readonly<CommandContext<Options>>) => Awaitable<void>;
378
- /**
379
- * Lazy command interface.
380
- * Lazy command that's not loaded until it is executed.
381
- */
382
308
  type LazyCommand<Options extends ArgOptions = ArgOptions> = () => Awaitable<Command<Options>>;
383
- /**
384
- * Define a command type.
385
- */
386
309
  type Commandable<Options extends ArgOptions> = Command<Options> | LazyCommand<Options>;
387
310
 
388
- export { DEFAULT_LOCALE as D };
389
- export type { Command as C, GenerateNamespacedKey as G, LazyCommand as L, TranslationAdapter as T, CommandOptions as a, CommandRunner as b, TranslationAdapterFactoryOptions as c, CommandBuiltinOptionsKeys as d, CommandBuiltinResourceKeys as e, CommandBuiltinKeys as f, CommandEnvironment as g, CommandContext as h, CommandResource as i, CommandResourceFetcher as j, TranslationAdapterFactory as k, Commandable as l };
311
+ //#endregion
312
+ 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.12.0",
4
+ "version": "0.14.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -41,6 +41,12 @@
41
41
  "require": "./lib/index.js",
42
42
  "default": "./lib/index.js"
43
43
  },
44
+ "./definition": {
45
+ "types": "./lib/definition.d.ts",
46
+ "import": "./lib/definition.js",
47
+ "require": "./lib/definition.js",
48
+ "default": "./lib/definition.js"
49
+ },
44
50
  "./renderer": {
45
51
  "types": "./lib/renderer/index.d.ts",
46
52
  "import": "./lib/renderer/index.js",
@@ -87,15 +93,17 @@
87
93
  "eslint-plugin-regexp": "^2.7.0",
88
94
  "eslint-plugin-unicorn": "^58.0.0",
89
95
  "eslint-plugin-unused-imports": "^4.1.4",
96
+ "eslint-plugin-vue": "^10.0.0",
97
+ "eslint-plugin-vue-composable": "^1.0.0",
90
98
  "eslint-plugin-yml": "^1.17.0",
91
99
  "gh-changelogen": "^0.2.8",
92
100
  "jsr": "^0.13.4",
93
101
  "knip": "^5.46.3",
94
102
  "lint-staged": "^15.5.0",
95
103
  "messageformat": "4.0.0-10",
96
- "pkg-pr-new": "^0.0.41",
104
+ "pkg-pr-new": "^0.0.42",
97
105
  "prettier": "^3.5.3",
98
- "tsdown": "^0.6.10",
106
+ "tsdown": "^0.7.0",
99
107
  "typedoc": "^0.28.1",
100
108
  "typedoc-plugin-markdown": "^4.6.0",
101
109
  "typedoc-vitepress-theme": "^1.1.2",
@@ -103,8 +111,9 @@
103
111
  "typescript-eslint": "^8.28.0",
104
112
  "vitepress": "^1.6.3",
105
113
  "vitepress-plugin-group-icons": "^1.3.8",
106
- "vitepress-plugin-llms": "^0.0.21",
107
- "vitest": "^3.0.9"
114
+ "vitepress-plugin-llms": "^0.0.22",
115
+ "vitest": "^3.0.9",
116
+ "vue": "^3.5.13"
108
117
  },
109
118
  "prettier": "@kazupon/prettier-config",
110
119
  "lint-staged": {