-
Notifications
You must be signed in to change notification settings - Fork 74
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
Option argument parsed as a global option #80
Comments
Hmm, I'm not sure this is a bug so much as undefined behavior. From the shell's perspective, the invocation you mention is no different from the following:
In other words, the quotes don't matter because they're interpreted away by the shell. That might clarify why in this situation, commander sees a global option. I'm not totally sure what the correct behavior is here, but it is interesting that |
I understand that the quotes are removed by the shell, but I would argue that the parser should understand that |
Looks like the problem is in the parsing of global options. In particular, the parse, rescue, remove and retry portion: commander/lib/commander/runner.rb Lines 380 to 386 in 0abbac4
In normal usage, it'll raise on the command specific options, which will then be removed from the array of options before retrying the parse. In the scenario detailed in this issue: |
Exactly, global options are parsed in a first pass before parsing command options. The |
I'm using Commander 4.4.7. I am noticing that if I have an option that takes an argument, and the argument starts with a global option, the argument is parsed as a global option.
When I run the program, it interprets
-vers=3.0
as the global option-v
:$ ruby test.rb --options "-vers=3.0" Name 0.1
If I use
=
to separate--options
from its argument, it works as expected:$ ruby test.rb --options="-vers=3.0" Parsed mount options: -vers=3.0 Success
So, we have a workaround, but I still argue that it's a bug. First, it's very common to omit the
=
.Second, it works in either case using
optparse
directly. Here is an example:Observe that it works as expected in either case:
The text was updated successfully, but these errors were encountered: