yargs / yargs/yargs

help for subcommand not showing

Open
#1,500 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
JavaScript
Stars
11.5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

My yargs structure shows top-level help when I call

node yargs-issue.js --help

generate plain html from json

Commands:
  yargs-issue.js plain <json>  generate plain html from json           [default]
  yargs-issue.js audio <json>  generate html with audio support

Positionals:
  json  the json file as found in the ../JSON/ directory

Options:
  --version           Show version number                              [boolean]
  --help              Show help                                        [boolean]
  --speakers, -s      speakers                                [array] [required]
  --release-date, -r  release date, e.g. 'November 25, 2019'          [required]

But when I try to invoke help from a subcommand:

./yargs-issue.js audio --help

the options for that subcommand are not shown. Instead I get the exact same output as before.
However, if I call the audio subcommand incorrectly by omitting a required option, I get the desired information about the subcommand-specific options:

node yargs-issue.js audio
yargs-issue.js audio <json>

generate html with audio support

Positionals:
  json  the json file as found in the ../JSON/ directory

Options:
  --version           Show version number                              [boolean]
  --help              Show help                                        [boolean]
  --speakers, -s      speakers                                [array] [required]
  --release-date, -r  release date, e.g. 'November 25, 2019'          [required]
  --audio-file, -a    audio file
  --audio-offset, -o  audio file offset when speech starts in seconds [float]
                                                                      [required]

Not enough non-option arguments: got 0, need at least 1

This is the source code of yargs-issue.js

const argv = require('yargs')
  .command(['plain <json>', '$0'], 'generate plain html from json', yargs => {
    yargs
    .positional('json', {
      describe: 'the json file as found in the ../JSON/ directory',
      nargs: 1,
      global: true, // used for both plain and audio commands
    })
    .option('speakers', {
      alias: 's',
      describe: 'speakers',
      demandOption: true,
      array: true,
      global: true,
    })
    .option('release-date', { // (will be renamed to releaseDate)
      alias: 'r',
      describe: 'release date, e.g. \'November 25, 2019\'',
      demandOption: true,
      nargs: 1,
      global: true,
    })
    .command('audio <json>', 'generate html with audio support', 
      yargs => { // builder
        return yargs
          .option('audio-file', {
            alias: 'a',
            describe: 'audio file',
            nargs: 1,
          })
          .option('audio-offset', { 
            alias: 'o',
            describe: 'audio file offset when speech starts in seconds [float]',
            demandOption: true,
            nargs: 1,
          })
      },
    )
  })
  .strict()
  .help()
  .argv

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the command definitions and help configuration in yargs-issue.js. Reproduce the behavior with ./yargs-issue.js audio --help and compare it with the missing-option output from node yargs-issue.js audio. Done means the audio subcommand displays its own options when invoked with --help, without changing the top-level help output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.