gunshi 1.0.0-beta.1 → 1.0.0-beta.2

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/bone.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cliCore } from "./core-C-EvVI4v.js";
1
+ import { t as cliCore } from "./core-D9EEP3Ac.js";
2
2
  //#region src/cli/bone.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,7 +1,7 @@
1
1
  import { a as hasPriorityValidationError } from "./error-wB83kWiv.js";
2
2
  import { t as plugin } from "./plugin-CG94VzCl.js";
3
- import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-BI37Q7Wx.js";
4
- import { t as cliCore } from "./core-C-EvVI4v.js";
3
+ import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Dr9mmkFc.js";
4
+ import { t as cliCore } from "./core-D9EEP3Ac.js";
5
5
  //#region ../plugin-global/src/types.ts
6
6
  /**
7
7
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,6 +1,6 @@
1
1
  import { i as NOOP, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CSecf6R5.js";
2
2
  import { n as kebabnize } from "./utils-CJLgPw25.js";
3
- import { create, getCommandSubCommands, isLazyCommand, resolveCommandArgs, resolveLazyCommand } from "./utils.js";
3
+ import { create, getCommandSubCommands, isLazyCommand, resolveLazyCommand } from "./utils.js";
4
4
  import { a as resolveArgs, n as ArgsValidationErrorKeys, o as parseArgs, t as ArgsValidationError } from "./resolver-CAlgxe_R-y4BytVTg.js";
5
5
  import { a as hasPriorityValidationError, i as CommandResolutionErrorKeys, n as CommandNotFoundErrorKeys, r as CommandResolutionError, t as CommandNotFoundError } from "./error-wB83kWiv.js";
6
6
  //#region src/decorators.ts
@@ -197,6 +197,47 @@ function resolveDependencies(plugins) {
197
197
  return sorted;
198
198
  }
199
199
  //#endregion
200
+ //#region src/cli/args.ts
201
+ /**
202
+ * @author kazuya kawaguchi (a.k.a. kazupon)
203
+ * @license MIT
204
+ */
205
+ /**
206
+ * Resolve the arguments of a command, the way gunshi parses and renders them.
207
+ *
208
+ * The global options belong to no command definition, so they are merged into the arguments of the
209
+ * command that runs. An argument of the command shadows the global option of the same name, and it
210
+ * shadows the same way by short name: a global option gives up its short name to an argument of the
211
+ * command that claims the same letter, and keeps its long name.
212
+ *
213
+ * NOTE(kazupon): this is not exported from the entry points. `@gunshi/plugin-completion` completes
214
+ * the arguments the same way with the copy in `@gunshi/shared`, and the tests of that copy pin it
215
+ * to the results of this one, so a change here has to be made there too.
216
+ *
217
+ * @param globalOptions - The global options that plugins registered with `addGlobalOption`
218
+ * @param args - The arguments that the command declares
219
+ * @returns The merged arguments
220
+ */
221
+ function resolveCommandArgs(globalOptions, args) {
222
+ return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
223
+ }
224
+ function resolveGlobalOptions(globalOptions, args) {
225
+ if (!globalOptions) return;
226
+ const shortNames = /* @__PURE__ */ new Set();
227
+ for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
228
+ const resolved = create();
229
+ for (const [name, schema] of globalOptions)
230
+ /**
231
+ * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
232
+ * command of the CLI shares. Only this command gives up the short name.
233
+ */
234
+ resolved[name] = schema.short && shortNames.has(schema.short) ? {
235
+ ...schema,
236
+ short: void 0
237
+ } : schema;
238
+ return resolved;
239
+ }
240
+ //#endregion
200
241
  //#region src/cli/core.ts
201
242
  /**
202
243
  * @author kazuya kawaguchi (a.k.a. kazupon)
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { create } from "./utils.js";
2
- import { n as cliUsage } from "./builtin-CMCjNe-j.js";
2
+ import { n as cliUsage } from "./builtin-ClJbNR1q.js";
3
3
  //#region src/generator.ts
4
4
  /**
5
5
  * The entry for usage generator.
package/lib/index.js CHANGED
@@ -2,8 +2,8 @@ import { n as ANONYMOUS_COMMAND_NAME, t as createCommandContext } from "./contex
2
2
  import { a as resolveArgs, n as ArgsValidationErrorKeys, o as parseArgs, t as ArgsValidationError } from "./resolver-CAlgxe_R-y4BytVTg.js";
3
3
  import { a as hasPriorityValidationError, c as isCommandResolutionError, i as CommandResolutionErrorKeys, n as CommandNotFoundErrorKeys, o as isArgsValidationError, r as CommandResolutionError, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-wB83kWiv.js";
4
4
  import { t as plugin } from "./plugin-CG94VzCl.js";
5
- import { a as namespacedId } from "./src-BI37Q7Wx.js";
6
- import { t as cli } from "./builtin-CMCjNe-j.js";
5
+ import { a as namespacedId } from "./src-Dr9mmkFc.js";
6
+ import { t as cli } from "./builtin-ClJbNR1q.js";
7
7
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
8
8
  //#region ../plugin-i18n/src/translation.ts
9
9
  /**
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-BI37Q7Wx.js";
1
+ import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-Dr9mmkFc.js";
2
2
  //#region src/renderer.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -608,6 +608,11 @@ async function resolveDisplayValue(ctx, key) {
608
608
  if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${await generateDefaultDisplayValue(ctx, schema)})`;
609
609
  if (schema.type === "enum") {
610
610
  const _default = schema.default === void 0 ? "" : await generateDefaultDisplayValue(ctx, schema);
611
+ /**
612
+ * NOTE(kazupon): an `enum` argument that has a `parse` function needs no `choices`, as args-tokens
613
+ * resolves its value with the function. There is no list to show then (#800).
614
+ */
615
+ if (!Array.isArray(schema.choices)) return _default ? `(${_default})` : "";
611
616
  const choices = `${await ctx.extensions[pluginId].text(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
612
617
  return `(${_default ? `${_default}, ${choices}` : choices})`;
613
618
  }
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { i as Args, n as ArgSchema } from "./resolver-BezrTUr7.js";
2
1
  import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-lD5uzpd5.js";
3
2
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/utils.d.ts
4
3
  //#region src/utils.d.ts
@@ -51,19 +50,6 @@ declare function resolveLazyCommand<G extends GunshiParamsConstraint = DefaultGu
51
50
  * @returns A new object with the specified prototype
52
51
  */
53
52
  declare function create<T>(obj?: object | null): T;
54
- /**
55
- * Resolve the arguments of a command, the way gunshi parses and renders them.
56
- *
57
- * The global options belong to no command definition, so they are merged into the arguments of the
58
- * command that runs. An argument of the command shadows the global option of the same name, and it
59
- * shadows the same way by short name: a global option gives up its short name to an argument of the
60
- * command that claims the same letter, and keeps its long name.
61
- *
62
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
63
- * @param args - The arguments that the command declares
64
- * @returns The merged arguments
65
- */
66
- declare function resolveCommandArgs<A extends Args = Args>(globalOptions?: ReadonlyMap<string, ArgSchema>, args?: A): A;
67
53
  /**
68
54
  * Log a message to the console.
69
55
  *
@@ -86,4 +72,4 @@ declare function getCommandSubCommands<G extends GunshiParamsConstraint = Defaul
86
72
  */
87
73
  declare function deepFreeze<T extends Record<string, any>>(obj: T, ignores?: string[]): Readonly<T>;
88
74
  //#endregion
89
- export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveCommandArgs, resolveLazyCommand };
75
+ export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveLazyCommand };
package/lib/utils.js CHANGED
@@ -80,37 +80,6 @@ function create(obj = null) {
80
80
  return Object.create(obj);
81
81
  }
82
82
  /**
83
- * Resolve the arguments of a command, the way gunshi parses and renders them.
84
- *
85
- * The global options belong to no command definition, so they are merged into the arguments of the
86
- * command that runs. An argument of the command shadows the global option of the same name, and it
87
- * shadows the same way by short name: a global option gives up its short name to an argument of the
88
- * command that claims the same letter, and keeps its long name.
89
- *
90
- * @param globalOptions - The global options that plugins registered with `addGlobalOption`
91
- * @param args - The arguments that the command declares
92
- * @returns The merged arguments
93
- */
94
- function resolveCommandArgs(globalOptions, args) {
95
- return Object.assign(create(), resolveGlobalOptions(globalOptions, args), args);
96
- }
97
- function resolveGlobalOptions(globalOptions, args) {
98
- if (!globalOptions) return;
99
- const shortNames = /* @__PURE__ */ new Set();
100
- for (const schema of Object.values(args || {})) if (schema.type !== "positional" && schema.short) shortNames.add(schema.short);
101
- const resolved = create();
102
- for (const [name, schema] of globalOptions)
103
- /**
104
- * NOTE(kazupon): a copy, because the schema is the one that the plugin registered, which every
105
- * command of the CLI shares. Only this command gives up the short name.
106
- */
107
- resolved[name] = schema.short && shortNames.has(schema.short) ? {
108
- ...schema,
109
- short: void 0
110
- } : schema;
111
- return resolved;
112
- }
113
- /**
114
83
  * Log a message to the console.
115
84
  *
116
85
  * @param args - Arguments to log
@@ -153,4 +122,4 @@ function deepFreeze(obj, ignores = []) {
153
122
  return Object.freeze(obj);
154
123
  }
155
124
  //#endregion
156
- export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, resolveCommandArgs, resolveLazyCommand };
125
+ export { create, deepFreeze, getCommandSubCommands, isLazyCommand, kebabnize, log, 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": "1.0.0-beta.1",
4
+ "version": "1.0.0-beta.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -108,11 +108,11 @@
108
108
  }
109
109
  },
110
110
  "devDependencies": {
111
- "@gunshi/plugin-global": "1.0.0-beta.1",
112
- "@gunshi/plugin-i18n": "1.0.0-beta.1",
113
- "@gunshi/plugin-renderer": "1.0.0-beta.1",
114
- "@gunshi/resources": "1.0.0-beta.1",
115
- "@gunshi/shared": "1.0.0-beta.1",
111
+ "@gunshi/plugin-global": "1.0.0-beta.2",
112
+ "@gunshi/plugin-i18n": "1.0.0-beta.2",
113
+ "@gunshi/plugin-renderer": "1.0.0-beta.2",
114
+ "@gunshi/resources": "1.0.0-beta.2",
115
+ "@gunshi/shared": "1.0.0-beta.2",
116
116
  "@types/node": "^25.6.2",
117
117
  "args-tokens": "1.0.0-beta.1",
118
118
  "deno": "^2.7.14",