Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8d0ba8

Browse files
committed
Fix completion of key-value pairs array
Enum array may be the list of pairs of key and value. Check if only key is completable, not pair. Fix #93 Fix #94
1 parent f4d64b0 commit a8d0ba8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/optparse.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ def make_switch(opts, block = nil)
15021502
block = notwice(o, block, 'block')
15031503
when Array, Hash
15041504
if Array === o
1505-
o, v = o.partition {|v| Completion.completable?(v)}
1505+
o, v = o.partition {|v,| Completion.completable?(v)}
15061506
values = notwice(v, values, 'values') unless v.empty?
15071507
next if o.empty?
15081508
end

test/optparse/test_placearg.rb

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def setup
88
@opt.def_option("--option [VAL]") {|x| @flag = x}
99
@opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x}
1010
@opt.def_option("--enum [VAL]", [:Alpha, :Bravo, :Charlie]) {|x| @enum = x}
11+
@opt.def_option("--enumval [VAL]", [[:Alpha, 1], [:Bravo, 2], [:Charlie, 3]]) {|x| @enum = x}
1112
@opt.def_option("--integer [VAL]", Integer, [1, 2, 3]) {|x| @integer = x}
1213
@opt.def_option("--range [VAL]", Integer, 1..3) {|x| @range = x}
1314
@topt = nil
@@ -102,6 +103,11 @@ def test_enum
102103
assert_equal(:Alpha, @enum)
103104
end
104105

106+
def test_enum_pair
107+
assert_equal([], no_error {@opt.parse!(%w"--enumval=A")})
108+
assert_equal(1, @enum)
109+
end
110+
105111
def test_enum_conversion
106112
assert_equal([], no_error {@opt.parse!(%w"--integer=1")})
107113
assert_equal(1, @integer)

0 commit comments

Comments
 (0)