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

Specifying both count and boolean should throw error #216

Open
hildjj opened this issue Nov 30, 2015 · 3 comments
Open

Specifying both count and boolean should throw error #216

hildjj opened this issue Nov 30, 2015 · 3 comments

Comments

@hildjj
Copy link

hildjj commented Nov 30, 2015

As discussed in yargs/yargs#256, specifying both count and boolean is a programming error. yargs should throw an exception, or at the very least print a warning. If printing a warning is chosen, the default count should be 0 instead of 2 (as is currently the case).

@plroebuck
Copy link

This is still broken as of yargs-v11.0.0.
Should throw an exception if .boolean() method is used with .count() for the same option.

#!/usr/bin/env node
'use strict';

var argv = require('yargs')
  .options({
    'verbose': {
      description: 'Set verbosity level',
      boolean: true,
      count: true,
      alias: 'v'
    }
  })
  .help('help', 'Show usage information and exit')
  .argv;

console.log(argv.verbose);  // outputs 2+count(v)
$ expect="3"
$ out=$(bin/testme -vvv)
$ if [ "${expect}" = "${out}" ]; then echo "success"; else echo "failed: expect=${expect}, actual=${out}"; fi
failed: expect=3, actual=5

@bcoe
Copy link
Member

bcoe commented Mar 4, 2018

@hildjj @plroebuck let's start by printing a warning if you use two mutually exclusive options in yargs ... this will encourage folks to stop doing so, but will allow us to release the update without it being a breaking change.

I bet there are a few other combinations of options we could come up with that shouldn't be possible in conjunction, so we should try to write this warning mechanism in a way that's easy to sprinkle throughout the codebase.

I would love help working on this issue, if either of you are interested?

@bcoe bcoe transferred this issue from yargs/yargs Nov 9, 2019
@bcoe
Copy link
Member

bcoe commented Nov 9, 2019

@juergba has been starting to add some of this validation logic, see:

#191

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

No branches or pull requests

3 participants