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

Help- and version option description not shown #1820

Closed
OsmanAltun opened this issue Dec 4, 2020 · 1 comment · Fixed by #1882
Closed

Help- and version option description not shown #1820

OsmanAltun opened this issue Dec 4, 2020 · 1 comment · Fixed by #1882

Comments

@OsmanAltun
Copy link
Contributor

The code:

const yargs = require('yargs').locale('en')

let output

const options = {
    exec: { alias: 'e', desc: 'Dis supposed to be exec', type: 'string', requiresArg: true },
    h: { alias: 'help', desc: 'Dis supposed to be help' },
    v: { alias: 'version', desc: 'Dis supposed to be version' }
}

yargs.options(options)

yargs.parse(['--help'], (_err, _argv, _output) => { output = _output })

console.log(output)

Expected output:

Options:
  -e, --exec      Dis supposed to be exec                                [string]
  -h, --help      Dis supposed to be help                                [boolean]
  -v, --version  Dis supposed to be version                              [boolean]

Actual output:

Options:
  -e, --exec     Dis supposed to be exec                                [string]
  -h, --help     Show help                                             [boolean]
  -v, --version  Show version number                                   [boolean]

Note
No need for a workaround since I already got one, but I just wanted to mention this so it would get fixed.

@bcoe
Copy link
Member

bcoe commented Feb 28, 2021

@OsmanAltun I think what's actually happening here, is that because .help() and .version() are special options which are automatically registered, overriding their description is not having the intended affect. Probably because, when an inner command fires, it just re-adds the .help() and .version() with their default description.

Here's a workaround I'd suggest, if you want to override their default text:

import yargs from 'yargs'

const y = yargs().locale('en')
y.updateStrings({
  'Show help': 'Dis supposed to be help',
  'Show version number': 'Dis supposed to be version'
})

let output

const options = {
    exec: { alias: 'e', desc: 'Dis supposed to be exec', type: 'string', requiresArg: true },
    h: { alias: 'help' },
    v: { alias: 'version' }
}

y.options(options)

y.parse(['--help'], (_err, _argv, _output) => { output = _output })

console.log(output)

☝️ keeping in mind that this means people in other locales won't get the benefit of a translated string.


While I think this issue might have inadvertently been addressed by #1826, I think actually supporting the behavior of allowing the description of --help and --version to be overridden is likely just a new feature we'd need to add.

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

Successfully merging a pull request may close this issue.

2 participants