Support options with only a short flag#1256
Conversation
…n option constructor.
|
Side note: I hit a merge conflict when updating the branch which prompted me to look at how |
|
I created a I am thinking we might do a pre-release in June for v6, with short flags and variadic options. |
abetomo
left a comment
There was a problem hiding this comment.
Awesome, thanks for doing this.
| let longFlag; | ||
| // Use original very loose parsing to maintain backwards compatibility for now, | ||
| // which allowed for example unintended `-sw, --short-word` [sic]. | ||
| const flagParts = flags.split(/[ |,]+/); |
There was a problem hiding this comment.
this pattern seems buggy if the comment is still accurate, did you intend to say /( |,)+/ there? or just /[ ,]+/ to match space or comma, or really wanted to add a pipe | to the mix?
There was a problem hiding this comment.
The pipe is really in the mix. From the README:
Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').
The comment is about -sw which is neither a short flag nor a long name.
Pull Request
Problem
Users may wish to declare an option which has only a short flag and no long flag.
Defining just a short flag for an option appeared to almost work, but was not actually supported internally.
See: #1249
Solution
Extend option flag parsing to allow short, or long, or both. Extend the support to the custom option flags for
.helpOption()and.version()too.ChangeLog