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

Using .name and .description has unexpected results. #516

Closed
joshuapinter opened this issue Mar 26, 2016 · 9 comments
Closed

Using .name and .description has unexpected results. #516

joshuapinter opened this issue Mar 26, 2016 · 9 comments

Comments

@joshuapinter
Copy link

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.

@joshuapinter
Copy link
Author

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

@ORESoftware
Copy link

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.

@CanRau
Copy link

CanRau commented Aug 26, 2016

would love to use .name, too and @ORESoftware solution sounds simple?!

@ORESoftware
Copy link

@CanRau - I recommend ditching commander and using "dashdash" from Trent Mick =>

README.md at master on trentm/node-dashdash
https://github.com/trentm/node-dashdash/blob/master/README.md

@CanRau
Copy link

CanRau commented Aug 26, 2016

subcommands seem more complex but I'll look more into it tomorrow thanks for the hint.
just found https://www.npmjs.com/package/wiz-cliparse which might be interesting..
maybe minimist could be enough though..

@kcivey
Copy link

kcivey commented Sep 1, 2016

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 .opts property that would be only the options, with none of the interfering methods,, but that doesn't exist (there's a function there instead, which still has the same problems, returning a function for name and other options that conflict with methods).

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:

  • action
  • addImplicitHelpCommand
  • alias
  • allowUnknownOption
  • args
  • arguments
  • command
  • Command
  • commandHelp
  • commands
  • description
  • executeSubCommand
  • help
  • helpInformation
  • largestOptionLength
  • missingArgument
  • name
  • normalize
  • option
  • Option
  • optionFor
  • optionHelp
  • optionMissingArgument
  • options
  • opts
  • outputHelp
  • parse
  • parseArgs
  • parseExpectedArgs
  • parseOptions
  • rawArgs
  • unknownOption
  • usage
  • variadicArgNotLast
  • version

@supnate
Copy link

supnate commented Nov 18, 2016

I've moved to https://www.npmjs.com/package/argparse because of this limitation.

@shadowspawn
Copy link
Collaborator

Closing in favour of #183
See also #933

@shadowspawn
Copy link
Collaborator

shadowspawn commented Nov 23, 2019

I have opened a Pull Request which allows storing option values separately rather than as command properties (access using .opts()), and passes the options (rather than the command) to the action handler.

See #1102

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

6 participants