Closed zachgersh closed 11 years ago
Thanks for opening this @zachgersh. @visionmedia you can find more context for this issue on a related Jekyll issue.
Hmm, so reading through the Jekyll issue it sounds like the best workaround is to explicitly define the shorthand switches in a non-conflicting way, e.g. -p
and -P
, rather than letting OptionParser guess.
I'm open to suggestions about what commander could do to make this better...
Is there a way to make it so that the short flags do not get automatically set via OptionParser unless they are listed explicitly?
On Jun 7, 2013, at 1:14 AM, Gabriel Gilder notifications@github.com wrote:
Hmm, so reading through the Jekyll issue it sounds like the best workaround is to explicitly define the shorthand switches in a non-conflicting way, e.g. -p and -P, rather than letting OptionParser guess.
I'm open to suggestions about what commander could do to make this better...
— Reply to this email directly or view it on GitHub.
I did some testing with OptionParser and I'm not seeing a way to disable the automatic creation of short flags.
A possible way to fix this issue would be to have commander parse command flags before parsing global flags. However, I'm not sure that that approach would be correct, and there's a strong possibility that it would break existing scripts.
I don't see anything in the Ruby documentation about OptionParser that shows it automatically generating a short flag anywhere. I definitely believe you tested it but what did you do to force it to create a short flag?
Here's a sample script that shows some of OptionParser's behavior.
-v
turns on --verbose
(automatically generated short flag).-Q
turns on --trace
(explicit short flag).-t
produces an AmbiguousOption exception (OptionParser can't decide between --test
and --trace
). And in fact, you'll see the same behavior with commander if you define two global options and use an implied short flag. For instance, define --best
and --bestest
as global options and try to call the script with -b
. This also produces OptionParser::AmbiguousOption
.#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.on("--verbose") do |v|
options[:verbose] = v
end
opts.on("--test") do |t|
options[:test] = t
end
opts.on("-Q", "--trace") do |t|
options[:trace] = t
end
end.parse!
p options
p ARGV
Hey All,
Hopefully you can throw a suggestion out as to how I would solve this problem.
Currently have a global option --plugins with no explicit -p switch (OptionParser implicitly creates the -p switch as suggested by the documentation).
Later on there is a command option off of something called :serve which takes a --port or -p (explicitly defined).
So, when writing something like this
server --plugins "/foo" -p 1111
plugins gets all screwy because it now thinks it is supposed to look in the 111 directory.
Is there a way to get around this?