Skip to content

Allow custom description for special options#1882

Merged
bcoe merged 10 commits intoyargs:masterfrom
OsmanAltun:fix-1820
Apr 11, 2021
Merged

Allow custom description for special options#1882
bcoe merged 10 commits intoyargs:masterfrom
OsmanAltun:fix-1820

Conversation

@OsmanAltun
Copy link
Copy Markdown
Contributor

This PR fixes #1820

@bcoe bcoe mentioned this pull request Apr 4, 2021
7 tasks
@bcoe
Copy link
Copy Markdown
Member

bcoe commented Apr 11, 2021

@OsmanAltun being able to set a custom description and aliases was already supported for help(), .version(), you just need to make sure to do it separately through .alias() and .describe().

The fact that the approach of setting a description and alias through .options() partially worked is a bug -- we could try to make it so that we check, at the time of setting the options, whether they collide with the help or version option, and then merge the settings together -- but, given that you can already get the intended behavior (as demonstrated in the updated tests) I think it's probably better to leave things for now.

@bcoe bcoe merged commit ecbc037 into yargs:master Apr 11, 2021
@OsmanAltun
Copy link
Copy Markdown
Contributor Author

make sure to do it separately through .alias() and .describe().

I already know this and did this on day one, however if help and version could somehow be treated the same as a non-special options, I could place all options in a single place. This is better for readability I believe.

Expected:

// variables

const options = {
  streaming: {
    chromecast: { desc: 'Google Chromecast', defaultDescription: 'all' },
  },
  simple: {
    t: { alias: 'subtitles', desc: 'Load subtitles file', type: 'string', requiresArg: true },
    h: { alias: 'help', desc: 'help info' },
    v: { alias: 'version', desc: 'version info' }
  },
  advanced: {
    p: { alias: 'port', desc: 'Change the http server port', default: 8000, requiresArg: true },
  }
}

// config

yargs
  .command(commands)
  .options(options.streaming).group(Object.keys(options.streaming), 'Options (streaming): ')
  .options(options.simple).group(Object.keys(options.simple), 'Options (simple): ')
  .options(options.advanced).group(Object.keys(options.advanced), 'Options (advanced)')

currently:

// variables

const options = {
  streaming: {
    chromecast: { desc: 'Google Chromecast', defaultDescription: 'all' },
  },
  simple: {
    t: { alias: 'subtitles', desc: 'Load subtitles file', type: 'string', requiresArg: true },
  },
  advanced: {
    p: { alias: 'port', desc: 'Change the http server port', default: 8000, requiresArg: true },
  }
}

// config

yargs
  .command(commands)
  .options(options.streaming).group(Object.keys(options.streaming), 'Options (streaming): ')
  .options(options.simple).group(Object.keys(options.simple).concat(['help', 'version']), 'Options (simple): ')
  .options(options.advanced).group(Object.keys(options.advanced), 'Options (advanced)')
  .alias({ h: 'help', v: 'version' })
  .describe({ help: 'Show help information', version: 'Show version information' })

Having said that, this is no big deal since I got the intended behavior already, but I would appreciate it if u opened an issue referencing this to fix at a later date/release maybe.

@OsmanAltun OsmanAltun deleted the fix-1820 branch July 16, 2021 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Help- and version option description not shown

2 participants