gunshi 0.22.0 → 0.23.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,19 +1,26 @@
1
- import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, resolveLazyCommand } from "./utils-STQBqMtf.js";
2
- import { createCommandContext } from "./context-BefYjlE-.js";
3
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
1
+ import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, isLazyCommand, resolveLazyCommand } from "./utils-GlOAgmx0.js";
2
+ import { createCommandContext } from "./context-B_pkfbdk.js";
3
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-8HgcYJqp.js";
4
4
  import { parseArgs, resolveArgs } from "args-tokens";
5
5
 
6
6
  //#region src/cli.ts
7
- async function cli(argv, entry, opts = {}) {
7
+ /**
8
+ * Run the command.
9
+ * @param args Command line arguments
10
+ * @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
11
+ * @param options A {@link CliOptions | CLI options}
12
+ * @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
13
+ */
14
+ async function cli(argv, entry, options = {}) {
15
+ const cliOptions = resolveCliOptions(options, entry);
8
16
  const tokens = parseArgs(argv);
9
17
  const subCommand = getSubCommand(tokens);
10
- const resolvedCommandOptions = resolveCommandOptions(opts, entry);
11
- const [name, command, callMode] = await resolveCommand(subCommand, entry, resolvedCommandOptions, true);
18
+ const { commandName: name, command, callMode } = await resolveCommand(subCommand, entry, cliOptions);
12
19
  if (!command) throw new Error(`Command not found: ${name || ""}`);
13
- const args = resolveArguments(command.args);
20
+ const args = resolveArguments(getCommandArgs(command));
14
21
  const { values, positionals, rest, error } = resolveArgs(args, tokens, {
15
22
  optionGrouping: true,
16
- skipPositional: resolvedCommandOptions.subCommands.size > 0 ? 0 : -1
23
+ skipPositional: cliOptions.subCommands.size > 0 ? 0 : -1
17
24
  });
18
25
  const omitted = !subCommand;
19
26
  const ctx = await createCommandContext({
@@ -26,7 +33,7 @@ async function cli(argv, entry, opts = {}) {
26
33
  omitted,
27
34
  callMode,
28
35
  command,
29
- commandOptions: resolvedCommandOptions
36
+ cliOptions
30
37
  });
31
38
  if (values.version) {
32
39
  showVersion(ctx);
@@ -44,16 +51,20 @@ async function cli(argv, entry, opts = {}) {
44
51
  await showValidationErrors(ctx, error);
45
52
  return;
46
53
  }
47
- if (!command.run) throw new Error(`'run' not found on Command \`${name || ""}\``);
48
- await command.run(ctx);
54
+ await executeCommand(command, ctx, name || "");
49
55
  }
50
- function resolveArguments(options) {
51
- return Object.assign(create(), options, COMMON_ARGS);
56
+ function getCommandArgs(cmd) {
57
+ if (isLazyCommand(cmd)) return cmd.args || create();
58
+ else if (typeof cmd === "object") return cmd.args || create();
59
+ else return create();
52
60
  }
53
- function resolveCommandOptions(options, entry) {
61
+ function resolveArguments(args) {
62
+ return Object.assign(create(), args, COMMON_ARGS);
63
+ }
64
+ function resolveCliOptions(options, entry) {
54
65
  const subCommands = new Map(options.subCommands);
55
66
  if (options.subCommands) {
56
- if (typeof entry === "function" && "commandName" in entry && entry.commandName) subCommands.set(entry.commandName, entry);
67
+ if (isLazyCommand(entry)) subCommands.set(entry.commandName, entry);
57
68
  else if (typeof entry === "object" && entry.name) subCommands.set(entry.name, entry);
58
69
  }
59
70
  const resolvedOptions = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands });
@@ -88,47 +99,48 @@ async function showValidationErrors(ctx, error) {
88
99
  const render = ctx.env.renderValidationErrors || renderValidationErrors;
89
100
  ctx.log(await render(ctx, error));
90
101
  }
91
- const CANNOT_RESOLVE_COMMAND = [
92
- void 0,
93
- void 0,
94
- "unexpected"
95
- ];
96
- async function resolveCommand(sub, entry, options, needRunResolving = false) {
102
+ const CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
103
+ async function resolveCommand(sub, entry, options) {
97
104
  const omitted = !sub;
98
105
  async function doResolveCommand() {
99
- if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return [
100
- entry.commandName,
101
- await resolveLazyCommand(entry, "", needRunResolving),
102
- "entry"
103
- ];
104
- else return [
105
- void 0,
106
- { run: entry },
107
- "entry"
108
- ];
109
- else if (typeof entry === "object") return [
110
- resolveEntryName(entry),
111
- await resolveLazyCommand(entry, "", needRunResolving),
112
- "entry"
113
- ];
106
+ if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
107
+ commandName: entry.commandName,
108
+ command: entry,
109
+ callMode: "entry"
110
+ };
111
+ else return {
112
+ command: { run: entry },
113
+ callMode: "entry"
114
+ };
115
+ else if (typeof entry === "object") return {
116
+ commandName: resolveEntryName(entry),
117
+ command: entry,
118
+ callMode: "entry"
119
+ };
114
120
  else return CANNOT_RESOLVE_COMMAND;
115
121
  }
116
122
  if (omitted || options.subCommands?.size === 0) return doResolveCommand();
117
123
  const cmd = options.subCommands?.get(sub);
118
- if (cmd == null) return [
119
- sub,
120
- void 0,
121
- "unexpected"
122
- ];
123
- return [
124
- sub,
125
- await resolveLazyCommand(cmd, sub, needRunResolving),
126
- "subCommand"
127
- ];
124
+ if (cmd == null) return {
125
+ commandName: sub,
126
+ callMode: "unexpected"
127
+ };
128
+ if (isLazyCommand(cmd) && cmd.commandName == null) cmd.commandName = sub;
129
+ else if (typeof cmd === "object" && cmd.name == null) cmd.name = sub;
130
+ return {
131
+ commandName: sub,
132
+ command: cmd,
133
+ callMode: "subCommand"
134
+ };
128
135
  }
129
136
  function resolveEntryName(entry) {
130
137
  return entry.name || "(anonymous)";
131
138
  }
139
+ async function executeCommand(cmd, ctx, name) {
140
+ const resolved = isLazyCommand(cmd) ? await resolveLazyCommand(cmd, name, true) : cmd;
141
+ if (resolved.run == null) throw new Error(`'run' not found on Command \`${name}\``);
142
+ await resolved.run(ctx);
143
+ }
132
144
 
133
145
  //#endregion
134
146
  export { cli };
@@ -1,4 +1,4 @@
1
- import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-STQBqMtf.js";
1
+ import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-GlOAgmx0.js";
2
2
 
3
3
  //#region src/locales/en-US.json
4
4
  var COMMAND = "COMMAND";
@@ -72,7 +72,7 @@ const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
72
72
  * @param param A {@link CommandContextParams | parameters} to create a {@link CommandContext | command context}
73
73
  * @returns A {@link CommandContext | command context}, which is readonly
74
74
  */
75
- async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, commandOptions, callMode = "entry", omitted = false }) {
75
+ async function createCommandContext({ args, values, positionals, rest, argv, tokens, command, cliOptions, callMode = "entry", omitted = false }) {
76
76
  /**
77
77
  * normailize the options schema and values, to avoid prototype pollution
78
78
  */
@@ -83,10 +83,10 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
83
83
  /**
84
84
  * setup the environment
85
85
  */
86
- const env = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, commandOptions);
87
- const locale = resolveLocale(commandOptions.locale);
86
+ const env = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, cliOptions);
87
+ const locale = resolveLocale(cliOptions.locale);
88
88
  const localeStr = locale.toString();
89
- const translationAdapterFactory = commandOptions.translationAdapterFactory || createTranslationAdapter;
89
+ const translationAdapterFactory = cliOptions.translationAdapterFactory || createTranslationAdapter;
90
90
  const adapter = translationAdapterFactory({
91
91
  locale: localeStr,
92
92
  fallbackLocale: DEFAULT_LOCALE
@@ -118,7 +118,7 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
118
118
  let cachedCommands;
119
119
  async function loadCommands() {
120
120
  if (cachedCommands) return cachedCommands;
121
- const subCommands = [...commandOptions.subCommands || []];
121
+ const subCommands = [...cliOptions.subCommands || []];
122
122
  return cachedCommands = await Promise.all(subCommands.map(async ([name, cmd]) => await resolveLazyCommand(cmd, name)));
123
123
  }
124
124
  /**
@@ -137,7 +137,7 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
137
137
  rest,
138
138
  _: argv,
139
139
  tokens,
140
- log: commandOptions.usageSilent ? NOOP : log,
140
+ log: cliOptions.usageSilent ? NOOP : log,
141
141
  loadCommands,
142
142
  translate
143
143
  }));
package/lib/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Command, CommandCallMode, CommandContext, CommandOptions } from "./types-BbgfNBFM.js";
1
+ import { CliOptions, Command, CommandCallMode, CommandContext } from "./types-ZXqvU8Ti.js";
2
2
  import { ArgToken, ArgValues, Args } from "args-tokens";
3
3
 
4
4
  //#region src/context.d.ts
@@ -49,7 +49,7 @@ interface CommandContextParams<A extends Args, V> {
49
49
  /**
50
50
  * A command options, which is spicialized from `cli` function
51
51
  */
52
- commandOptions: CommandOptions<A>;
52
+ cliOptions: CliOptions<A>;
53
53
  }
54
54
  /**
55
55
  * Create a {@link CommandContext | command context}
@@ -64,7 +64,7 @@ declare function createCommandContext<A extends Args = Args, V extends ArgValues
64
64
  argv,
65
65
  tokens,
66
66
  command,
67
- commandOptions,
67
+ cliOptions,
68
68
  callMode,
69
69
  omitted
70
70
  }: CommandContextParams<A, V>): Promise<Readonly<CommandContext<A, V>>>; //#endregion
package/lib/context.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./utils-STQBqMtf.js";
2
- import { createCommandContext } from "./context-BefYjlE-.js";
1
+ import "./utils-GlOAgmx0.js";
2
+ import { createCommandContext } from "./context-B_pkfbdk.js";
3
3
 
4
4
  export { createCommandContext };
@@ -1,4 +1,4 @@
1
- import { Command, CommandLoader, LazyCommand } from "./types-BbgfNBFM.js";
1
+ import { Command, CommandLoader, LazyCommand } from "./types-ZXqvU8Ti.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
@@ -1,3 +1,3 @@
1
- import "./types-BbgfNBFM.js";
2
- import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-DUNcKGVg.js";
1
+ import "./types-ZXqvU8Ti.js";
2
+ import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-BFYUOPMR.js";
3
3
  export { ArgSchema, ArgValues, Args, define, lazy };
@@ -1,23 +1,23 @@
1
- import { Command, CommandOptions } from "./types-BbgfNBFM.js";
1
+ import { CliOptions, Command, LazyCommand } from "./types-ZXqvU8Ti.js";
2
2
  import { Args } from "args-tokens";
3
3
 
4
4
  //#region src/generator.d.ts
5
5
  /**
6
- * Generate the command usage.
7
- * @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
8
- * @param entry - A {@link Command | entry command}
9
- * @param opts - A {@link CommandOptions | command options}
10
- * @returns A rendered usage.
6
+ * generate options of `generate` function.
11
7
  */
12
8
 
9
+ /**
10
+ * generate options of `generate` function.
11
+ */
12
+ type GenerateOptions<A extends Args = Args> = CliOptions<A>;
13
13
  /**
14
14
  * Generate the command usage.
15
15
  * @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
16
16
  * @param entry - A {@link Command | entry command}
17
- * @param opts - A {@link CommandOptions | command options}
17
+ * @param options - A {@link CliOptions | cli options}
18
18
  * @returns A rendered usage.
19
19
  */
20
- declare function generate<A extends Args = Args>(command: string | null, entry: Command<A>, opts?: CommandOptions<A>): Promise<string>;
20
+ declare function generate<A extends Args = Args>(command: string | null, entry: Command<A> | LazyCommand<A>, options?: GenerateOptions<A>): Promise<string>;
21
21
 
22
22
  //#endregion
23
- export { generate };
23
+ export { GenerateOptions, generate };
package/lib/generator.js CHANGED
@@ -1,23 +1,24 @@
1
- import { create } from "./utils-STQBqMtf.js";
2
- import "./context-BefYjlE-.js";
3
- import "./renderer-BpwhGYRZ.js";
4
- import { cli } from "./cli-DEuAxEk9.js";
1
+ import { create } from "./utils-GlOAgmx0.js";
2
+ import "./context-B_pkfbdk.js";
3
+ import "./renderer-8HgcYJqp.js";
4
+ import { cli } from "./cli-DBIMF97F.js";
5
5
 
6
6
  //#region src/generator.ts
7
7
  /**
8
8
  * Generate the command usage.
9
9
  * @param command - usage generate command, if you want to generate the usage of the default command where there are target commands and sub-commands, specify `null`.
10
10
  * @param entry - A {@link Command | entry command}
11
- * @param opts - A {@link CommandOptions | command options}
11
+ * @param options - A {@link CliOptions | cli options}
12
12
  * @returns A rendered usage.
13
13
  */
14
- async function generate(command, entry, opts = {}) {
14
+ async function generate(command, entry, options = {}) {
15
15
  const args = ["-h"];
16
16
  if (command != null) args.unshift(command);
17
- return await cli(args, entry, Object.assign(create(), opts, {
18
- usageSilent: true,
19
- __proto__: null
20
- })) || "";
17
+ return await cli(args, entry, {
18
+ ...create(),
19
+ ...options,
20
+ usageSilent: true
21
+ }) || "";
21
22
  }
22
23
 
23
24
  //#endregion
package/lib/index.d.ts CHANGED
@@ -1,10 +1,24 @@
1
- import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-BbgfNBFM.js";
2
- import { define$1 as define, lazy$1 as lazy } from "./definition-DUNcKGVg.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-ZXqvU8Ti.js";
2
+ import { define$1 as define, lazy$1 as lazy } from "./definition-BFYUOPMR.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
6
+ /**
7
+ * Run the command.
8
+ * @param args Command line arguments
9
+ * @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
10
+ * @param options A {@link CliOptions | CLI options}
11
+ * @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
12
+ */
6
13
 
7
- declare function cli<A extends Args$1 = Args$1>(argv: string[], entry: Command<A> | CommandRunner<A> | LazyCommand<A>, opts?: CommandOptions<A>): Promise<string | undefined>;
14
+ /**
15
+ * Run the command.
16
+ * @param args Command line arguments
17
+ * @param entry A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
18
+ * @param options A {@link CliOptions | CLI options}
19
+ * @returns A rendered usage or undefined. if you will use {@link CliOptions.usageSilent} option, it will return rendered usage string.
20
+ */
21
+ declare function cli<A extends Args$1 = Args$1>(argv: string[], entry: Command<A> | CommandRunner<A> | LazyCommand<A>, options?: CliOptions<A>): Promise<string | undefined>;
8
22
 
9
23
  //#endregion
10
24
  //#region src/translation.d.ts
@@ -18,4 +32,4 @@ declare class DefaultTranslation implements TranslationAdapter {
18
32
  }
19
33
 
20
34
  //#endregion
21
- export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
35
+ export { ArgSchema, ArgValues, Args, CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-STQBqMtf.js";
2
- import { DefaultTranslation } from "./context-BefYjlE-.js";
1
+ import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-GlOAgmx0.js";
2
+ import { DefaultTranslation } from "./context-B_pkfbdk.js";
3
3
  import { define, lazy } from "./definition-DyVBFqB7.js";
4
- import "./renderer-BpwhGYRZ.js";
5
- import { cli } from "./cli-DEuAxEk9.js";
4
+ import "./renderer-8HgcYJqp.js";
5
+ import { cli } from "./cli-DBIMF97F.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-STQBqMtf.js";
1
+ import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey, resolveExamples } from "./utils-GlOAgmx0.js";
2
2
 
3
3
  //#region src/renderer/header.ts
4
4
  /**
package/lib/renderer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandContext } from "./types-BbgfNBFM.js";
1
+ import { CommandContext } from "./types-ZXqvU8Ti.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-STQBqMtf.js";
2
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
1
+ import "./utils-GlOAgmx0.js";
2
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-8HgcYJqp.js";
3
3
 
4
4
  export { renderHeader, renderUsage, renderValidationErrors };
@@ -25,7 +25,7 @@ type CommonArgType = {
25
25
  };
26
26
  };
27
27
  declare const COMMON_ARGS: CommonArgType;
28
- declare const COMMAND_OPTIONS_DEFAULT: CommandOptions<Args>;
28
+ declare const COMMAND_OPTIONS_DEFAULT: CliOptions<Args>;
29
29
  declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES"];
30
30
 
31
31
  //#endregion
@@ -72,58 +72,58 @@ type CommandArgKeys<A extends Args> = GenerateNamespacedKey<KeyOfArgs<RemovedInd
72
72
  interface CommandEnvironment<A extends Args = Args> {
73
73
  /**
74
74
  * Current working directory.
75
- * @see {@link CommandOptions.cwd}
75
+ * @see {@link CliOptions.cwd}
76
76
  */
77
77
  cwd: string | undefined;
78
78
  /**
79
79
  * Command name.
80
- * @see {@link CommandOptions.name}
80
+ * @see {@link CliOptions.name}
81
81
  */
82
82
  name: string | undefined;
83
83
  /**
84
84
  * Command description.
85
- * @see {@link CommandOptions.description}
85
+ * @see {@link CliOptions.description}
86
86
  *
87
87
  */
88
88
  description: string | undefined;
89
89
  /**
90
90
  * Command version.
91
- * @see {@link CommandOptions.version}
91
+ * @see {@link CliOptions.version}
92
92
  */
93
93
  version: string | undefined;
94
94
  /**
95
95
  * Left margin of the command output.
96
96
  * @default 2
97
- * @see {@link CommandOptions.leftMargin}
97
+ * @see {@link CliOptions.leftMargin}
98
98
  */
99
99
  leftMargin: number;
100
100
  /**
101
101
  * Middle margin of the command output.
102
102
  * @default 10
103
- * @see {@link CommandOptions.middleMargin}
103
+ * @see {@link CliOptions.middleMargin}
104
104
  */
105
105
  middleMargin: number;
106
106
  /**
107
107
  * Whether to display the usage option type.
108
108
  * @default false
109
- * @see {@link CommandOptions.usageOptionType}
109
+ * @see {@link CliOptions.usageOptionType}
110
110
  */
111
111
  usageOptionType: boolean;
112
112
  /**
113
113
  * Whether to display the option value.
114
114
  * @default true
115
- * @see {@link CommandOptions.usageOptionValue}
115
+ * @see {@link CliOptions.usageOptionValue}
116
116
  */
117
117
  usageOptionValue: boolean;
118
118
  /**
119
119
  * Whether to display the command usage.
120
120
  * @default false
121
- * @see {@link CommandOptions.usageSilent}
121
+ * @see {@link CliOptions.usageSilent}
122
122
  */
123
123
  usageSilent: boolean;
124
124
  /**
125
125
  * Sub commands.
126
- * @see {@link CommandOptions.subCommands}
126
+ * @see {@link CliOptions.subCommands}
127
127
  */
128
128
  subCommands: Map<string, Command<any> | LazyCommand<any>> | undefined;
129
129
  /**
@@ -140,9 +140,9 @@ interface CommandEnvironment<A extends Args = Args> {
140
140
  renderValidationErrors: ((ctx: CommandContext<A>, error: AggregateError) => Promise<string>) | null | undefined;
141
141
  }
142
142
  /**
143
- * Command options.
143
+ * CLI options of `cli` function.
144
144
  */
145
- interface CommandOptions<A extends Args = Args> {
145
+ interface CliOptions<A extends Args = Args> {
146
146
  /**
147
147
  * Current working directory.
148
148
  */
@@ -426,4 +426,4 @@ type LazyCommand<A extends Args = Args> = {
426
426
  * Define a command type.
427
427
  */
428
428
  type Commandable<A extends Args> = Command<A> | LazyCommand<A>; //#endregion
429
- export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
429
+ export { CliOptions, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandCallMode, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
@@ -38,9 +38,12 @@ const COMMAND_OPTIONS_DEFAULT = {
38
38
 
39
39
  //#endregion
40
40
  //#region src/utils.ts
41
+ function isLazyCommand(cmd) {
42
+ return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
43
+ }
41
44
  async function resolveLazyCommand(cmd, name, needRunResolving = false) {
42
45
  let command;
43
- if (typeof cmd === "function") {
46
+ if (isLazyCommand(cmd)) {
44
47
  command = Object.assign(create(), {
45
48
  name: cmd.commandName,
46
49
  description: cmd.description,
@@ -96,4 +99,4 @@ function deepFreeze(obj) {
96
99
  }
97
100
 
98
101
  //#endregion
99
- export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveExamples, resolveLazyCommand };
102
+ export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, isLazyCommand, 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.22.0",
4
+ "version": "0.23.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -103,11 +103,11 @@
103
103
  "eslint-plugin-vue-composable": "^1.0.0",
104
104
  "eslint-plugin-yml": "^1.18.0",
105
105
  "gh-changelogen": "^0.2.8",
106
- "gunshi019": "npm:gunshi@0.21.0",
106
+ "gunshi019": "npm:gunshi@0.22.0",
107
107
  "jsr": "^0.13.4",
108
108
  "jsr-exports-lint": "^0.2.0",
109
109
  "knip": "^5.53.0",
110
- "lint-staged": "^15.5.1",
110
+ "lint-staged": "^16.0.0",
111
111
  "messageformat": "4.0.0-11",
112
112
  "mitata": "^1.0.34",
113
113
  "pkg-pr-new": "^0.0.43",