We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 46639a2 commit 66628edCopy full SHA for 66628ed
lib/optimist.rb
@@ -703,12 +703,15 @@ def initialize
703
704
def add(values)
705
values = [values] unless values.is_a?(Array) # box the value
706
- values.compact.each do |val|
707
- if val == :none
+ values = values.compact
+ if values.include?(:none)
708
+ if values.size == 1
709
@auto = false
- raise "Cannot set short to :none if short-chars have been defined '#{@chars}'" unless chars.empty?
710
- next
+ return
711
end
712
+ raise ArgumentError, "Cannot use :none with any other values in short option: #{values.inspect}"
713
+ end
714
+ values.each do |val|
715
strval = val.to_s
716
sopt = case strval
717
when /^-(.)$/ then $1
test/optimist/alt_names_test.rb
@@ -18,7 +18,7 @@ def get_help_string
18
19
20
def test_altshort
21
- @p.opt :catarg, "desc", :short => ["c", "-C"]
+ @p.opt :catarg, "desc", :short => ["c", "-C"]
22
opts = @p.parse %w(-c)
23
assert_equal true, opts[:catarg]
24
opts = @p.parse %w(-C)
@@ -27,6 +27,18 @@ def test_altshort
27
assert_raises(CommandlineError) { @p.parse %w(-cC) }
28
29
30
+ def test_altshort_invalid_none
31
+ assert_raises(ArgumentError) {
32
+ @p.opt :something, "some opt", :short => [:s, :none]
33
+ }
34
35
+ @p.opt :something, "some opt", :short => [:none, :s]
36
37
38
+ @p.opt :zumthing, "some opt", :short => [:none, :none]
39
40
41
+
42
def test_altshort_with_multi
43
@p.opt :flag, "desc", :short => ["-c", "C", :x], :multi => true
44
@p.opt :num, "desc", :short => ["-n", "N"], :multi => true, type: Integer
0 commit comments