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