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

How to have an option with-a-dash in the name? #46

Closed
ghost opened this issue Jun 26, 2015 · 1 comment
Closed

How to have an option with-a-dash in the name? #46

ghost opened this issue Jun 26, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 26, 2015

I was using the following code and I could have swore that it was working, but it does not seem to be working today. args["no-restart"] and args["init-default"] are always undefined even when they exist in process.argv as '--init-default' and '--no-restart'.

Is this supported and if not, is there any reason that it should not be?

exports.known = {
  help: Boolean, 
  "init-default": Boolean,
  "no-restart": Boolean,
  verbose: Boolean,
  version: Boolean,
  path: path
};

exports.aliases = {
  h: '--help', 
  v: '--version',
  V: '--verbose'
};

var args = nopt(exports.known, exports.aliases, process.argv, 2);
var remain = args.argv.remain;
if (remain && remain.length > 0) {
  args.path = remain[0];
}

args.initDefault = args["init-default"];
args.noRestart = args["no-restart"];
// ...
@ghost
Copy link
Author

ghost commented Jun 26, 2015

OK, I figured it out - you can't have a flag that starts with "no-" because nopt does auto-negation based on the "no-" prefix. (So you have to have a flag called "whatever" instead of "no-whatever".)

This issue was closed.
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

No branches or pull requests

0 participants