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

fix: show hidden options in help #962

Merged
merged 1 commit into from Oct 14, 2017
Merged

Conversation

laggingreflex
Copy link
Contributor

Options with description: false will now show up help

fixes #851

yargs.js Outdated
@@ -644,9 +645,11 @@ function Yargs (processArgs, cwd, parentRequire) {
self.skipValidation(key)
}

const desc = opt.describe || opt.description || opt.desc
const desc = 'describe' in opt ? opt.describe : 'description' in opt ? opt.description : 'desc' in opt ? opt.desc : undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Ternary operator which is nested 3 times is really hard to understand. I think it will be better if it will be splitted in some more cases to be easier to read.

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.

Looks good to me, do you sign off too @Morishiri?

@laggingreflex
Copy link
Contributor Author

laggingreflex commented Sep 29, 2017

Having second thoughts on this. Currently it shows options if their description is set to false. (as per your comment @bcoe). Would it be better if it shows options when description is left blank, and doesn't show when it's set to false? This would also be more inline with the current docs (as pointed out by @gajus)

exports.describe: string used as the description for the command in help text, use false for a hidden command

Or would that break existing usage?

@gajus
Copy link
Contributor

gajus commented Sep 29, 2017

Would it be better if it shows options when description is left blank, and doesn't show when it's set to false? This would also be more inline with the current docs (as pointed out by @gajus)

👍

@bcoe
Copy link
Member

bcoe commented Oct 3, 2017

@laggingreflex good catch; I'm with both you and @gajus on this.

Let's show the option if an empty string is provided for the description, hide on null, false, undefined.

Sound reasonable?

@gajus
Copy link
Contributor

gajus commented Oct 3, 2017

I still think that an explicit option should be used to make a parameter hidden. All this convention based behaviour is tricky to document/ remember.

As long as option is provided, it should be visible, unless that option contains configuration {hidden: true}, i.e.

.options({
  foo: {
    describe: 'FOO'
  },
  bar: {},
  baz: {
    describe: 'BAZ',
    hidden: true
  }
});

With this configuration,

  • foo and bar are visible by default
  • baz is visible if --yargs-show-hidden (or whatever) option is provided

The benefits of this approach:

  • You can validate that describe value is a string
  • Hidden options can have a description

@bcoe
Copy link
Member

bcoe commented Oct 4, 2017

@gajus this argument seems reasonable to me, and I think we're inching up on a new major release of yargs any ways, with some of the work I've been doing around command parsing/number coercion.

@laggingreflex thoughts on the options discussed above?

@bcoe
Copy link
Member

bcoe commented Oct 13, 2017

@laggingreflex this looks good to me; any idea why test coverage dropped so much?

@laggingreflex
Copy link
Contributor Author

I was testing with .only locally which dropped the coverage. Fixed now.

Also this doesn't yet implement --yargs-show-hidden, I'm working on an alternative for that.

@bcoe
Copy link
Member

bcoe commented Oct 13, 2017

@laggingreflex 👍 I'm working on a pretty big 10.x release, it would be nice to land this in it (I'd also love help testing the changes on master when you have time).

@laggingreflex
Copy link
Contributor Author

laggingreflex commented Oct 13, 2017

Instead of --yargs-show-hidden (@gajus) how about this:

yargs.showHelp('log', {showHidden: [true|false]})

This gives the user more control. Like maybe they wouldn't want to show hidden commands at all. Or maybe they'd want it behind a custom flag. This way they can implement it themselves.

It however require that the user implements the --help themselves too:

const argv = yargs
  .options({
    baz: {
      describe: 'BAZ',
      hidden: true
    },
    'show-hidden': {
      describe: 'Show hidden options',
      type: 'boolean'
    },
  })
  .help(false)
  .argv

if (yargs.help) {
  yargs.showHelp('log', {hidden: argv.showHidden})
}

@bcoe
Copy link
Member

bcoe commented Oct 13, 2017

@laggingreflex I'd be tempted to discuss --yargs-show-hidden in a separate issue. I think that this feature is enough of an edge-case that there's benefit to landing this feature first... mainly, I'm on the fence about --yargs-show-hidden; for starters I don't like baking the yargs name into a flag, so I'd probably call it something like --show-hidden (folks calling this flag feels like an edge-case to me though).

@laggingreflex
Copy link
Contributor Author

I've undone the last commit and I'll move it to a separate issue/pr.

This now only enables the {hidden: true} option to hide the option from --help (instead of by omitting the description).

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.

options without description to not appear in --help
4 participants