-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Using .name and .description has unexpected results. #516
Comments
And just so we know what I'm talking about, here's a little code sample. my_cli.js program
.version("0.0.1")
.option('-c, --configure', 'Configure AppHub credentials.')
.option('-d, --description', 'Description of the AppHub package.')
.option('-n, --name', 'Name of the AppHub package.')
console.log(program.configure)
console.log(program.description)
console.log(program.name) $ ./my_cli.js --configure --description --name
# =>
true
true
true $ ./my_cli.js
# =>
undefined
function()
function() |
AFAICT this is a bad namespacing problem; enough reason to not use this lib at all. All TJ would have had to do to solve this would be to put everything on program.args, as in program.args.configure and program.args.description instead just on program itself, as in program.description and program.configure. Frankly I don't get it, but I guess it's sleeker to just put it on program, but that's not good IMO. |
would love to use .name, too and @ORESoftware solution sounds simple?! |
@CanRau - I recommend ditching commander and using "dashdash" from Trent Mick => README.md at master on trentm/node-dashdash |
subcommands seem more complex but I'll look more into it tomorrow thanks for the hint. |
I just ran into this bug too, and it looks like it's been around for years with no fix: #19. That earlier issue mentions adding a Am I missing some way of using properties with these reserved names? Obviously some are unlikely to cause conflicts, but quite a few of them seem like they'd be popular names for options, so I'm surprised commander.js continues to be used so widely if it fails in a bizarre and undocumented way with certain names (like "name" or "action"). These are the names, not including several more that start with underscores:
|
I've moved to https://www.npmjs.com/package/argparse because of this limitation. |
I have opened a Pull Request which allows storing option values separately rather than as command properties (access using See #1102 |
I should have expected this but it caught me off guard and wasted some cycles.
There's probably a list of protected words. Adding something to the docs or code to say you can't use those words as option names would be great.
I'll do the PR if someone can help with the protected words for the options.
The text was updated successfully, but these errors were encountered: