@gunshi/plugin-renderer 0.34.0 → 0.35.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.
Files changed (2) hide show
  1. package/lib/index.js +25 -12
  2. package/package.json +4 -4
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ANONYMOUS_COMMAND_NAME, plugin } from "@gunshi/plugin";
2
- //#region ../../node_modules/.pnpm/args-tokens@0.26.1/node_modules/args-tokens/lib/utils.js
2
+ //#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/utils.js
3
3
  /**
4
4
  * Entry point of utils.
5
5
  *
@@ -303,6 +303,15 @@ const pluginId = namespacedId("renderer");
303
303
  * @license MIT
304
304
  */
305
305
  const COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
306
+ function isHiddenArg(schema) {
307
+ return schema.hidden === true;
308
+ }
309
+ function getVisibleOptionalArgs(args) {
310
+ return Object.entries(args).filter(([_, schema]) => schema.type !== "positional" && !isHiddenArg(schema));
311
+ }
312
+ function getVisiblePositionalArgs(args) {
313
+ return Object.entries(args).filter(([_, schema]) => schema.type === "positional" && !isHiddenArg(schema));
314
+ }
306
315
  /**
307
316
  * Render the usage.
308
317
  *
@@ -484,7 +493,7 @@ async function hasCommands(ctx) {
484
493
  * @returns True if the command has options
485
494
  */
486
495
  function hasOptionalArgs(args) {
487
- return Object.values(args).some((arg) => arg.type !== "positional");
496
+ return getVisibleOptionalArgs(args).length > 0;
488
497
  }
489
498
  /**
490
499
  * Check if the command has positional arguments
@@ -493,7 +502,7 @@ function hasOptionalArgs(args) {
493
502
  * @returns True if the command has options
494
503
  */
495
504
  function hasPositionalArgs(args) {
496
- return Object.values(args).some((arg) => arg.type === "positional");
505
+ return getVisiblePositionalArgs(args).length > 0;
497
506
  }
498
507
  /**
499
508
  * Check if all options have default values
@@ -502,7 +511,8 @@ function hasPositionalArgs(args) {
502
511
  * @returns True if all options have default values
503
512
  */
504
513
  function hasAllDefaultOptions(args) {
505
- return !!(args && Object.values(args).every((arg) => arg.default));
514
+ const visibleOptionalArgs = getVisibleOptionalArgs(args);
515
+ return visibleOptionalArgs.length > 0 && visibleOptionalArgs.every(([_, arg]) => arg.default);
506
516
  }
507
517
  /**
508
518
  * Generate options symbols for usage
@@ -512,7 +522,7 @@ function hasAllDefaultOptions(args) {
512
522
  * @returns Options symbols for usage
513
523
  */
514
524
  async function generateOptionsSymbols(ctx, args) {
515
- return hasOptionalArgs(args) ? hasAllDefaultOptions(args) ? `[${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}]` : `<${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}>` : "";
525
+ return getVisibleOptionalArgs(args).length > 0 ? hasAllDefaultOptions(args) ? `[${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}]` : `<${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}>` : "";
516
526
  }
517
527
  /**
518
528
  * Get optional arguments pairs for usage
@@ -521,8 +531,7 @@ async function generateOptionsSymbols(ctx, args) {
521
531
  * @returns Options pairs for usage
522
532
  */
523
533
  function getOptionalArgsPairs(ctx) {
524
- return Object.entries(ctx.args).reduce((acc, [name, schema]) => {
525
- if (schema.type === "positional") return acc;
534
+ return getVisibleOptionalArgs(ctx.args).reduce((acc, [name, schema]) => {
526
535
  let key = makeShortLongOptionPair(schema, name, ctx.toKebab);
527
536
  if (schema.type !== "boolean") {
528
537
  const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
@@ -562,9 +571,11 @@ async function resolveDisplayValue(ctx, key) {
562
571
  * @returns Generated options usage
563
572
  */
564
573
  async function generateOptionalArgsUsage(ctx, optionsPairs) {
565
- const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
566
- const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
567
- return (await Promise.all(Object.entries(optionsPairs).map(async ([key, value]) => {
574
+ const optionsPairsEntries = Object.entries(optionsPairs);
575
+ if (optionsPairsEntries.length === 0) return "";
576
+ const optionsMaxLength = Math.max(...optionsPairsEntries.map(([_, value]) => value.length));
577
+ const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...optionsPairsEntries.map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
578
+ return (await Promise.all(optionsPairsEntries.map(async ([key, value]) => {
568
579
  let rawDesc = await ctx.extensions[pluginId].text(resolveArgKey(key, ctx.name));
569
580
  if (!rawDesc && key.startsWith("no-")) {
570
581
  const name = resolveNegatableKey(key);
@@ -581,10 +592,11 @@ async function generateOptionalArgsUsage(ctx, optionsPairs) {
581
592
  }))).join("\n");
582
593
  }
583
594
  function getPositionalArgs(args) {
584
- return Object.entries(args).filter(([_, schema]) => schema.type === "positional");
595
+ return getVisiblePositionalArgs(args);
585
596
  }
586
597
  async function generatePositionalArgsUsage(ctx) {
587
598
  const positionals = getPositionalArgs(ctx.args);
599
+ if (positionals.length === 0) return "";
588
600
  const argsMaxLength = Math.max(...positionals.map(([name]) => name.length));
589
601
  return (await Promise.all(positionals.map(async ([name]) => {
590
602
  const desc = await ctx.extensions[pluginId].text(resolveArgKey(name, ctx.name)) || ctx.args[name].description || "";
@@ -593,7 +605,8 @@ async function generatePositionalArgsUsage(ctx) {
593
605
  }))).join("\n");
594
606
  }
595
607
  function generatePositionalSymbols(args) {
596
- return hasPositionalArgs(args) ? getPositionalArgs(args).map(([name, arg]) => {
608
+ const visiblePositionalArgs = getVisiblePositionalArgs(args);
609
+ return visiblePositionalArgs.length > 0 ? visiblePositionalArgs.map(([name, arg]) => {
597
610
  const elements = [];
598
611
  if (arg.multiple) {
599
612
  if (arg.required) elements.push(`<${name}>`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin-renderer",
3
3
  "description": "usage renderer plugin for gunshi",
4
- "version": "0.34.0",
4
+ "version": "0.35.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -53,10 +53,10 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@gunshi/plugin": "0.34.0"
56
+ "@gunshi/plugin": "0.35.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-i18n": "0.34.0"
59
+ "@gunshi/plugin-i18n": "0.35.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "deno": "^2.7.14",
@@ -64,7 +64,7 @@
64
64
  "jsr-exports-lint": "^0.4.2",
65
65
  "publint": "^0.3.20",
66
66
  "tsdown": "0.21.0",
67
- "@gunshi/shared": "0.34.0"
67
+ "@gunshi/shared": "0.35.0"
68
68
  },
69
69
  "scripts": {
70
70
  "build": "tsdown",