gunshi 0.27.0-beta.2 → 0.27.0-beta.4
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 +27 -1
- package/lib/bone.d.ts +5 -1
- package/lib/bone.js +7 -3
- package/lib/{cli-B121JwoR.js → cli-CTN-xtKX.js} +45 -4
- package/lib/{context-C7rkDQK3.d.ts → context-CMrZI9J4.d.ts} +2 -2
- package/lib/{context-CaqWZ3MF.js → context-DRQZ3doU.js} +17 -2
- package/lib/context.d.ts +2 -2
- package/lib/context.js +2 -2
- package/lib/{core-clRbigv-.js → core-D15eimMG.js} +11 -7
- package/lib/{definition-BPAFRYmH.d.ts → definition-BWGhvqMF.d.ts} +20 -16
- package/lib/{definition-qbPc8FcH.js → definition-D5821Sur.js} +1 -1
- package/lib/definition.d.ts +3 -3
- package/lib/definition.js +3 -3
- package/lib/generator.d.ts +1 -1
- package/lib/generator.js +20 -6
- package/lib/index-BDRk6VtJ.d.ts +158 -0
- package/lib/index.d.ts +7 -161
- package/lib/index.js +7 -7
- package/lib/{plugin-BRVcC8lF.js → plugin-bQlPfOlH.js} +1 -1
- package/lib/plugin-gv9ogu9N.d.ts +11 -0
- package/lib/plugin.d.ts +4 -4
- package/lib/plugin.js +3 -3
- package/lib/renderer.d.ts +10 -2
- package/lib/renderer.js +4 -4
- package/lib/{src-hz2EqFqR.js → src-DZnfAAwF.js} +63 -30
- package/lib/{types-DpGOiC0p.d.ts → types-DIfsK4mZ.d.ts} +16 -12
- package/lib/utils-BVBpgaJv.d.ts +50 -0
- package/lib/{utils-Bh4TdPy8.js → utils-DA31tfdY.js} +1 -1
- package/lib/utils.d.ts +2 -45
- package/lib/utils.js +1 -1
- package/package.json +10 -10
- package/lib/constants-BX52JB9x.d.ts +0 -8
package/README.md
CHANGED
|
@@ -28,8 +28,15 @@ Gunshi is designed to simplify the creation of modern command-line interfaces:
|
|
|
28
28
|
- 🌍 **Internationalization**: Built with global users in mind, featuring locale-aware design, resource management, and multi-language support.
|
|
29
29
|
- 🔌 **Pluggable**: Extensible plugin system with dependency management and lifecycle hooks for modular CLI development.
|
|
30
30
|
|
|
31
|
+
## 📡 Status
|
|
32
|
+
|
|
33
|
+
- v0.26.3: stable
|
|
34
|
+
- v0.27: beta
|
|
35
|
+
|
|
31
36
|
## 💿 Installation
|
|
32
37
|
|
|
38
|
+
### Stable
|
|
39
|
+
|
|
33
40
|
```sh
|
|
34
41
|
# npm
|
|
35
42
|
npm install --save gunshi
|
|
@@ -41,12 +48,31 @@ pnpm add gunshi
|
|
|
41
48
|
yarn add gunshi
|
|
42
49
|
|
|
43
50
|
## deno
|
|
44
|
-
deno add jsr:@
|
|
51
|
+
deno add jsr:@gunshi/gunshi
|
|
45
52
|
|
|
46
53
|
## bun
|
|
47
54
|
bun add gunshi
|
|
48
55
|
```
|
|
49
56
|
|
|
57
|
+
### v0.27 Beta
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
# npm
|
|
61
|
+
npm install --save gunshi@beta
|
|
62
|
+
|
|
63
|
+
## pnpm
|
|
64
|
+
pnpm add gunshi@beta
|
|
65
|
+
|
|
66
|
+
## yarn
|
|
67
|
+
yarn add gunshi@beta
|
|
68
|
+
|
|
69
|
+
## deno (you can specify version with `@`)
|
|
70
|
+
deno add jsr:@gunshi/gunshi@0.27.2
|
|
71
|
+
|
|
72
|
+
## bun
|
|
73
|
+
bun add gunshi@beta
|
|
74
|
+
```
|
|
75
|
+
|
|
50
76
|
## 🚀 Usage
|
|
51
77
|
|
|
52
78
|
```js
|
package/lib/bone.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as ValidationErrorsDecorator, C as GunshiParams, D as Prettify, E as NormalizeToGunshiParams, O as RendererDecorator, S as ExtractExtensions, T as LazyCommand, _ as Commandable, a as Awaitable, b as ExtractArgExplicitlyProvided, c as CommandCallMode, d as CommandContextExtension, f as CommandDecorator, g as CommandRunner, h as CommandLoader, i as Args, k as RenderingOptions, l as CommandContext, m as CommandExamplesFetcher, n as ArgToken, o as CliOptions, p as CommandEnvironment, r as ArgValues, s as Command, t as ArgSchema, u as CommandContextCore, v as DefaultGunshiParams, w as GunshiParamsConstraint, x as ExtractArgs, y as ExtendContext } from "./types-DIfsK4mZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/cli/bone.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Run the command.
|
package/lib/bone.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import "./utils-
|
|
3
|
-
import { cliCore } from "./core-
|
|
1
|
+
import "./context-DRQZ3doU.js";
|
|
2
|
+
import "./utils-DA31tfdY.js";
|
|
3
|
+
import { t as cliCore } from "./core-D15eimMG.js";
|
|
4
4
|
|
|
5
5
|
//#region src/cli/bone.ts
|
|
6
6
|
/**
|
|
7
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
7
11
|
* Run the command.
|
|
8
12
|
*
|
|
9
13
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { cliCore } from "./core-
|
|
2
|
-
import { plugin } from "./plugin-
|
|
3
|
-
import {
|
|
1
|
+
import { t as cliCore } from "./core-D15eimMG.js";
|
|
2
|
+
import { t as plugin } from "./plugin-bQlPfOlH.js";
|
|
3
|
+
import { a as namespacedId, s as COMMON_ARGS, t as renderer } from "./src-DZnfAAwF.js";
|
|
4
4
|
|
|
5
5
|
//#region ../plugin-global/src/types.ts
|
|
6
6
|
/**
|
|
7
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
8
|
+
* @license MIT
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
7
11
|
* The unique identifier for the global options plugin.
|
|
8
12
|
*/
|
|
9
13
|
const pluginId = namespacedId("global");
|
|
@@ -11,6 +15,10 @@ const pluginId = namespacedId("global");
|
|
|
11
15
|
//#endregion
|
|
12
16
|
//#region ../plugin-global/src/decorator.ts
|
|
13
17
|
/**
|
|
18
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
19
|
+
* @license MIT
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
14
22
|
* Decorator function to extend the command with global options.
|
|
15
23
|
*
|
|
16
24
|
* @param baseRunner - The base command runner
|
|
@@ -84,6 +92,35 @@ function extension(ctx) {
|
|
|
84
92
|
//#endregion
|
|
85
93
|
//#region ../plugin-global/src/index.ts
|
|
86
94
|
/**
|
|
95
|
+
* The entry point of global options plugin
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* import global from '@gunshi/plugin-global'
|
|
100
|
+
* import { cli } from 'gunshi'
|
|
101
|
+
*
|
|
102
|
+
* const entry = (ctx) => {
|
|
103
|
+
* // ...
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* await cli(process.argv.slice(2), entry, {
|
|
107
|
+
* // ...
|
|
108
|
+
*
|
|
109
|
+
* plugins: [
|
|
110
|
+
* global()
|
|
111
|
+
* ],
|
|
112
|
+
*
|
|
113
|
+
* // ...
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @module
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
121
|
+
* @license MIT
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
87
124
|
* global options plugin
|
|
88
125
|
*
|
|
89
126
|
* @returns A defined plugin as global options
|
|
@@ -103,6 +140,10 @@ function global() {
|
|
|
103
140
|
//#endregion
|
|
104
141
|
//#region src/cli/builtin.ts
|
|
105
142
|
/**
|
|
143
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
144
|
+
* @license MIT
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
106
147
|
* Run the command.
|
|
107
148
|
*
|
|
108
149
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
@@ -117,4 +158,4 @@ async function cli(args, entry, options = {}) {
|
|
|
117
158
|
}
|
|
118
159
|
|
|
119
160
|
//#endregion
|
|
120
|
-
export { cli };
|
|
161
|
+
export { cli as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as GunshiParams, T as LazyCommand, b as ExtractArgExplicitlyProvided, c as CommandCallMode, d as CommandContextExtension, i as Args, l as CommandContext, n as ArgToken, o as CliOptions, r as ArgValues, s as Command, v as DefaultGunshiParams, w as GunshiParamsConstraint, x as ExtractArgs, y as ExtendContext } from "./types-DIfsK4mZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/context.d.ts
|
|
4
4
|
|
|
@@ -94,4 +94,4 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
94
94
|
extensions: ExtractExtensions<E>;
|
|
95
95
|
}>>>>;
|
|
96
96
|
//#endregion
|
|
97
|
-
export {
|
|
97
|
+
export { ExtractExtensions as n, createCommandContext as r, CommandContextParams as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as log, n as deepFreeze, r as isLazyCommand, t as create } from "./utils-DA31tfdY.js";
|
|
2
2
|
|
|
3
3
|
//#region src/constants.ts
|
|
4
4
|
const ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
@@ -27,6 +27,21 @@ const CLI_OPTIONS_DEFAULT = {
|
|
|
27
27
|
//#endregion
|
|
28
28
|
//#region src/context.ts
|
|
29
29
|
/**
|
|
30
|
+
* The entry for gunshi context.
|
|
31
|
+
* This module is exported for the purpose of testing the command.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```js
|
|
35
|
+
* import { createCommandContext } from 'gunshi/context'
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
42
|
+
* @license MIT
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
30
45
|
* Create a command context.
|
|
31
46
|
*
|
|
32
47
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
@@ -98,4 +113,4 @@ function getCommandName(cmd) {
|
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
//#endregion
|
|
101
|
-
export { ANONYMOUS_COMMAND_NAME, CLI_OPTIONS_DEFAULT
|
|
116
|
+
export { NOOP as i, ANONYMOUS_COMMAND_NAME as n, CLI_OPTIONS_DEFAULT as r, createCommandContext as t };
|
package/lib/context.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-DIfsK4mZ.js";
|
|
2
|
+
import { n as ExtractExtensions, r as createCommandContext, t as CommandContextParams } from "./context-CMrZI9J4.js";
|
|
3
3
|
export { CommandContextParams, ExtractExtensions, createCommandContext };
|
package/lib/context.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ANONYMOUS_COMMAND_NAME, CLI_OPTIONS_DEFAULT,
|
|
2
|
-
import {
|
|
1
|
+
import { i as NOOP, n as ANONYMOUS_COMMAND_NAME, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-DRQZ3doU.js";
|
|
2
|
+
import { o as resolveLazyCommand, r as isLazyCommand, t as create } from "./utils-DA31tfdY.js";
|
|
3
3
|
import { parseArgs, resolveArgs } from "args-tokens";
|
|
4
4
|
|
|
5
5
|
//#region src/decorators.ts
|
|
6
|
-
const EMPTY_RENDERER =
|
|
6
|
+
const EMPTY_RENDERER = () => Promise.resolve("");
|
|
7
7
|
/**
|
|
8
8
|
* Factory function for creating a decorators manager.
|
|
9
9
|
*
|
|
@@ -162,6 +162,10 @@ function resolveDependencies(plugins) {
|
|
|
162
162
|
//#endregion
|
|
163
163
|
//#region src/cli/core.ts
|
|
164
164
|
/**
|
|
165
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
166
|
+
* @license MIT
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
165
169
|
* Run the command.
|
|
166
170
|
*
|
|
167
171
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
@@ -179,7 +183,7 @@ async function cliCore(argv, entry, options, plugins) {
|
|
|
179
183
|
const cliOptions = normalizeCliOptions(options, decorators, pluginContext);
|
|
180
184
|
const tokens = parseArgs(argv);
|
|
181
185
|
const subCommand = getSubCommand(tokens);
|
|
182
|
-
const { commandName: name, command, callMode } =
|
|
186
|
+
const { commandName: name, command, callMode } = resolveCommand(subCommand, entry, cliOptions);
|
|
183
187
|
if (!command) throw new Error(`Command not found: ${name || ""}`);
|
|
184
188
|
const args = resolveArguments(pluginContext, getCommandArgs(command));
|
|
185
189
|
const { explicit, values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
@@ -262,9 +266,9 @@ function getSubCommand(tokens) {
|
|
|
262
266
|
return firstToken && firstToken.kind === "positional" && firstToken.index === 0 && firstToken.value ? firstToken.value : "";
|
|
263
267
|
}
|
|
264
268
|
const CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
|
|
265
|
-
|
|
269
|
+
function resolveCommand(sub, entry, options) {
|
|
266
270
|
const omitted = !sub;
|
|
267
|
-
|
|
271
|
+
function doResolveCommand() {
|
|
268
272
|
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
|
|
269
273
|
commandName: entry.commandName,
|
|
270
274
|
command: entry,
|
|
@@ -332,4 +336,4 @@ async function executeCommand(cmd, ctx, decorators) {
|
|
|
332
336
|
}
|
|
333
337
|
|
|
334
338
|
//#endregion
|
|
335
|
-
export { cliCore };
|
|
339
|
+
export { cliCore as t };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as GunshiParams, D as Prettify, S as ExtractExtensions, T as LazyCommand, h as CommandLoader, i as Args, s as Command, v as DefaultGunshiParams, w as GunshiParamsConstraint, x as ExtractArgs, y as ExtendContext } from "./types-DIfsK4mZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Infer command properties excluding for {@link define} function
|
|
@@ -44,8 +48,8 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
44
48
|
* @param definition - A {@link Command | command} definition
|
|
45
49
|
* @returns A defined {@link Command | command}
|
|
46
50
|
*/
|
|
47
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends InferCommandProps<G> = InferCommandProps<G>>(definition: C & Command<{
|
|
48
|
-
args: A;
|
|
51
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A$1 extends Args = ExtractArgs<G>, C extends InferCommandProps<G> = InferCommandProps<G>>(definition: C & Command<{
|
|
52
|
+
args: A$1;
|
|
49
53
|
extensions: ExtractExtensions<G>;
|
|
50
54
|
}>): CommandDefinitionResult<G, C>;
|
|
51
55
|
/**
|
|
@@ -55,14 +59,14 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
55
59
|
*
|
|
56
60
|
* @internal
|
|
57
61
|
*/
|
|
58
|
-
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
59
|
-
args: A;
|
|
62
|
+
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A$1 extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
63
|
+
args: A$1;
|
|
60
64
|
extensions: DefaultExtensions;
|
|
61
65
|
}>> = {}>(definition: C & Command<{
|
|
62
|
-
args: A;
|
|
66
|
+
args: A$1;
|
|
63
67
|
extensions: DefaultExtensions;
|
|
64
68
|
}>) => CommandDefinitionResult<{
|
|
65
|
-
args: A;
|
|
69
|
+
args: A$1;
|
|
66
70
|
extensions: DefaultExtensions;
|
|
67
71
|
}, C>;
|
|
68
72
|
/**
|
|
@@ -109,11 +113,11 @@ declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWith
|
|
|
109
113
|
* @param loader - A {@link CommandLoader | command loader}
|
|
110
114
|
* @returns A {@link LazyCommand | lazy command} with loader
|
|
111
115
|
*/
|
|
112
|
-
declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
113
|
-
args: A;
|
|
116
|
+
declare function lazy<A$1 extends Args>(loader: CommandLoader<{
|
|
117
|
+
args: A$1;
|
|
114
118
|
extensions: {};
|
|
115
119
|
}>): LazyCommand<{
|
|
116
|
-
args: A;
|
|
120
|
+
args: A$1;
|
|
117
121
|
extensions: {};
|
|
118
122
|
}, {}>;
|
|
119
123
|
/**
|
|
@@ -151,17 +155,17 @@ declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
|
151
155
|
* @param definition - An optional {@link Command | command} definition
|
|
152
156
|
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
153
157
|
*/
|
|
154
|
-
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends ExtractArgs<G> = ExtractArgs<G>, D extends Partial<Command<{
|
|
155
|
-
args: A;
|
|
158
|
+
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A$1 extends ExtractArgs<G> = ExtractArgs<G>, D extends Partial<Command<{
|
|
159
|
+
args: A$1;
|
|
156
160
|
extensions: {};
|
|
157
161
|
}>> = Partial<Command<{
|
|
158
|
-
args: A;
|
|
162
|
+
args: A$1;
|
|
159
163
|
extensions: {};
|
|
160
164
|
}>>>(loader: CommandLoader<{
|
|
161
|
-
args: A;
|
|
165
|
+
args: A$1;
|
|
162
166
|
extensions: {};
|
|
163
167
|
}>, definition: D): LazyCommand<{
|
|
164
|
-
args: A;
|
|
168
|
+
args: A$1;
|
|
165
169
|
extensions: {};
|
|
166
170
|
}, D>;
|
|
167
171
|
/**
|
|
@@ -232,4 +236,4 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
232
236
|
*/
|
|
233
237
|
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<NormalizeGunshiParams<G>>;
|
|
234
238
|
//#endregion
|
|
235
|
-
export {
|
|
239
|
+
export { lazyWithTypes as i, defineWithTypes as n, lazy as r, define as t };
|
package/lib/definition.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { C as GunshiParams, T as LazyCommand, g as CommandRunner, h as CommandLoader, i as Args, r as ArgValues, s as Command, t as ArgSchema, v as DefaultGunshiParams, y as ExtendContext } from "./types-DIfsK4mZ.js";
|
|
2
|
+
import { r as createCommandContext, t as CommandContextParams } from "./context-CMrZI9J4.js";
|
|
3
|
+
import { i as lazyWithTypes, n as defineWithTypes, r as lazy, t as define } from "./definition-BWGhvqMF.js";
|
|
4
4
|
export { ArgSchema, ArgValues, Args, Command, CommandContextParams, CommandLoader, CommandRunner, DefaultGunshiParams, ExtendContext, GunshiParams, LazyCommand, createCommandContext, define, defineWithTypes, lazy, lazyWithTypes };
|
package/lib/definition.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createCommandContext } from "./context-
|
|
2
|
-
import "./utils-
|
|
3
|
-
import {
|
|
1
|
+
import { t as createCommandContext } from "./context-DRQZ3doU.js";
|
|
2
|
+
import "./utils-DA31tfdY.js";
|
|
3
|
+
import { i as lazyWithTypes, n as defineWithTypes, r as lazy, t as define } from "./definition-D5821Sur.js";
|
|
4
4
|
|
|
5
5
|
export { createCommandContext, define, defineWithTypes, lazy, lazyWithTypes };
|
package/lib/generator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliOptions, Command, DefaultGunshiParams, GunshiParamsConstraint
|
|
1
|
+
import { T as LazyCommand, o as CliOptions, s as Command, v as DefaultGunshiParams, w as GunshiParamsConstraint } from "./types-DIfsK4mZ.js";
|
|
2
2
|
|
|
3
3
|
//#region src/generator.d.ts
|
|
4
4
|
|
package/lib/generator.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import "./context-
|
|
2
|
-
import { create } from "./utils-
|
|
3
|
-
import "./core-
|
|
4
|
-
import "./plugin-
|
|
5
|
-
import "./src-
|
|
6
|
-
import { cli } from "./cli-
|
|
1
|
+
import "./context-DRQZ3doU.js";
|
|
2
|
+
import { t as create } from "./utils-DA31tfdY.js";
|
|
3
|
+
import "./core-D15eimMG.js";
|
|
4
|
+
import "./plugin-bQlPfOlH.js";
|
|
5
|
+
import "./src-DZnfAAwF.js";
|
|
6
|
+
import { t as cli } from "./cli-CTN-xtKX.js";
|
|
7
7
|
|
|
8
8
|
//#region src/generator.ts
|
|
9
9
|
/**
|
|
10
|
+
* The entry for usage generator.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* import { generate } from 'gunshi/generator'
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
21
|
+
* @license MIT
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
10
24
|
* Generate the command usage.
|
|
11
25
|
*
|
|
12
26
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command parameters.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { C as GunshiParams, T as LazyCommand, g as CommandRunner, i as Args$1, o as CliOptions, s as Command, v as DefaultGunshiParams, w as GunshiParamsConstraint, y as ExtendContext } from "./types-DIfsK4mZ.js";
|
|
2
|
+
import { parseArgs as parseArgs$1, resolveArgs as resolveArgs$1 } from "args-tokens";
|
|
3
|
+
|
|
4
|
+
//#region ../plugin-i18n/src/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Translation adapter factory options.
|
|
8
|
+
*/
|
|
9
|
+
interface TranslationAdapterFactoryOptions {
|
|
10
|
+
/**
|
|
11
|
+
* A locale (BCP 47 language tag).
|
|
12
|
+
*/
|
|
13
|
+
locale: string;
|
|
14
|
+
/**
|
|
15
|
+
* A fallback locale.
|
|
16
|
+
*
|
|
17
|
+
* @default DEFAULT_LOCALE ('en-US')
|
|
18
|
+
*/
|
|
19
|
+
fallbackLocale: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Translation adapter.
|
|
23
|
+
*
|
|
24
|
+
* 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.
|
|
25
|
+
* This adapter will support localization with your preferred message format.
|
|
26
|
+
*/
|
|
27
|
+
interface TranslationAdapter<MessageResource = string> {
|
|
28
|
+
/**
|
|
29
|
+
* Get a resource of locale.
|
|
30
|
+
*
|
|
31
|
+
* @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
|
|
32
|
+
* @returns A resource of locale. if resource not found, return `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
getResource(locale: string): Record<string, string> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Set a resource of locale.
|
|
37
|
+
*
|
|
38
|
+
* @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
|
|
39
|
+
* @param resource - A resource of locale
|
|
40
|
+
*/
|
|
41
|
+
setResource(locale: string, resource: Record<string, string>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get a message of locale.
|
|
44
|
+
*
|
|
45
|
+
* @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
|
|
46
|
+
* @param key - A key of message resource
|
|
47
|
+
* @returns A message of locale. if message not found, return `undefined`.
|
|
48
|
+
*/
|
|
49
|
+
getMessage(locale: string, key: string): MessageResource | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Translate a message.
|
|
52
|
+
*
|
|
53
|
+
* @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47)
|
|
54
|
+
* @param key - A key of message resource
|
|
55
|
+
* @param values - A values to be resolved in the message
|
|
56
|
+
* @returns A translated message, if message is not translated, return `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../plugin-i18n/src/translation.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* Default implementation of {@linkcode TranslationAdapter}.
|
|
64
|
+
*/
|
|
65
|
+
declare class DefaultTranslation implements TranslationAdapter {
|
|
66
|
+
#private;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new instance of DefaultTranslation.
|
|
69
|
+
*
|
|
70
|
+
* @param options - Options for the translation adapter, see {@linkcode TranslationAdapterFactoryOptions}
|
|
71
|
+
*/
|
|
72
|
+
constructor(options: TranslationAdapterFactoryOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Get a resource of locale.
|
|
75
|
+
*
|
|
76
|
+
* @param locale - A locale of resource (BCP 47 language tag)
|
|
77
|
+
* @returns A resource of locale. If resource not found, return `undefined`.
|
|
78
|
+
*/
|
|
79
|
+
getResource(locale: string): Record<string, string> | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Set a resource of locale.
|
|
82
|
+
*
|
|
83
|
+
* @param locale - A locale of resource (BCP 47 language tag)
|
|
84
|
+
* @param resource - A resource of locale
|
|
85
|
+
*/
|
|
86
|
+
setResource(locale: string, resource: Record<string, string>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get a message of locale.
|
|
89
|
+
*
|
|
90
|
+
* @param locale - A locale of message (BCP 47 language tag)
|
|
91
|
+
* @param key - A key of message resource
|
|
92
|
+
* @returns A message of locale. If message not found, return `undefined`.
|
|
93
|
+
*/
|
|
94
|
+
getMessage(locale: string, key: string): string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Translate a message.
|
|
97
|
+
*
|
|
98
|
+
* @param locale - A locale of message (BCP 47 language tag)
|
|
99
|
+
* @param key - A key of message resource
|
|
100
|
+
* @param values - A values to interpolate in the message
|
|
101
|
+
* @returns A translated message, if message is not translated, return `undefined`.
|
|
102
|
+
*/
|
|
103
|
+
translate(locale: string, key: string, values?: Record<string, unknown>): string | undefined;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/cli/builtin.d.ts
|
|
107
|
+
/**
|
|
108
|
+
* Run the command.
|
|
109
|
+
*
|
|
110
|
+
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
111
|
+
*
|
|
112
|
+
* @param args - Command line arguments
|
|
113
|
+
* @param entry - A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
114
|
+
* @param options - A {@link CliOptions | CLI options}
|
|
115
|
+
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
116
|
+
*/
|
|
117
|
+
declare function cli<G extends GunshiParamsConstraint>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* Run the command.
|
|
120
|
+
*
|
|
121
|
+
* @typeParam A - The type of {@linkcode Args | arguments} defined in the command and cli options.
|
|
122
|
+
*
|
|
123
|
+
* @param args - Command line arguments
|
|
124
|
+
* @param entry - A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
125
|
+
* @param options - A {@link CliOptions | CLI options}
|
|
126
|
+
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
127
|
+
*/
|
|
128
|
+
declare function cli<A extends Args$1 = Args$1, G extends GunshiParams = {
|
|
129
|
+
args: A;
|
|
130
|
+
extensions: {};
|
|
131
|
+
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Run the command.
|
|
134
|
+
*
|
|
135
|
+
* @typeParam E - An {@linkcode ExtendContext} type to specify the shape of command and cli options.
|
|
136
|
+
*
|
|
137
|
+
* @param args - Command line arguments
|
|
138
|
+
* @param entry - A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
139
|
+
* @param options - A {@link CliOptions | CLI options}
|
|
140
|
+
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
141
|
+
*/
|
|
142
|
+
declare function cli<E extends ExtendContext = ExtendContext, G extends GunshiParams = {
|
|
143
|
+
args: Args$1;
|
|
144
|
+
extensions: E;
|
|
145
|
+
}>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Run the command.
|
|
148
|
+
*
|
|
149
|
+
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
|
|
150
|
+
*
|
|
151
|
+
* @param args - Command line arguments
|
|
152
|
+
* @param entry - A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
|
|
153
|
+
* @param options - A {@link CliOptions | CLI options}
|
|
154
|
+
* @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
|
|
155
|
+
*/
|
|
156
|
+
declare function cli<G extends GunshiParams = DefaultGunshiParams>(args: string[], entry: Command<G> | CommandRunner<G> | LazyCommand<G>, options?: CliOptions<G>): Promise<string | undefined>;
|
|
157
|
+
//#endregion
|
|
158
|
+
export { DefaultTranslation as i, resolveArgs$1 as n, cli as r, parseArgs$1 as t };
|