gunshi 0.37.3 → 1.0.0-beta.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.
package/lib/bone.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-CbDvcwY3.js";
2
- import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
1
+ import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-By5dj6NT.js";
2
+ import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CVwpWSau.js";
3
3
 
4
4
  //#region src/cli/bone.d.ts
5
5
  /**
package/lib/bone.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cliCore } from "./core-CLzX86kY.js";
1
+ import { t as cliCore } from "./core-DARRFBGf.js";
2
2
  //#region src/cli/bone.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,7 +1,7 @@
1
- import { r as hasPriorityValidationError } from "./error-B5QxSzk9.js";
2
- import { t as plugin } from "./plugin-DneW3Toi.js";
3
- import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-80_afJQM.js";
4
- import { t as cliCore } from "./core-CLzX86kY.js";
1
+ import { a as hasPriorityValidationError } from "./error-wB83kWiv.js";
2
+ import { t as plugin } from "./plugin-CG94VzCl.js";
3
+ import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-Cj5m08gX.js";
4
+ import { t as cliCore } from "./core-DARRFBGf.js";
5
5
  //#region ../plugin-global/src/types.ts
6
6
  /**
7
7
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -24,16 +24,21 @@ const pluginId = namespacedId("global");
24
24
  * @returns A command decorator that adds global options handling
25
25
  */
26
26
  const decorator = (baseRunner) => async (ctx) => {
27
- const { values, validationError, extensions: { [pluginId]: { showVersion, showHeader, showUsage, showValidationErrors } } } = ctx;
27
+ /**
28
+ * NOTE(kazupon): the core puts the globals still in effect on `env.globalOptions`. A command that
29
+ * declares the same name — even with an identical schema — is not in that map, so `--version` /
30
+ * `--help` belong to the command.
31
+ */
32
+ const { values, validationError, env: { globalOptions }, extensions: { [pluginId]: { showVersion, showHeader, showUsage, showValidationErrors } } } = ctx;
28
33
  if (hasPriorityValidationError(validationError)) {
29
34
  await showValidationErrors(validationError);
30
35
  throw validationError;
31
36
  }
32
- if (values.version) return showVersion();
37
+ if (values.version && globalOptions?.has("version")) return showVersion();
33
38
  const buf = [];
34
39
  const header = await showHeader();
35
40
  if (header) buf.push(header);
36
- if (values.help) {
41
+ if (values.help && globalOptions?.has("help")) {
37
42
  const usage = await showUsage();
38
43
  if (usage) {
39
44
  buf.push(usage);
@@ -160,14 +165,29 @@ function global() {
160
165
  * @returns A rendered usage or undefined. if you will use {@linkcode CliOptions.usageSilent} option, it will return rendered usage string.
161
166
  */
162
167
  async function cli(args, entry, options = {}) {
163
- const builtInPlugins = [global(), renderer()];
164
- return cliCore(args, entry, options, builtInPlugins);
168
+ return cliCore(args, entry, options, createBuiltInPlugins());
165
169
  }
166
- //#endregion
167
- //#region src/cli.ts
168
170
  /**
169
- * @author kazuya kawaguchi (a.k.a. kazupon)
170
- * @license MIT
171
+ * Render the usage of a command, without running it.
172
+ *
173
+ * This is what `generate` of `gunshi/generator` is made of. It resolves the command the same way
174
+ * {@linkcode cli} does, with the same built-in plugins, and renders the usage of the command it
175
+ * arrives at, whatever that command declares as its own arguments.
176
+ *
177
+ * @internal
178
+ *
179
+ * @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command and cli options.
180
+ *
181
+ * @param args - Command line arguments, which name the command to render
182
+ * @param entry - A {@link Command | entry command}, an {@link CommandRunner | inline command runner}, or a {@link LazyCommand | lazily-loaded command}
183
+ * @param options - A {@link CliOptions | CLI options}
184
+ * @returns A rendered usage, or `undefined` if there is no usage renderer to render it
171
185
  */
186
+ async function cliUsage(args, entry, options = {}) {
187
+ return cliCore(args, entry, options, createBuiltInPlugins(), true);
188
+ }
189
+ function createBuiltInPlugins() {
190
+ return [global(), renderer()];
191
+ }
172
192
  //#endregion
173
- export { cli as t };
193
+ export { cliUsage as n, cli as t };