gunshi 0.24.0 → 0.25.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.
@@ -1,6 +1,6 @@
1
- import { ANONYMOUS_COMMAND_NAME, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, isLazyCommand, resolveLazyCommand } from "./utils-D41C8Abf.js";
2
- import { createCommandContext } from "./context-COFfMm-R.js";
3
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-kzo45gaB.js";
1
+ import { ANONYMOUS_COMMAND_NAME, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, isLazyCommand, resolveLazyCommand } from "./utils-B_QNzw5q.js";
2
+ import { createCommandContext } from "./context-DT5PgSdv.js";
3
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-CTx2DsBI.js";
4
4
  import { parseArgs, resolveArgs } from "args-tokens";
5
5
 
6
6
  //#region src/cli.ts
@@ -19,7 +19,8 @@ async function cli(argv, entry, options = {}) {
19
19
  if (!command) throw new Error(`Command not found: ${name || ""}`);
20
20
  const args = resolveArguments(getCommandArgs(command));
21
21
  const { values, positionals, rest, error } = resolveArgs(args, tokens, {
22
- optionGrouping: true,
22
+ shortGrouping: true,
23
+ toKebab: command.toKebab,
23
24
  skipPositional: cliOptions.subCommands.size > 0 ? 0 : -1
24
25
  });
25
26
  const omitted = !subCommand;
@@ -1,4 +1,4 @@
1
- import { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, isLazyCommand, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-D41C8Abf.js";
1
+ import { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, isLazyCommand, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-B_QNzw5q.js";
2
2
 
3
3
  //#region src/locales/en-US.json
4
4
  var COMMAND = "COMMAND";
@@ -137,6 +137,7 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
137
137
  rest,
138
138
  _: argv,
139
139
  tokens,
140
+ toKebab: command.toKebab,
140
141
  log: cliOptions.usageSilent ? NOOP : log,
141
142
  loadCommands,
142
143
  translate
package/lib/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CliOptions, Command, CommandCallMode, CommandContext, LazyCommand } from "./types-BDWiiycu.js";
1
+ import { CliOptions, Command, CommandCallMode, CommandContext, LazyCommand } from "./types-B7j6WSjQ.js";
2
2
  import { ArgToken, ArgValues, Args } from "args-tokens";
3
3
 
4
4
  //#region src/context.d.ts
package/lib/context.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./utils-D41C8Abf.js";
2
- import { createCommandContext } from "./context-COFfMm-R.js";
1
+ import "./utils-B_QNzw5q.js";
2
+ import { createCommandContext } from "./context-DT5PgSdv.js";
3
3
 
4
4
  export { createCommandContext };
@@ -1,4 +1,4 @@
1
- import { Command, CommandLoader, LazyCommand } from "./types-BDWiiycu.js";
1
+ import { Command, CommandLoader, LazyCommand } from "./types-B7j6WSjQ.js";
2
2
  import { ArgSchema, ArgValues as ArgValues$1, Args, Args as Args$1 } from "args-tokens";
3
3
 
4
4
  //#region src/definition.d.ts
@@ -20,6 +20,7 @@ function lazy(loader, definition) {
20
20
  loader.args = definition.args;
21
21
  loader.examples = definition.examples;
22
22
  loader.resource = definition.resource;
23
+ loader.toKebab = definition.toKebab;
23
24
  }
24
25
  return loader;
25
26
  }
@@ -1,3 +1,3 @@
1
- import "./types-BDWiiycu.js";
2
- import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-zTfMFgKw.js";
1
+ import "./types-B7j6WSjQ.js";
2
+ import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-C3eTsvXE.js";
3
3
  export { ArgSchema, ArgValues, Args, define, lazy };
package/lib/definition.js CHANGED
@@ -1,3 +1,3 @@
1
- import { define, lazy } from "./definition-DyVBFqB7.js";
1
+ import { define, lazy } from "./definition-wq1Kmbvq.js";
2
2
 
3
3
  export { define, lazy };
@@ -1,4 +1,4 @@
1
- import { CliOptions, Command, LazyCommand } from "./types-BDWiiycu.js";
1
+ import { CliOptions, Command, LazyCommand } from "./types-B7j6WSjQ.js";
2
2
  import { Args } from "args-tokens";
3
3
 
4
4
  //#region src/generator.d.ts
package/lib/generator.js CHANGED
@@ -1,7 +1,7 @@
1
- import { create } from "./utils-D41C8Abf.js";
2
- import "./context-COFfMm-R.js";
3
- import "./renderer-kzo45gaB.js";
4
- import { cli } from "./cli-BVD3QITm.js";
1
+ import { create } from "./utils-B_QNzw5q.js";
2
+ import "./context-DT5PgSdv.js";
3
+ import "./renderer-CTx2DsBI.js";
4
+ import { cli } from "./cli-BtS9kKar.js";
5
5
 
6
6
  //#region src/generator.ts
7
7
  /**
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-BDWiiycu.js";
2
- import { define$1 as define, lazy$1 as lazy } from "./definition-zTfMFgKw.js";
1
+ import { CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-B7j6WSjQ.js";
2
+ import { define$1 as define, lazy$1 as lazy } from "./definition-C3eTsvXE.js";
3
3
  import { ArgSchema, ArgValues, Args, Args as Args$1, parseArgs, resolveArgs } from "args-tokens";
4
4
 
5
5
  //#region src/cli.d.ts
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-D41C8Abf.js";
2
- import { DefaultTranslation } from "./context-COFfMm-R.js";
3
- import { define, lazy } from "./definition-DyVBFqB7.js";
4
- import "./renderer-kzo45gaB.js";
5
- import { cli } from "./cli-BVD3QITm.js";
1
+ import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-B_QNzw5q.js";
2
+ import { DefaultTranslation } from "./context-DT5PgSdv.js";
3
+ import { define, lazy } from "./definition-wq1Kmbvq.js";
4
+ import "./renderer-CTx2DsBI.js";
5
+ import { cli } from "./cli-BtS9kKar.js";
6
6
  import { parseArgs, resolveArgs } from "args-tokens";
7
7
 
8
8
  export { DEFAULT_LOCALE, DefaultTranslation, cli, define, lazy, parseArgs, resolveArgs };
@@ -1,4 +1,4 @@
1
- import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey, resolveExamples } from "./utils-D41C8Abf.js";
1
+ import { COMMON_ARGS, create, kebabnize, resolveArgKey, resolveBuiltInKey, resolveExamples } from "./utils-B_QNzw5q.js";
2
2
 
3
3
  //#region src/renderer/header.ts
4
4
  /**
@@ -187,8 +187,9 @@ function hasAllDefaultOptions(ctx) {
187
187
  function generateOptionsSymbols(ctx) {
188
188
  return hasOptionalArgs(ctx) ? hasAllDefaultOptions(ctx) ? `[${ctx.translate(resolveBuiltInKey("OPTIONS"))}]` : `<${ctx.translate(resolveBuiltInKey("OPTIONS"))}>` : "";
189
189
  }
190
- function makeShortLongOptionPair(schema, name) {
191
- let key = `--${name}`;
190
+ function makeShortLongOptionPair(schema, name, toKebab) {
191
+ const displayName = toKebab || schema.toKebab ? kebabnize(name) : name;
192
+ let key = `--${displayName}`;
192
193
  if (schema.short) key = `-${schema.short}, ${key}`;
193
194
  return key;
194
195
  }
@@ -198,12 +199,18 @@ function makeShortLongOptionPair(schema, name) {
198
199
  * @returns Options pairs for usage
199
200
  */
200
201
  function getOptionalArgsPairs(ctx) {
201
- return Object.entries(ctx.args).reduce((acc, [name, value]) => {
202
- if (value.type === "positional") return acc;
203
- let key = makeShortLongOptionPair(value, name);
204
- if (value.type !== "boolean") key = value.default ? `${key} [${name}]` : `${key} <${name}>`;
202
+ return Object.entries(ctx.args).reduce((acc, [name, schema]) => {
203
+ if (schema.type === "positional") return acc;
204
+ let key = makeShortLongOptionPair(schema, name, ctx.toKebab);
205
+ if (schema.type !== "boolean") {
206
+ const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
207
+ key = schema.default ? `${key} [${displayName}]` : `${key} <${displayName}>`;
208
+ }
205
209
  acc[name] = key;
206
- if (value.type === "boolean" && value.negatable && !COMMON_ARGS_KEYS.includes(name)) acc[`no-${name}`] = `--no-${name}`;
210
+ if (schema.type === "boolean" && schema.negatable && !COMMON_ARGS_KEYS.includes(name)) {
211
+ const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
212
+ acc[`no-${name}`] = `--no-${displayName}`;
213
+ }
207
214
  return acc;
208
215
  }, create());
209
216
  }
@@ -217,7 +224,7 @@ function generateDefaultDisplayValue(ctx, schema) {
217
224
  function resolveDisplayValue(ctx, key) {
218
225
  if (COMMON_ARGS_KEYS.includes(key)) return "";
219
226
  const schema = ctx.args[key];
220
- if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string") && schema.default !== void 0) return `(${generateDefaultDisplayValue(ctx, schema)})`;
227
+ if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${generateDefaultDisplayValue(ctx, schema)})`;
221
228
  if (schema.type === "enum") {
222
229
  const _default = schema.default !== void 0 ? generateDefaultDisplayValue(ctx, schema) : "";
223
230
  const choices = `${ctx.translate(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
@@ -239,7 +246,7 @@ async function generateOptionalArgsUsage(ctx, optionsPairs) {
239
246
  if (!rawDesc && key.startsWith("no-")) {
240
247
  const name = resolveNegatableKey(key);
241
248
  const schema = ctx.args[name];
242
- const optionKey = makeShortLongOptionPair(schema, name);
249
+ const optionKey = makeShortLongOptionPair(schema, name, ctx.toKebab);
243
250
  rawDesc = `${ctx.translate(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
244
251
  }
245
252
  const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
package/lib/renderer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandContext } from "./types-BDWiiycu.js";
1
+ import { CommandContext } from "./types-B7j6WSjQ.js";
2
2
  import { Args } from "args-tokens";
3
3
 
4
4
  //#region src/renderer/header.d.ts
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./utils-D41C8Abf.js";
2
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-kzo45gaB.js";
1
+ import "./utils-B_QNzw5q.js";
2
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-CTx2DsBI.js";
3
3
 
4
4
  export { renderHeader, renderUsage, renderValidationErrors };
@@ -271,6 +271,11 @@ interface CommandContext<A extends Args = Args, V = ArgValues<A>> {
271
271
  * The command call mode is `entry` when the command is executed as an entry command, and `subCommand` when the command is executed as a sub-command.
272
272
  */
273
273
  callMode: CommandCallMode;
274
+ /**
275
+ * Whether to convert the camel-case style argument name to kebab-case.
276
+ * This context value is set from {@link Command.toKebab} option.
277
+ */
278
+ toKebab?: boolean;
274
279
  /**
275
280
  * Output a message.
276
281
  * If {@link CommandEnvironment.usageSilent} is true, the message is not output.
@@ -324,6 +329,11 @@ interface Command<A extends Args = Args> {
324
329
  * Command resource fetcher.
325
330
  */
326
331
  resource?: CommandResourceFetcher<A>;
332
+ /**
333
+ * Whether to convert the camel-case style argument name to kebab-case.
334
+ * If you will set to `true`, All {@link Command.args} names will be converted to kebab-case.
335
+ */
336
+ toKebab?: boolean;
327
337
  }
328
338
  /**
329
339
  * Command resource.
@@ -72,6 +72,14 @@ async function resolveLazyCommand(cmd, name, needRunResolving = false) {
72
72
  function resolveBuiltInKey(key) {
73
73
  return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
74
74
  }
75
+ /**
76
+ * Convert a camelCase string to kebab-case
77
+ * @param str The string to convert
78
+ * @returns The kebab-case version of the string
79
+ */
80
+ function kebabnize(str) {
81
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
82
+ }
75
83
  function resolveArgKey(key) {
76
84
  return `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
77
85
  }
@@ -100,4 +108,4 @@ function deepFreeze(obj) {
100
108
  }
101
109
 
102
110
  //#endregion
103
- export { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, isLazyCommand, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveExamples, resolveLazyCommand };
111
+ export { ANONYMOUS_COMMAND_NAME, BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, isLazyCommand, kebabnize, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveExamples, 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.24.0",
4
+ "version": "0.25.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -78,7 +78,7 @@
78
78
  }
79
79
  },
80
80
  "dependencies": {
81
- "args-tokens": "^0.18.0"
81
+ "args-tokens": "^0.19.0"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@eslint/markdown": "^6.4.0",
@@ -86,13 +86,13 @@
86
86
  "@kazupon/eslint-config": "^0.29.0",
87
87
  "@kazupon/prettier-config": "^0.1.1",
88
88
  "@types/node": "^22.15.21",
89
- "@typescript/native-preview": "7.0.0-dev.20250522.2",
90
- "@vitest/eslint-plugin": "^1.2.0",
89
+ "@typescript/native-preview": "7.0.0-dev.20250526.1",
90
+ "@vitest/eslint-plugin": "^1.2.1",
91
91
  "bumpp": "^10.1.1",
92
92
  "deno": "^2.3.3",
93
93
  "eslint": "^9.27.0",
94
94
  "eslint-config-prettier": "^10.1.5",
95
- "eslint-import-resolver-typescript": "^4.3.5",
95
+ "eslint-import-resolver-typescript": "^4.4.1",
96
96
  "eslint-plugin-import": "^2.31.0",
97
97
  "eslint-plugin-jsonc": "^2.20.1",
98
98
  "eslint-plugin-module-interop": "^0.3.1",
@@ -104,26 +104,27 @@
104
104
  "eslint-plugin-vue-composable": "^1.0.0",
105
105
  "eslint-plugin-yml": "^1.18.0",
106
106
  "gh-changelogen": "^0.2.8",
107
- "gunshi019": "npm:gunshi@0.23.1",
107
+ "gunshi019": "npm:gunshi@0.19.0",
108
108
  "jsr": "^0.13.4",
109
109
  "jsr-exports-lint": "^0.4.0",
110
- "knip": "^5.57.2",
110
+ "knip": "^5.58.0",
111
111
  "lint-staged": "^16.0.0",
112
112
  "messageformat": "4.0.0-12",
113
113
  "mitata": "^1.0.34",
114
114
  "pkg-pr-new": "^0.0.50",
115
115
  "prettier": "^3.5.3",
116
116
  "publint": "^0.3.12",
117
- "tsdown": "^0.12.2",
117
+ "tsdown": "^0.12.3",
118
118
  "typedoc": "^0.28.4",
119
119
  "typedoc-plugin-markdown": "^4.6.3",
120
120
  "typedoc-vitepress-theme": "^1.1.2",
121
121
  "typescript-eslint": "^8.32.1",
122
122
  "vitepress": "^1.6.3",
123
123
  "vitepress-plugin-group-icons": "^1.5.5",
124
- "vitepress-plugin-llms": "^1.3.3",
124
+ "vitepress-plugin-llms": "^1.3.4",
125
125
  "vitest": "^3.1.4",
126
- "vue": "^3.5.14"
126
+ "vue": "^3.5.14",
127
+ "zod": "^3.25.28"
127
128
  },
128
129
  "prettier": "@kazupon/prettier-config",
129
130
  "lint-staged": {