I have such a simple code in Ruby (test.rb):
#! /usr/bin/env ruby
require 'optparse'
OptionParser.new do |option|
option.on("--sort", "Sort data") do
puts "--sort passed"
end
end.parse!
then I run it: ./test.rb -s and got:
--sort passed
Have I missed something?
I want the only --sort (long) option works, not the short one.
How do I get it?
From the documentation, it appears that this isn't possible.
The
#onmethod uses the syntax of#make_switch, which is described here. The whole documentation makes no mention of being able to turn long or short variables on or off.However, is this really a problem? The convention is that options are accessible via long and short names, and forcing a change in that behaviour might frustrate your users.
If you really don't want to allow short names, the best option would be to look at some other libraries (e.g. highline, slop, trollop) or roll your own.