gunshi 0.8.0 → 0.9.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 +10 -9
- package/lib/{context-DYokJ5k3.js → context-DeTM_Qpg.js} +3 -2
- package/lib/context.d.ts +1 -1
- package/lib/context.js +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +12 -12
- package/lib/renderer/index.d.ts +1 -1
- package/lib/renderer/index.js +2 -2
- package/lib/{renderer-KLx2dW-W.js → renderer-DIRwkoRd.js} +1 -1
- package/lib/{types.d-CX4RmDVT.d.ts → types.d-Dp0YJQNw.d.ts} +20 -1
- package/lib/{utils-CU_LSsUg.js → utils-jm146hfy.js} +12 -10
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
Gunshi is a modern javascript command-line library
|
|
12
12
|
|
|
13
|
-
> [!TIP]
|
|
13
|
+
> [!TIP] <!-- eslint-disable-line markdown/no-missing-label-refs -->
|
|
14
14
|
> gunshi (軍師) is a position in ancient Japanese samurai battle in which a samurai devised strategies and gave orders. That name is inspired by the word "command".
|
|
15
15
|
|
|
16
16
|
## ✨ Features
|
|
@@ -64,7 +64,7 @@ import { cli } from 'gunshi'
|
|
|
64
64
|
|
|
65
65
|
const args = process.argv.slice(2)
|
|
66
66
|
// run a simple command
|
|
67
|
-
cli(args, () => {
|
|
67
|
+
await cli(args, () => {
|
|
68
68
|
// something logic ...
|
|
69
69
|
console.log('Hello from Gunshi!', args)
|
|
70
70
|
})
|
|
@@ -103,7 +103,7 @@ const command = {
|
|
|
103
103
|
|
|
104
104
|
// run a command that is defined above
|
|
105
105
|
// (the 3rd argument of `cli` is the command option)
|
|
106
|
-
cli(process.argv.slice(2), command, {
|
|
106
|
+
await cli(process.argv.slice(2), command, {
|
|
107
107
|
name: 'my-app',
|
|
108
108
|
version: '1.0.0',
|
|
109
109
|
description: 'My CLI application'
|
|
@@ -201,7 +201,7 @@ const mainCommand = {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
// run the CLI with composable sub-commands
|
|
204
|
-
cli(process.argv.slice(2), mainCommand, {
|
|
204
|
+
await cli(process.argv.slice(2), mainCommand, {
|
|
205
205
|
name: 'my-app',
|
|
206
206
|
version: '1.0.0',
|
|
207
207
|
subCommands
|
|
@@ -239,7 +239,7 @@ const subCommands = new Map()
|
|
|
239
239
|
subCommands.set('lazy', lazyCommand)
|
|
240
240
|
|
|
241
241
|
// run the CLI with lazy-loaded commands
|
|
242
|
-
cli(
|
|
242
|
+
await cli(
|
|
243
243
|
process.argv.slice(2),
|
|
244
244
|
{ name: 'main', run: () => {} },
|
|
245
245
|
{
|
|
@@ -281,7 +281,7 @@ const command = {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
// run with --help to see the automatically generated usage information
|
|
284
|
-
cli(process.argv.slice(2), command, {
|
|
284
|
+
await cli(process.argv.slice(2), command, {
|
|
285
285
|
name: 'my-app',
|
|
286
286
|
version: '1.0.0'
|
|
287
287
|
})
|
|
@@ -324,7 +324,7 @@ const customUsageRenderer = ctx => {
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
// run with custom renderers
|
|
327
|
-
cli(
|
|
327
|
+
await cli(
|
|
328
328
|
process.argv.slice(2),
|
|
329
329
|
{ name: 'app', run: () => {} },
|
|
330
330
|
{
|
|
@@ -371,7 +371,7 @@ const command = {
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
// run with locale support
|
|
374
|
-
cli(process.argv.slice(2), command, {
|
|
374
|
+
await cli(process.argv.slice(2), command, {
|
|
375
375
|
name: 'my-app',
|
|
376
376
|
version: '1.0.0',
|
|
377
377
|
// set the locale via an environment variable
|
|
@@ -394,7 +394,8 @@ If you are interested in contributing to `gunshi`, I highly recommend checking o
|
|
|
394
394
|
|
|
395
395
|
This project is inspired and powered by:
|
|
396
396
|
|
|
397
|
-
- [`citty`](https://github.com/unjs/citty), created by UnJS team and contributors
|
|
397
|
+
- [`citty`](https://github.com/unjs/citty), created by [UnJS team](https://github.com/unjs) and contributors
|
|
398
|
+
- [`ordana`](https://github.com/sapphi-red/ordana), createdy by [sapphi-red](https://github.com/sapphi-red), inspired documentation generation
|
|
398
399
|
- cline and claude 3.7 sonnet, examples and docs is generated
|
|
399
400
|
|
|
400
401
|
Thank you!
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE, create, deepFreeze, mapResourceWithBuiltinKey, resolveLazyCommand } from "./utils-
|
|
1
|
+
import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveLazyCommand } from "./utils-jm146hfy.js";
|
|
2
2
|
|
|
3
3
|
//#region locales/en-US.json
|
|
4
4
|
var COMMAND = "COMMAND";
|
|
@@ -43,7 +43,7 @@ var DefaultTranslation = class {
|
|
|
43
43
|
getMessage(locale, key) {
|
|
44
44
|
const resource = this.getResource(locale);
|
|
45
45
|
if (resource) return resource[key];
|
|
46
|
-
return
|
|
46
|
+
return void 0;
|
|
47
47
|
}
|
|
48
48
|
translate(locale, key, _values = create()) {
|
|
49
49
|
/**
|
|
@@ -130,6 +130,7 @@ async function createCommandContext({ options, values, positionals, command, com
|
|
|
130
130
|
values: _values,
|
|
131
131
|
positionals,
|
|
132
132
|
usage,
|
|
133
|
+
log: commandOptions.usageSilent ? NOOP : log,
|
|
133
134
|
loadCommands,
|
|
134
135
|
translate
|
|
135
136
|
}));
|
package/lib/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArgOptions, ArgValues } from 'args-tokens';
|
|
2
|
-
import { C as Command, a as CommandOptions, b as CommandContext } from './types.d-
|
|
2
|
+
import { C as Command, a as CommandOptions, b as CommandContext } from './types.d-Dp0YJQNw.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Parameters of {@link createCommandContext}
|
package/lib/context.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ArgOptions } from 'args-tokens';
|
|
2
2
|
export { ArgOptionSchema, ArgOptions, ArgValues } from 'args-tokens';
|
|
3
|
-
import { C as Command, c as CommandRunner, a as CommandOptions, T as TranslationAdapter, d as TranslationAdapterFactoryOptions } from './types.d-
|
|
4
|
-
export { g as CommandBuiltinKeys, e as CommandBuiltinOptionsKeys, f as CommandBuiltinResourceKeys, b as CommandContext, h as CommandEnvironment, i as CommandResource, j as CommandResourceFetcher, l as Commandable, G as GenerateNamespacedKey, L as LazyCommand, k as TranslationAdapterFactory } from './types.d-
|
|
3
|
+
import { C as Command, c as CommandRunner, a as CommandOptions, T as TranslationAdapter, d as TranslationAdapterFactoryOptions } from './types.d-Dp0YJQNw.js';
|
|
4
|
+
export { g as CommandBuiltinKeys, e as CommandBuiltinOptionsKeys, f as CommandBuiltinResourceKeys, b as CommandContext, h as CommandEnvironment, i as CommandResource, j as CommandResourceFetcher, l as Commandable, G as GenerateNamespacedKey, L as LazyCommand, k as TranslationAdapterFactory } from './types.d-Dp0YJQNw.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Run the command
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DefaultTranslation, createCommandContext } from "./context-
|
|
2
|
-
import { COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, create,
|
|
3
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-
|
|
1
|
+
import { DefaultTranslation, createCommandContext } from "./context-DeTM_Qpg.js";
|
|
2
|
+
import { COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, create, resolveLazyCommand } from "./utils-jm146hfy.js";
|
|
3
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-DIRwkoRd.js";
|
|
4
4
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
5
5
|
|
|
6
6
|
//#region src/cli.ts
|
|
@@ -56,38 +56,38 @@ async function showUsage(ctx) {
|
|
|
56
56
|
if (ctx.env.renderUsage === null) return;
|
|
57
57
|
const usage = await (ctx.env.renderUsage || renderUsage)(ctx);
|
|
58
58
|
if (usage) {
|
|
59
|
-
log(usage);
|
|
59
|
+
ctx.log(usage);
|
|
60
60
|
return usage;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function showVersion(ctx) {
|
|
64
|
-
log(ctx.env.version);
|
|
64
|
+
ctx.log(ctx.env.version);
|
|
65
65
|
}
|
|
66
66
|
async function showHeader(ctx) {
|
|
67
67
|
if (ctx.env.renderHeader === null) return;
|
|
68
68
|
const header = await (ctx.env.renderHeader || renderHeader)(ctx);
|
|
69
69
|
if (header) {
|
|
70
|
-
log(header);
|
|
71
|
-
log();
|
|
70
|
+
ctx.log(header);
|
|
71
|
+
ctx.log();
|
|
72
72
|
return header;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async function showValidationErrors(ctx, error) {
|
|
76
76
|
if (ctx.env.renderValidationErrors === null) return;
|
|
77
77
|
const render = ctx.env.renderValidationErrors || renderValidationErrors;
|
|
78
|
-
log(await render(ctx, error));
|
|
78
|
+
ctx.log(await render(ctx, error));
|
|
79
79
|
}
|
|
80
80
|
async function resolveCommand(sub, entry, options) {
|
|
81
81
|
const omitted = !sub;
|
|
82
|
-
if (typeof entry === "function") return [
|
|
82
|
+
if (typeof entry === "function") return [void 0, {
|
|
83
83
|
run: entry,
|
|
84
84
|
default: true
|
|
85
85
|
}];
|
|
86
|
-
else if (omitted) return typeof entry === "object" ? [entry.name, await resolveLazyCommand(entry,
|
|
86
|
+
else if (omitted) return typeof entry === "object" ? [entry.name, await resolveLazyCommand(entry, void 0, true)] : [void 0, void 0];
|
|
87
87
|
else {
|
|
88
|
-
if (options.subCommands == null) return [sub,
|
|
88
|
+
if (options.subCommands == null) return [sub, void 0];
|
|
89
89
|
const cmd = options.subCommands?.get(sub);
|
|
90
|
-
if (cmd == null) return [sub,
|
|
90
|
+
if (cmd == null) return [sub, void 0];
|
|
91
91
|
return [sub, await resolveLazyCommand(cmd, sub)];
|
|
92
92
|
}
|
|
93
93
|
}
|
package/lib/renderer/index.d.ts
CHANGED
package/lib/renderer/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../utils-
|
|
2
|
-
import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-
|
|
1
|
+
import "../utils-jm146hfy.js";
|
|
2
|
+
import { renderHeader, renderUsage, renderValidationErrors } from "../renderer-DIRwkoRd.js";
|
|
3
3
|
|
|
4
4
|
export { renderHeader, renderUsage, renderValidationErrors };
|
|
@@ -6,6 +6,7 @@ import { ArgOptions, ArgValues } from 'args-tokens';
|
|
|
6
6
|
declare const DEFAULT_LOCALE = "en-US";
|
|
7
7
|
declare const BUILT_IN_PREFIX = "_";
|
|
8
8
|
declare const BUILT_IN_KEY_SEPARATOR = ":";
|
|
9
|
+
declare const NOOP: () => void;
|
|
9
10
|
type CommonOptionType = {
|
|
10
11
|
readonly help: {
|
|
11
12
|
readonly type: "boolean"
|
|
@@ -26,8 +27,9 @@ declare const __constants_COMMAND_BUILTIN_RESOURCE_KEYS: typeof COMMAND_BUILTIN_
|
|
|
26
27
|
declare const __constants_COMMAND_OPTIONS_DEFAULT: typeof COMMAND_OPTIONS_DEFAULT;
|
|
27
28
|
declare const __constants_COMMON_OPTIONS: typeof COMMON_OPTIONS;
|
|
28
29
|
declare const __constants_DEFAULT_LOCALE: typeof DEFAULT_LOCALE;
|
|
30
|
+
declare const __constants_NOOP: typeof NOOP;
|
|
29
31
|
declare namespace __constants {
|
|
30
|
-
export { __constants_BUILT_IN_KEY_SEPARATOR as BUILT_IN_KEY_SEPARATOR, __constants_BUILT_IN_PREFIX as BUILT_IN_PREFIX, __constants_COMMAND_BUILTIN_RESOURCE_KEYS as COMMAND_BUILTIN_RESOURCE_KEYS, __constants_COMMAND_OPTIONS_DEFAULT as COMMAND_OPTIONS_DEFAULT, __constants_COMMON_OPTIONS as COMMON_OPTIONS, __constants_DEFAULT_LOCALE as DEFAULT_LOCALE };
|
|
32
|
+
export { __constants_BUILT_IN_KEY_SEPARATOR as BUILT_IN_KEY_SEPARATOR, __constants_BUILT_IN_PREFIX as BUILT_IN_PREFIX, __constants_COMMAND_BUILTIN_RESOURCE_KEYS as COMMAND_BUILTIN_RESOURCE_KEYS, __constants_COMMAND_OPTIONS_DEFAULT as COMMAND_OPTIONS_DEFAULT, __constants_COMMON_OPTIONS as COMMON_OPTIONS, __constants_DEFAULT_LOCALE as DEFAULT_LOCALE, __constants_NOOP as NOOP };
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -98,6 +100,12 @@ interface CommandEnvironment<Options extends ArgOptions = ArgOptions> {
|
|
|
98
100
|
*/
|
|
99
101
|
usageOptionType: boolean;
|
|
100
102
|
/**
|
|
103
|
+
* Whether to display the command usage
|
|
104
|
+
* @default false
|
|
105
|
+
* @see {@link}
|
|
106
|
+
*/
|
|
107
|
+
usageSilent: boolean;
|
|
108
|
+
/**
|
|
101
109
|
* Sub commands
|
|
102
110
|
* @see {@link CommandOptions.subCommands}
|
|
103
111
|
*/
|
|
@@ -157,6 +165,10 @@ interface CommandOptions<Options extends ArgOptions = ArgOptions> {
|
|
|
157
165
|
*/
|
|
158
166
|
usageOptionType?: boolean;
|
|
159
167
|
/**
|
|
168
|
+
* Whether to display the command usage
|
|
169
|
+
*/
|
|
170
|
+
usageSilent?: boolean;
|
|
171
|
+
/**
|
|
160
172
|
* Render function the command usage
|
|
161
173
|
*/
|
|
162
174
|
renderUsage?: ((ctx: Readonly<CommandContext<Options>>) => Promise<string>) | null;
|
|
@@ -226,6 +238,13 @@ interface CommandContext<
|
|
|
226
238
|
*/
|
|
227
239
|
usage: CommandUsage<Options>;
|
|
228
240
|
/**
|
|
241
|
+
* Output a message
|
|
242
|
+
* @description if {@link CommandEnvironment.usageSilent} is true, the message is not output
|
|
243
|
+
* @param message an output message, @see {@link console.log}
|
|
244
|
+
* @param optionalParams an optional parameters, @see {@link console.log}
|
|
245
|
+
*/
|
|
246
|
+
log: (message?: any, ...optionalParams: any[]) => void;
|
|
247
|
+
/**
|
|
229
248
|
* Load sub-commands
|
|
230
249
|
* @description The loaded commands are cached and returned when called again
|
|
231
250
|
* @returns loaded commands
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const DEFAULT_LOCALE = "en-US";
|
|
4
4
|
const BUILT_IN_PREFIX = "_";
|
|
5
5
|
const BUILT_IN_KEY_SEPARATOR = ":";
|
|
6
|
+
const NOOP = () => {};
|
|
6
7
|
const COMMON_OPTIONS = {
|
|
7
8
|
help: {
|
|
8
9
|
type: "boolean",
|
|
@@ -14,18 +15,19 @@ const COMMON_OPTIONS = {
|
|
|
14
15
|
}
|
|
15
16
|
};
|
|
16
17
|
const COMMAND_OPTIONS_DEFAULT = {
|
|
17
|
-
name:
|
|
18
|
-
description:
|
|
19
|
-
version:
|
|
20
|
-
cwd:
|
|
21
|
-
|
|
18
|
+
name: void 0,
|
|
19
|
+
description: void 0,
|
|
20
|
+
version: void 0,
|
|
21
|
+
cwd: void 0,
|
|
22
|
+
usageSilent: false,
|
|
23
|
+
subCommands: void 0,
|
|
22
24
|
leftMargin: 2,
|
|
23
25
|
middleMargin: 10,
|
|
24
26
|
usageOptionType: false,
|
|
25
|
-
renderHeader:
|
|
26
|
-
renderUsage:
|
|
27
|
-
renderValidationErrors:
|
|
28
|
-
translationAdapterFactory:
|
|
27
|
+
renderHeader: void 0,
|
|
28
|
+
renderUsage: void 0,
|
|
29
|
+
renderValidationErrors: void 0,
|
|
30
|
+
translationAdapterFactory: void 0
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
//#endregion
|
|
@@ -60,4 +62,4 @@ function deepFreeze(obj) {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
//#endregion
|
|
63
|
-
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveBuiltInKey, resolveLazyCommand };
|
|
65
|
+
export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_OPTIONS, DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveBuiltInKey, resolveLazyCommand };
|
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.9.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -72,28 +72,33 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@eslint/markdown": "^6.2.2",
|
|
74
74
|
"@intlify/core": "next",
|
|
75
|
-
"@kazupon/eslint-config": "^0.
|
|
75
|
+
"@kazupon/eslint-config": "^0.26.1",
|
|
76
76
|
"@kazupon/prettier-config": "^0.1.1",
|
|
77
77
|
"@types/node": "^22.13.9",
|
|
78
78
|
"@vitest/eslint-plugin": "^1.1.36",
|
|
79
79
|
"bumpp": "^10.0.3",
|
|
80
|
-
"eslint": "^9.
|
|
80
|
+
"eslint": "^9.22.0",
|
|
81
81
|
"eslint-config-prettier": "^10.0.2",
|
|
82
|
+
"eslint-import-resolver-typescript": "^4.2.2",
|
|
83
|
+
"eslint-plugin-import": "^2.31.0",
|
|
82
84
|
"eslint-plugin-jsonc": "^2.19.1",
|
|
85
|
+
"eslint-plugin-module-interop": "^0.3.0",
|
|
83
86
|
"eslint-plugin-promise": "^7.2.1",
|
|
84
87
|
"eslint-plugin-regexp": "^2.7.0",
|
|
85
88
|
"eslint-plugin-unicorn": "^57.0.0",
|
|
89
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
86
90
|
"eslint-plugin-yml": "^1.17.0",
|
|
87
91
|
"gh-changelogen": "^0.2.8",
|
|
88
92
|
"jsr": "^0.13.4",
|
|
89
93
|
"knip": "^5.45.0",
|
|
90
94
|
"lint-staged": "^15.4.3",
|
|
91
|
-
"messageformat": "4.0.0-
|
|
95
|
+
"messageformat": "4.0.0-10",
|
|
92
96
|
"pkg-pr-new": "^0.0.41",
|
|
93
97
|
"prettier": "^3.5.3",
|
|
94
98
|
"tsdown": "^0.6.4",
|
|
95
99
|
"typescript": "^5.4.2",
|
|
96
100
|
"typescript-eslint": "^8.26.0",
|
|
101
|
+
"vitepress": "^1.6.3",
|
|
97
102
|
"vitest": "^3.0.7"
|
|
98
103
|
},
|
|
99
104
|
"prettier": "@kazupon/prettier-config",
|
|
@@ -116,6 +121,9 @@
|
|
|
116
121
|
"clean": "git clean -df",
|
|
117
122
|
"dev": "pnpx @eslint/config-inspector --config eslint.config.ts",
|
|
118
123
|
"dev:eslint": "pnpx @eslint/config-inspector --config eslint.config.ts",
|
|
124
|
+
"docs:build": "vitepress build docs",
|
|
125
|
+
"docs:dev": "vitepress dev docs",
|
|
126
|
+
"docs:preview": "vitepress preview docs",
|
|
119
127
|
"fix": "pnpm run --stream --color \"/^fix:/\"",
|
|
120
128
|
"fix:eslint": "eslint . --fix",
|
|
121
129
|
"fix:knip": "knip --fix --no-exit-code",
|