implement posix_order flag

This commit is contained in:
Josh Holtrop 2013-01-22 18:09:44 -05:00
parent dd4148a3d6
commit 6ae8e62f7b
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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