return option value for short option also
This commit is contained in:
parent
cf049aed2f
commit
90d2a938d5
11
lib/yawpa.rb
11
lib/yawpa.rb
@ -39,9 +39,6 @@ module Yawpa
|
|||||||
raise InvalidArgumentsException.new("Not enough arguments supplied for option '#{param_key}'")
|
raise InvalidArgumentsException.new("Not enough arguments supplied for option '#{param_key}'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if opts[param_key].length == 1
|
|
||||||
opts[param_key] = opts[param_key].first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elsif param =~ /^-(.+)$/
|
elsif param =~ /^-(.+)$/
|
||||||
short_flags = $1
|
short_flags = $1
|
||||||
@ -76,6 +73,14 @@ module Yawpa
|
|||||||
end
|
end
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Condense 1-element arrays of option values to just the element itself
|
||||||
|
opts.each_key do |k|
|
||||||
|
if opts[k].class == Array and opts[k].length == 1
|
||||||
|
opts[k] = opts[k].first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return [opts, args]
|
return [opts, args]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,5 +107,15 @@ describe Yawpa do
|
|||||||
opts[:option].should be_true
|
opts[:option].should be_true
|
||||||
args.should eq(['qqq'])
|
args.should eq(['qqq'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns option argument at next position for a short option" do
|
||||||
|
options = {
|
||||||
|
option: {nargs: 1, short: 'o'},
|
||||||
|
}
|
||||||
|
params = ['-o', 'val', 'rrr']
|
||||||
|
opts, args = Yawpa.parse(params, options)
|
||||||
|
opts[:option].should eq('val')
|
||||||
|
args.should eq(['rrr'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user