Option values starting with dashes don't work
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 259
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
I have a program taking options with values. Sometimes those values start with a dash. If that happens, optimist tries to parse those as actual options instead of values, leading either to wrong options being activated or interested error messages.
The expected behavior is that the value after an option requiring a value is always assigned to the that option.
Here's an example:
#!/usr/bin/env ruby
require "optimist"
require "pp"
o = Optimist::options do
opt :action, "an action", :type => :string
opt :ignore, "ignore stuff"
end
pp o
Here are a couple of examples:
[0 mosu@sweet-chili ~/test] ./ruby1.rb --action jump
{:action=>"jump", :ignore=>false, :help=>false, :action_given=>true}
[0 mosu@sweet-chili ~/test] ./ruby1.rb --action --jump
Error: unknown argument '--jump'.
Try --help for help.
[255 mosu@sweet-chili ~/test] ./ruby1.rb --action -a --ignore
Error: option '-a' specified multiple times.
Try --help for help.
[255 mosu@sweet-chili ~/test] ./ruby1.rb --action --ignore
Error: option '--action' needs a parameter.
Try --help for help.
The first case is obviously OK.
The other cases are all really bad. In each case the value after --action (--jump in case 2, -a in case 3 and --ignore in case 4) should be assigned to the action option as the spec says that it must have a value.
Background: this is from a script doing DNS validation for the ACME protocol (Let's Encrypt certificates). It has to deal with the auth tokens that the Let's Encrypt servers generate. Today such an auth token started with a dash, and my program broke. I do not have any control over the auth tokens, which characters they consist of etc. A workaround such as "use different argument formats, then" doesn't help if I don't have control over the data my callers must use.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Optimist::options entry point and trace how an option requiring a value consumes the next argument. Add regression coverage for values beginning with '-' using the --action examples in the issue. Done means --jump, -a, and --ignore are assigned to action rather than parsed as options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100