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

#395 fix, short options do not understand adjacent values #599

Closed
wants to merge 1 commit into from

Conversation

TheRoSS
Copy link
Contributor

@TheRoSS TheRoSS commented Dec 28, 2016

Example of the bug:

commander.option("-c ")
console.log("C:", commander.C)

$ node program -c234
C: -2

@shadowspawn
Copy link
Collaborator

It looks like this pull request works with -a234 => a=234 for an option taking a value, and -xyz => -x -y -z if x is a boolean flag, but leaves some combination cases like -axz 3 or -xa234.

It would be nice if there was a standard we could refer to for short flag handling. Should we only consider numbers?

Keeping pull request open for now.

@shadowspawn
Copy link
Collaborator

Link to issue: #395

@shadowspawn
Copy link
Collaborator

shadowspawn commented Apr 4, 2019

Found a couple of posix references which align with suggested pull request, and python adds the last short flag taking a value.

  1. https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

Multiple options may follow a hyphen delimiter in a single token if the options do not take arguments. Thus, ‘-abc’ is equivalent to ‘-a -b -c’.

  1. https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html#Example-of-Getopt
% testopt -a -b
aflag = 1, bflag = 1, cvalue = (null)

% testopt -ab
aflag = 1, bflag = 1, cvalue = (null)

% testopt -c foo
aflag = 0, bflag = 0, cvalue = foo

% testopt -cfoo
aflag = 0, bflag = 0, cvalue = foo
  1. https://docs.python.org/2/library/argparse.html#option-value-syntax

For short options (options only one character long), the option and its value can be concatenated

Several short options can be joined together, using only a single - prefix, as long as only the last option (or none of them) requires a value

Copy link
Collaborator

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you still interested in doing more work on this @TheRoSS ?

I am now happy with supporting adjacent values. I have a few small changes I would like made, and want to do some testing. Checking whether you are still engaged before I go further.

No problem if you are no longer interested, I'll find somewhere to reference this work for future use by someone else.

Thank you for your contributions.

@TheRoSS
Copy link
Contributor Author

TheRoSS commented May 6, 2019

Good day. I am rather busy just now. But can participate in this issue in the end of May

Copy link
Collaborator

@shadowspawn shadowspawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wish I had noted the changes when I first reviewed, but only one that stood out when I looked again was to follow the existing whitespace format (odd though it is!).

@shadowspawn
Copy link
Collaborator

Merging into release/v3.0.0 branch

shadowspawn added a commit that referenced this pull request Jun 23, 2019
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Jun 23, 2019
@shadowspawn
Copy link
Collaborator

(I deleted some requested style changes that turned out to be stale, format on master had changed.)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jun 24, 2019

I made some minor changes, and already had one approval. Merged into v3 and will be included in that release. Closing to make it clear that should not be merged into master.

Thank you for your contributions.

@shadowspawn
Copy link
Collaborator

Update: I am working my way through the parsing process looking into another bug. I suspect this fix only works for action based commands.

@shadowspawn
Copy link
Collaborator

Available now as a prerelease. See #1001

@shadowspawn
Copy link
Collaborator

kevinoid added a commit to kevinoid/node-project-template that referenced this pull request Aug 9, 2019
In commander.js v3.0.0 (as a result of tj/commander.js#599) -wx is
interpreted as -w with (invalid) timeout "x" instead of -w -x (which
makes sense and is consistent with GNU getopt behavior).  Split the
options to avoid the problem.

Signed-off-by: Kevin Locke <[email protected]>
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Aug 12, 2019
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

Successfully merging this pull request may close these issues.

3 participants