diff --git a/lib/micro-optparse/parser.rb b/lib/micro-optparse/parser.rb index c722f84..ae68cbf 100644 --- a/lib/micro-optparse/parser.rb +++ b/lib/micro-optparse/parser.rb @@ -43,12 +43,13 @@ def process!(arguments = ARGV) @result = @default_values.clone # reset or new @optionparser ||= OptionParser.new do |p| # prepare only once @options.each do |o| - @used_short << short = o[:settings][:short] || short_from(o[:name]) + @used_short << short = o[:settings][:no_short] ? nil : o[:settings][:short] || short_from(o[:name]) @result[o[:name]] = o[:settings][:default] || false unless o[:settings][:optional] # set default name = o[:name].to_s.gsub("_", "-") klass = o[:settings][:default].class == Fixnum ? Integer : o[:settings][:default].class - args = [] << "-" + short << o[:description] + args = [o[:description]] + args << "-" + short if short if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch args << "--[no-]" + name else # argument with parameter, add class for typecheck diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 1734ae0..4d17da2 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -265,5 +265,12 @@ result.should include("-b, --bac") result.should include("-c, --cba") end + + it "should be possible to prevent creation of short arguments" do + result = `ruby spec/programs/noshort.rb --help` + result.should_not include("-f, --foo") + result.should include("--foo") + result.should include("-b, --bar") + end end end \ No newline at end of file diff --git a/spec/programs/noshort.rb b/spec/programs/noshort.rb new file mode 100644 index 0000000..df997ef --- /dev/null +++ b/spec/programs/noshort.rb @@ -0,0 +1,11 @@ +require "rubygems" +require "micro-optparse" + +options = Parser.new do |p| + p.option :foo, "Option 1", :default => "String", :no_short => true + p.option :bar, "Option 2", :default => "String" +end.process! + +options.each_pair do |key, value| + puts ":#{key} => #{value}" +end \ No newline at end of file