Closed ondra-m closed 6 years ago
Can you provide an example of why you would need to access active_command
? I'm not sure I see the use case.
Cmd
test --files file1.txt --files file2.txt
Commander
command :test do |c|
c.option('--files FILES', Array)
end
Result of option.files will be file2.txt but I need also file1.txt. So I add custom Proc with
proxy_options = Commander::Runner.instance.active_command.proxy_options
saved = proxy_options.find{|switch, _| switch == :files }
if saved
saved[1].concat(values)
else
proxy_options << [:files, values]
end
First I modify command.rb but I do not think that's a desirable feature for more people.
What do you think?
I see, so the actual problem here is that repeated options result in the last one "winning" rather than the repeated option being treated as an array. It seems to be that this should be fixed in the option parser rather than hacking around it with a custom proc. Since this could be a breaking change I'd suggest making it an optional switch on the commander program so you can opt-in to this parsing style.
Closing since this has not been updated in a while. Please feel free to reopen if this is still an issue for you.
I need parse values from args like:
It will be much nicer if I use just
active_command
.