@gunshi/plugin-completion 0.27.0-beta.3 → 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/lib/index.js +84 -28
- package/package.json +11 -11
package/lib/index.js
CHANGED
|
@@ -121,38 +121,30 @@ const ARG_NEGATABLE_PREFIX = "no-";
|
|
|
121
121
|
|
|
122
122
|
//#endregion
|
|
123
123
|
//#region ../resources/locales/en-US.json
|
|
124
|
-
var COMMAND = "COMMAND";
|
|
125
|
-
var COMMANDS = "COMMANDS";
|
|
126
|
-
var SUBCOMMAND = "SUBCOMMAND";
|
|
127
|
-
var USAGE = "USAGE";
|
|
128
|
-
var ARGUMENTS = "ARGUMENTS";
|
|
129
|
-
var OPTIONS = "OPTIONS";
|
|
130
|
-
var EXAMPLES = "EXAMPLES";
|
|
131
|
-
var FORMORE = "For more info, run any command with the `--help` flag";
|
|
132
124
|
var NEGATABLE = "Negatable of";
|
|
133
|
-
var DEFAULT = "default";
|
|
134
|
-
var CHOICES = "choices";
|
|
135
|
-
var help = "Display this help message";
|
|
136
|
-
var version = "Display this version";
|
|
137
125
|
var en_US_default = {
|
|
138
|
-
COMMAND,
|
|
139
|
-
COMMANDS,
|
|
140
|
-
SUBCOMMAND,
|
|
141
|
-
USAGE,
|
|
142
|
-
ARGUMENTS,
|
|
143
|
-
OPTIONS,
|
|
144
|
-
EXAMPLES,
|
|
145
|
-
FORMORE,
|
|
126
|
+
COMMAND: "COMMAND",
|
|
127
|
+
COMMANDS: "COMMANDS",
|
|
128
|
+
SUBCOMMAND: "SUBCOMMAND",
|
|
129
|
+
USAGE: "USAGE",
|
|
130
|
+
ARGUMENTS: "ARGUMENTS",
|
|
131
|
+
OPTIONS: "OPTIONS",
|
|
132
|
+
EXAMPLES: "EXAMPLES",
|
|
133
|
+
FORMORE: "For more info, run any command with the `--help` flag",
|
|
146
134
|
NEGATABLE,
|
|
147
|
-
DEFAULT,
|
|
148
|
-
CHOICES,
|
|
149
|
-
help,
|
|
150
|
-
version
|
|
135
|
+
DEFAULT: "default",
|
|
136
|
+
CHOICES: "choices",
|
|
137
|
+
help: "Display this help message",
|
|
138
|
+
version: "Display this version"
|
|
151
139
|
};
|
|
152
140
|
|
|
153
141
|
//#endregion
|
|
154
142
|
//#region ../shared/src/utils.ts
|
|
155
143
|
/**
|
|
144
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
145
|
+
* @license MIT
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
156
148
|
* Resolve a namespaced key for argument resources.
|
|
157
149
|
*
|
|
158
150
|
* Argument keys are prefixed with "arg:".
|
|
@@ -221,6 +213,10 @@ function makeShortLongOptionPair(schema, name, toKebab) {
|
|
|
221
213
|
//#endregion
|
|
222
214
|
//#region ../shared/src/localization.ts
|
|
223
215
|
/**
|
|
216
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
217
|
+
* @license MIT
|
|
218
|
+
*/
|
|
219
|
+
/**
|
|
224
220
|
* Create a localizable function for a command.
|
|
225
221
|
*
|
|
226
222
|
* This function will resolve the translation key based on the command context and the provided translation function.
|
|
@@ -248,7 +244,7 @@ function localizable(ctx, cmd, translate) {
|
|
|
248
244
|
}
|
|
249
245
|
const schema = ctx.args[argKey];
|
|
250
246
|
if (!schema) return argKey;
|
|
251
|
-
return negatable && schema.type === "boolean" && schema.negatable ? `${
|
|
247
|
+
return negatable && schema.type === "boolean" && schema.negatable ? `${NEGATABLE} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
|
|
252
248
|
}
|
|
253
249
|
if (key === resolveKey("description", ctx.name)) return "";
|
|
254
250
|
else if (key === resolveKey("examples", ctx.name)) return await resolveExamples(ctx, cmd.examples);
|
|
@@ -260,6 +256,10 @@ function localizable(ctx, cmd, translate) {
|
|
|
260
256
|
//#endregion
|
|
261
257
|
//#region src/types.ts
|
|
262
258
|
/**
|
|
259
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
260
|
+
* @license MIT
|
|
261
|
+
*/
|
|
262
|
+
/**
|
|
263
263
|
* The unique identifier for the completion plugin.
|
|
264
264
|
*/
|
|
265
265
|
const pluginId = namespacedId("completion");
|
|
@@ -301,6 +301,62 @@ function quoteExec() {
|
|
|
301
301
|
|
|
302
302
|
//#endregion
|
|
303
303
|
//#region src/index.ts
|
|
304
|
+
/**
|
|
305
|
+
* The entry point of completion plugin
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```js
|
|
309
|
+
* import { cli } from 'gunshi'
|
|
310
|
+
* import completion from '@gunshi/plugin-completion'
|
|
311
|
+
*
|
|
312
|
+
* const command = {
|
|
313
|
+
* name: 'deploy',
|
|
314
|
+
* args: {
|
|
315
|
+
* environment: {
|
|
316
|
+
* type: 'string',
|
|
317
|
+
* short: 'e',
|
|
318
|
+
* description: 'Target environment'
|
|
319
|
+
* },
|
|
320
|
+
* config: {
|
|
321
|
+
* type: 'string',
|
|
322
|
+
* short: 'c',
|
|
323
|
+
* description: 'Config file path'
|
|
324
|
+
* }
|
|
325
|
+
* },
|
|
326
|
+
* run: ctx => {
|
|
327
|
+
* console.log(`Deploying to ${ctx.values.environment}`)
|
|
328
|
+
* }
|
|
329
|
+
* }
|
|
330
|
+
*
|
|
331
|
+
* await cli(process.argv.slice(2), command, {
|
|
332
|
+
* name: 'my-cli',
|
|
333
|
+
* version: '1.0.0',
|
|
334
|
+
* plugins: [
|
|
335
|
+
* completion({
|
|
336
|
+
* config: {
|
|
337
|
+
* entry: {
|
|
338
|
+
* args: {
|
|
339
|
+
* config: {
|
|
340
|
+
* handler: () => [
|
|
341
|
+
* { value: 'prod.json', description: 'Production config' },
|
|
342
|
+
* { value: 'dev.json', description: 'Development config' },
|
|
343
|
+
* { value: 'test.json', description: 'Test config' }
|
|
344
|
+
* ]
|
|
345
|
+
* }
|
|
346
|
+
* }
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* })
|
|
350
|
+
* ]
|
|
351
|
+
* })
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @module
|
|
355
|
+
*/
|
|
356
|
+
/**
|
|
357
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
358
|
+
* @license MIT
|
|
359
|
+
*/
|
|
304
360
|
const TERMINATOR = "--";
|
|
305
361
|
const NOOP_HANDLER = () => {
|
|
306
362
|
return [];
|
|
@@ -323,7 +379,7 @@ function completion(options = {}) {
|
|
|
323
379
|
id: pluginId,
|
|
324
380
|
name: "completion",
|
|
325
381
|
dependencies,
|
|
326
|
-
|
|
382
|
+
setup(ctx) {
|
|
327
383
|
/**
|
|
328
384
|
* add command for completion script generation
|
|
329
385
|
*/
|
|
@@ -332,7 +388,7 @@ function completion(options = {}) {
|
|
|
332
388
|
name: completeName,
|
|
333
389
|
description: "Generate shell completion script",
|
|
334
390
|
rendering: { header: null },
|
|
335
|
-
run:
|
|
391
|
+
run: (cmdCtx) => {
|
|
336
392
|
if (!cmdCtx.env.name) throw new Error("your cli name is not defined.");
|
|
337
393
|
let shell = cmdCtx._[1];
|
|
338
394
|
if (shell === TERMINATOR) shell = void 0;
|
|
@@ -378,7 +434,7 @@ async function registerCompletion({ name, cmd, config, i18nPluginId: i18nPluginI
|
|
|
378
434
|
extensions
|
|
379
435
|
});
|
|
380
436
|
if (i18n) {
|
|
381
|
-
if (!await i18n.loadResource(i18n.locale, ctx, resolvedCmd)) console.warn(`Failed to load i18n resources for command: ${name} (${i18n.locale})`);
|
|
437
|
+
if (!await i18n.loadResource(i18n.locale, ctx, resolvedCmd)) console.warn(`Failed to load i18n resources for command: ${name} (${i18n.locale.toString()})`);
|
|
382
438
|
}
|
|
383
439
|
const localizeDescription = localizable(ctx, resolvedCmd, i18n ? i18n.translate : void 0);
|
|
384
440
|
const commandTab = isBombshellRoot ? t : t.command(name, await localizeDescription(resolveKey("description", ctx.name)) || resolvedCmd.description || "");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/plugin-completion",
|
|
3
3
|
"description": "completion plugin for gunshi",
|
|
4
|
-
"version": "0.27.0-beta.
|
|
4
|
+
"version": "0.27.0-beta.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -52,24 +52,24 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@bomb.sh/tab": "^0.0.
|
|
56
|
-
"@gunshi/plugin": "0.27.0-beta.
|
|
55
|
+
"@bomb.sh/tab": "^0.0.9",
|
|
56
|
+
"@gunshi/plugin": "0.27.0-beta.4"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@gunshi/plugin-i18n": "0.27.0-beta.
|
|
59
|
+
"@gunshi/plugin-i18n": "0.27.0-beta.4"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@types/node": "^
|
|
63
|
-
"deno": "^2.5.
|
|
62
|
+
"@types/node": "^24.10.1",
|
|
63
|
+
"deno": "^2.5.6",
|
|
64
64
|
"jsr": "^0.13.5",
|
|
65
65
|
"jsr-exports-lint": "^0.4.1",
|
|
66
|
-
"publint": "^0.3.
|
|
66
|
+
"publint": "^0.3.15",
|
|
67
67
|
"rollup-plugin-license": "^3.6.0",
|
|
68
|
-
"tsdown": "0.15.
|
|
69
|
-
"typedoc": "^0.28.
|
|
68
|
+
"tsdown": "0.15.12",
|
|
69
|
+
"typedoc": "^0.28.15",
|
|
70
70
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
71
|
-
"@gunshi/
|
|
72
|
-
"@gunshi/
|
|
71
|
+
"@gunshi/plugin-i18n": "0.27.0-beta.4",
|
|
72
|
+
"@gunshi/shared": "0.27.0-beta.4"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "tsdown",
|