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

.count misbehaves with hyphenated flags #256

Closed
kahlil opened this issue Sep 14, 2015 · 10 comments
Closed

.count misbehaves with hyphenated flags #256

kahlil opened this issue Sep 14, 2015 · 10 comments
Labels

Comments

@kahlil
Copy link

kahlil commented Sep 14, 2015

If I do something like this:

var opts = require('yargs')
    .count('log-level')
    .alias('l', 'log-level')
    .argv;

console.log(opts);

And pass -lll yargs will always count 2 no matter what. If I use loglevel as the main name of the flag it counts them correctly.

@bcoe bcoe added the bug label Sep 15, 2015
@bcoe
Copy link
Member

bcoe commented Sep 15, 2015

Hey @kahlil what version of yargs are you running, I can't seem to reproduce:

#!/usr/bin/env node

var opts = require('./')
    .count('log-level')
    .alias('l', 'log-level')
    .argv;

console.log(opts);
Benjamins-MacBook-Pro:yargs benjamincoe$ ./test.js -llll
{ _: [], l: 4, 'log-level': 4, logLevel: 4, '$0': 'test.js' }

@phated
Copy link

phated commented Sep 15, 2015

Sorry, this is probably related to gulp-cli, which is on a super old version (1.3.3). I am working on updating it now.

@phated
Copy link

phated commented Sep 15, 2015

Ref #78

@kahlil
Copy link
Author

kahlil commented Sep 15, 2015

Oops, @phated is right. I did not check the version! Sorry for this 🙏

@nexdrew
Copy link
Member

nexdrew commented Sep 15, 2015

Closing based on previous comments. If you find another problem, please open a new issue. Thanks!

@nexdrew nexdrew closed this as completed Sep 15, 2015
@hildjj
Copy link

hildjj commented Nov 30, 2015

With version 3.30.0:

var argv = require('yargs')
.options({
  verbose: {
    description: 'Verbose output',
    boolean:     true,
    count:       true,
    alias:       'v'
  }
}).argv;

console.log(argv.verbose);  // outputs 2+count(v)

With .options, the count is always 2 more than it should be. Using:

var argv = require('yargs')
    .count('verbose')
    .alias('v', 'verbose')
    .argv;

everything seems to work fine.

@hildjj
Copy link

hildjj commented Nov 30, 2015

Actually, it's the boolean: true that's causing the issue, not .options.

@nexdrew
Copy link
Member

nexdrew commented Nov 30, 2015

@hildjj Thanks for pointing this out! count is just a special form of boolean, so the boolean part is superfluous/unnecessary.

@hildjj
Copy link

hildjj commented Nov 30, 2015

Perhaps a warning/error, then, if you specify both? Starting the count at 2 was unexpected behavior.

@nexdrew
Copy link
Member

nexdrew commented Nov 30, 2015

@hildjj Agreed. Would you mind creating a new ticket for that?

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

No branches or pull requests

5 participants