diff --git a/lib/yawpa.rb b/lib/yawpa.rb index c66c5d7..a1572c1 100644 --- a/lib/yawpa.rb +++ b/lib/yawpa.rb @@ -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 diff --git a/spec/yawpa_spec.rb b/spec/yawpa_spec.rb index a4385cc..233c25b 100644 --- a/spec/yawpa_spec.rb +++ b/spec/yawpa_spec.rb @@ -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