-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Possible to parse multiple long options? #13
Comments
Hmmm, it seems that it works as long as I have some short options also -- e.g.: while getopts_long 'r:t: remoteHost: toDir:' OPTKEY; do I guess the bug is that multiple long options don't work if you define no short options. |
This works: |
starting the optspec string with a space also works if you change the getopts call on line 20 to |
Thanks @AndrewDDavis for suggesting [the fix](#13 (comment))!
Using getopts_long without short options is an edge case I hadn’t really considered before. Most of my use includes at least "-h" (help), so I rarely run into this. That said, short options aren’t required, so this should be possible. In “silent mode” (when OPTSPEC starts with We could introduce a special character for verbose mode as a counterpart to :, but personally, I’d be against it. Every new character exception we add diverges getopts_long further from the built-in getopts, increases cognitive load, and adds (minimal) risk of future collisions. “Space” is the most logical choice — it’s standard ASCII, unlikely to conflict with options, and even if built-in getopts adopts it later, it would (hopefully) be to support the same feature. 🤞 So, for verbose mode without short options, just start OPTSPEC with a space. PS: Thanks @AndrewDDavis for the idea and for catching that bug! I’ve added tests to prevent it happening in the future, and it’ll be included in getopts_long v1.2.3 once #21 is merged. |
I have this code:
and I'm invoking my script with arguments:
--remoteHost=somehost --toDir=/tmp/foo
The result is:
The result is the same if I use as arguments:
--remote-host somehost --to-dir /tmp/foo
How do I specify that both
--remoteHost
and--toDir
are valid long options?The text was updated successfully, but these errors were encountered: