Skip to content

Specifying both count and boolean should throw error #216

Open

Description

@hildjj

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).

Activity

  1. plroebuck commented on Feb 26, 2018

    @plroebuck

    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
  2. bcoe commented on Mar 4, 2018

    @bcoe
    Member

    @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?

  3. transferred this issue fromyargs/yargson Nov 9, 2019
  4. bcoe commented on Nov 9, 2019

    @bcoe
    Member

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions