From 218b130ba5b2c7223eb471e23bcdcfbabc6861b4 Mon Sep 17 00:00:00 2001 From: Paul Armstrong Date: Mon, 27 Nov 2023 16:48:23 -0800 Subject: [PATCH] fix: preserve --show-advanced to sub-commands (#447) **Problem:** Using `--show-advanced` on subcommands isn't showing the hidden/advanced options. **Solution:** Yargs doesn't seem to automatically carry this option through to subcommands, so forcing it across in the command visitor will apply it correctly. --- .changeset/plenty-pigs-decide.md | 7 +++++++ modules/yargs/src/yargs.ts | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .changeset/plenty-pigs-decide.md diff --git a/.changeset/plenty-pigs-decide.md b/.changeset/plenty-pigs-decide.md new file mode 100644 index 00000000..9d24ac7a --- /dev/null +++ b/.changeset/plenty-pigs-decide.md @@ -0,0 +1,7 @@ +--- +'@onerepo/core': patch +'onerepo': patch +'@onerepo/yargs': patch +--- + +Worked around a bug in Yargs that prevented `--show-advanced` from showing hidden/advanced help documentation when used on sub-commands. diff --git a/modules/yargs/src/yargs.ts b/modules/yargs/src/yargs.ts index 7ed155c9..03e2c997 100644 --- a/modules/yargs/src/yargs.ts +++ b/modules/yargs/src/yargs.ts @@ -40,7 +40,7 @@ export function setupYargs(yargs: Yargv): Yargs { .middleware(setEnvironmentMiddleware, true) .middleware(sudoCheckMiddleware(yargs), true) .wrap(Math.min(160, process.stdout.columns)) - .showHidden('show-advanced', 'Show advanced options') + .showHidden('show-advanced', 'Pair with `--help` to show advanced options.') .group('show-advanced', 'Global:') .global('show-advanced') .group('help', 'Global:') @@ -90,7 +90,7 @@ export const commandDirOptions = ({ exclude, recurse: false, visit: function visitor(commandModule) { - const { command, description, handler, ...rest } = commandModule; + const { command, description, handler, builder } = commandModule; // Very arbitrary, but require at least 4 words in the description to help end users if (description !== false && description.split(' ').length < 3) { @@ -100,7 +100,12 @@ export const commandDirOptions = ({ return { command, description, - ...rest, + // Need to re-attach `.showHidden()` to due a bug in Yargs in which commadDir doesn't respond to it, even though it does get listed in the `--help` output + builder: (yargs: Yargs) => + builder(yargs) + .showHidden('show-advanced', 'Pair with `--help` to show advanced options.') + .group('show-advanced', 'Global:') + .global('show-advanced'), handler: async (argv: Arguments) => { performance.mark('onerepo_start_Startup hooks'); await startup(argv);