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

'version' is interpreted as '--version' #471

Closed
fatso83 opened this issue Nov 18, 2015 · 5 comments · Fixed by #494
Closed

'version' is interpreted as '--version' #471

fatso83 opened this issue Nov 18, 2015 · 5 comments · Fixed by #494
Labels
bug Commander is not working as intended

Comments

@fatso83
Copy link

fatso83 commented Nov 18, 2015

According to the docs, only "my-cmd --version" should output the version number, but I have found that commander also picks up the string 'version' anywhere in the arguments.

As an example of where this causes problems, you can have a look at a little utility I wrote called pick_json. It is used it to extract fields from json on stdin.

$ echo '{ "name" : "myapp", "version" : "3.4.5" }' > appinfo.json

$ pick_json name < appinfo.json
myapp

$ pick_json version < appinfo.json  #WTF moment
1.1.2

$ pick_json --version
1.1.2

As you can see, instead of picking the version field from the json, it shows the version number of pick_json. This is not inline with the docs.

@SomeKittens
Copy link
Collaborator

Does the bug still happen if you put version in quotes?

@fatso83
Copy link
Author

fatso83 commented Nov 19, 2015

Yup

carl-erik at timbuktu in ~/kode/pick_json  (master)
$ pick_json "version" < appinfo.json
1.1.1

carl-erik at timbuktu in ~/kode/pick_json  (master)
$ pick_json 'version' < appinfo.json
1.1.1

But that really does not come as a surprise, as the shell does the unescaping. I can escape the quotes, as in pick_json '"version"', but then you are already way into hack and slash programming to work around the bug, and it doesn't work anyway (in my case).

@SomeKittens SomeKittens added the bug Commander is not working as intended label Nov 19, 2015
@SomeKittens
Copy link
Collaborator

Yup, definitely a bug on our side.

@fatso83
Copy link
Author

fatso83 commented Nov 19, 2015

I looked at the source, and it happens due to the logic in parseOptions and parseArgs that does away with the dashes, and subsequently "--version" and "version" both emits the same signal.

Not totally sure how to fix this in a nice way.

@fatso83
Copy link
Author

fatso83 commented Nov 19, 2015

Maybe Options should have a prefixed name to avoid overlapping event names? I understand that this might be troublesome due to the logic involving the "--no-" prefixes.

Whatever the solution might be, "--version" and "version" should result in two different event names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Commander is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants