Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe field is not show in command function #2140

Closed
yhojann-cl opened this issue Feb 27, 2022 · 2 comments
Closed

Describe field is not show in command function #2140

yhojann-cl opened this issue Feb 27, 2022 · 2 comments
Labels

Comments

@yhojann-cl
Copy link

yhojann-cl commented Feb 27, 2022

By example:

const yargs = require('yargs');

yargs(process.argv.slice(2))
    .command('$0 <foo>', 'Description', (yargs) => {
        yargs
        .positional('foo', { describe: 'Foo', type: 'string', demand: true })
        .option('bar', { alias: 'b', describe: 'Bar' })
    }).argv

The result is:

$ moduleBinary
moduleBinary <foo>

Description

Positionals:
  foo                                                     [cadena de caracteres]

Opciones:
  --help     Muestra ayuda                                            [booleano]
  --version  Muestra número de versión                                [booleano]

Hacen falta argumentos no-opcionales: Número recibido 0, necesita por lo menos 1

foo description is hidden and bar option is hidden, but when call --help option can see all texts:

$ moduleBinary --help
moduleBinary <foo>

Description

Positionals:
  foo  Foo                                                [cadena de caracteres]

Opciones:
      --help     Muestra ayuda                                        [booleano]
      --version  Muestra número de versión                            [booleano]
  -b, --bar      Bar

Version: 17.3.1.

@bcoe bcoe added bug p2 p1 and removed p2 labels Mar 19, 2022
@jly36963
Copy link
Contributor

jly36963 commented Apr 1, 2022

I believe this problem is solved in yargs 17.4. Prior to that version, there was a bug with failed default commands and the resulting usage output. If I remember correctly, user-defined args were missing descriptions, and optional args were omitted completely.
PR

const input = ''

yargs(input)
  .command({
    command: '$0 <arg1>',
    desc: 'default desc',
    builder: yargs => yargs
      .option('arg1', {
        type: 'string',
        desc: 'arg1 desc (default command)',
        demandOption: true
      })
      .option('arg2', {
        type: 'string',
        desc: 'arg2 desc (default command)'
      }),
    handler: argv => {
      console.log(argv)
    }
  })
  .strict()
  .parse()

Before the fix:

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --arg1                                                     [string] [required]

After the fix:

Options:
 --help     Show help                                                 [boolean]
 --version  Show version number                                       [boolean]
 --arg1     arg1 desc (default command)                     [string] [required]
 --arg2     arg2 desc (default command)                                [string]

@jly36963 jly36963 self-assigned this Apr 1, 2022
@jly36963 jly36963 removed their assignment Jan 29, 2023
@shadowspawn
Copy link
Member

This was likely an interaction with the default command, and has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants