implement posix_order flag
This commit is contained in:
parent
dd4148a3d6
commit
6ae8e62f7b
@ -12,7 +12,7 @@ module Yawpa
|
||||
class InvalidArgumentsException < Exception; end
|
||||
|
||||
module_function
|
||||
def parse(params, options)
|
||||
def parse(params, options, flags = {})
|
||||
options = _massage_options(options)
|
||||
opts = {}
|
||||
args = []
|
||||
@ -50,6 +50,9 @@ module Yawpa
|
||||
end
|
||||
short_idx += 1
|
||||
end
|
||||
elsif flags[:posix_order]
|
||||
args = params[i, params.length]
|
||||
break
|
||||
else
|
||||
args << params[i]
|
||||
end
|
||||
|
@ -201,5 +201,17 @@ describe Yawpa do
|
||||
opts[:option].should eq('NEW_VALUE')
|
||||
args.should be_empty
|
||||
end
|
||||
|
||||
it "ignores options after arguments in posix_order mode" do
|
||||
options = {
|
||||
one: {},
|
||||
two: {},
|
||||
}
|
||||
params = ['--one', 'arg', '--two']
|
||||
opts, args = Yawpa.parse(params, options, posix_order: true)
|
||||
opts[:one].should be_true
|
||||
opts[:two].should be_false
|
||||
args.should eq(['arg', '--two'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user