Closed akostadinov closed 5 years ago
Unfortunately this is not possible without replacing the OptionParser library (which is part of Ruby's standard library). We already have an open issue for this: https://github.com/commander-rb/commander/issues/6
I don't think this is the same issue. #6 talks about --
followed by a letter, not single -
followed by a letter. Also there is some indication the problem is not present with global options.
I have tested that this is the case. From ~/.gem/ruby/gems/commander-4.4.0/lib/commander/runner.rb
when I remove '-h'
from line 55, then the -h
option is usable (at least as a global option, I have not tried a command option).
Sorry, the issue is a little buried in there - if you check out the StackOverflow link it describes the problem. Here's a short demo case though:
require 'optparse'
settings = {}
parser = OptionParser.new do |opts|
opts.on('--help') do
settings[:help] = true
end
end
parser.parse!(%w(-h))
p settings
# => {:help=>true}
Basically OptionParser always sets up the short version of an option, whether you specify it or not.
I tested and it does look like removing the -h
allows the use of a -h
global option — it would also work to change the order in which global options are added, I believe, because the last one to use a flag wins.
However! I don't see a way to make it work as a command option. I'm not sure if that's an issue for your use case or not.
My use case is to use as a global option. I guess there might be other use cases where people want to use as a command option but not me atm :)
I didn't test but I wonder what happens if we register another short option (possibly some weird unicode character) for the short opt. Would that make opt-parser skip registering -h
. I have to try it out.
Closing this issue since it hasn't been updated in a long time — please feel free to reopen or submit a PR if this is still relevant. Thanks!
Hi, sometimes it's preferable to disable
-h
option and have only--help
. This for example when hostname is to be specified. Please make-h
option configurable.--help
is fine, there can be no confusion.