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

feature: add method to hide option extras #2156

Merged
merged 10 commits into from Dec 28, 2022
Merged

feature: add method to hide option extras #2156

merged 10 commits into from Dec 28, 2022

Conversation

jly36963
Copy link
Contributor

@jly36963 jly36963 commented Mar 27, 2022

Addresses: #2153

Description

Given the following:

yargs('cmd1 --help')
  .command(
    'cmd1',
    'cmd1 desc',
    yargs => yargs
      .option('opt1', {
        type: 'string',
        choices: ['foo', 'bar', 'baz'],
        alias: 'o',
        required: true,
        description: "A long description that might break formatting"
      }),
    argv => console.log(argv)
  )
  .hideOptionExtras()
  .strict()
  .parse()

The hideOptionExtras would cause the following output

cmd1 desc

Options:
      --help     Show help                                             [boolean]
      --version  Show version number                                   [boolean]
  -o, --opt1     A long description that might break formatting
                              [string] [required] [choices: "foo", "bar", "baz"]

to look like this instead

cmd1 desc

Options:
      --help     Show help
      --version  Show version number
  -o, --opt1     A long description that might break formatting

Questions

If this works, I'll add unit tests.
What other things would need to change? (docs, examples, etc)

@jly36963 jly36963 requested a review from bcoe March 27, 2022 16:59
Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about adding one off functions to tweak yargs' default layout. What if instead we did something like we did with parserConfiguration. Add a helper usageConfiguration, which we can gradually add more layout options to:

yargs.usageConfiguration({
  'show-types': false
})

@jly36963 jly36963 requested a review from bcoe March 30, 2022 02:57
Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jly36963 this is great work, thank you 👏

One ask, would it be possible to add this setting in the list here: https://github.com/yargs/yargs/blob/main/docs/api.md#parserconfigurationobj

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this. I think usageConfiguration will help us provide nuanced configuration without adding 1,000,000 additional methods.

@ljharb
Copy link
Contributor

ljharb commented Jan 29, 2023

I’m a bit confused; how can i show types in general, but hide types for an a specific option?

@jly36963
Copy link
Contributor Author

@ljharb I don't think there is a way currently. It would likely be a new property on option/positional objects like hideUsageTypes, or potentially a refactor on the usage logic to allow for customizations.

I won't be involved with this package much in the future, so I won't be much help in implementing this change

@ljharb
Copy link
Contributor

ljharb commented Jan 29, 2023

In that case, this does not solve #1145, thanks for confirming.

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.

None yet

3 participants