Skip to content

Commit

Permalink
fix: preserve --show-advanced to sub-commands (#447)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
paularmstrong authored Nov 28, 2023
1 parent 3051ff2 commit 218b130
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/plenty-pigs-decide.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 8 additions & 3 deletions modules/yargs/src/yargs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Expand Down Expand Up @@ -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) {
Expand All @@ -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<DefaultArgv>) => {
performance.mark('onerepo_start_Startup hooks');
await startup(argv);
Expand Down

0 comments on commit 218b130

Please sign in to comment.