return boolean options set
This commit is contained in:
parent
56e644e16e
commit
056257b8f5
26
lib/yawpa.rb
26
lib/yawpa.rb
@ -17,11 +17,29 @@ module Yawpa
|
||||
i = 0
|
||||
while i < params.length
|
||||
param = params[i]
|
||||
if param[0] != '-'
|
||||
args << params[i]
|
||||
if param =~ /^(-+)(.+)$/
|
||||
case $1.length
|
||||
when 2
|
||||
param_key = if options[$2]
|
||||
$2
|
||||
elsif options[$2.to_sym]
|
||||
$2.to_sym
|
||||
else
|
||||
opt_config = options[param] || options[param.to_sym]
|
||||
raise UnknownOptionException.new("Unknown option '#{param}'") if opt_config.nil?
|
||||
nil
|
||||
end
|
||||
if param_key.nil?
|
||||
raise UnknownOptionException.new("Unknown option '#{param}'")
|
||||
end
|
||||
opt_config = options[param_key]
|
||||
nargs = opt_config[:nargs] || 0
|
||||
if nargs == 0
|
||||
opts[param_key] = true
|
||||
elsif nargs.class == FixNum
|
||||
elsif nargs.class == Range
|
||||
end
|
||||
end
|
||||
else
|
||||
args << params[i]
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
@ -15,5 +15,19 @@ describe Yawpa do
|
||||
params = ['one', '--option', 'two']
|
||||
expect { Yawpa.parse(params, options) }.to raise_error
|
||||
end
|
||||
|
||||
it "returns boolean options which are set" do
|
||||
options = {
|
||||
one: {},
|
||||
two: {},
|
||||
three: {},
|
||||
}
|
||||
params = ['--one', 'arg', '--two', 'arg2']
|
||||
opts, args = Yawpa.parse(params, options)
|
||||
opts.include?(:one).should be_true
|
||||
opts.include?(:two).should be_true
|
||||
opts.include?(:three).should be_false
|
||||
args.should eq(['arg', 'arg2'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user