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}'")
|
||||
end
|
||||
end
|
||||
if opts[param_key].length == 1
|
||||
opts[param_key] = opts[param_key].first
|
||||
end
|
||||
end
|
||||
elsif param =~ /^-(.+)$/
|
||||
short_flags = $1
|
||||
@ -76,6 +73,14 @@ module Yawpa
|
||||
end
|
||||
i += 1
|
||||
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]
|
||||
end
|
||||
|
||||
|
@ -107,5 +107,15 @@ describe Yawpa do
|
||||
opts[:option].should be_true
|
||||
args.should eq(['qqq'])
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user