diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 14:46:21 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 14:47:06 -0700 |
commit | 0950d09d12ec06e97915d264e8724e736c84e36a (patch) | |
tree | ded36b42808ab9a214830af0d10a2b365b8f4734 | |
parent | a2537dc52724386b8f05240e9b18bff437141e79 (diff) | |
download | puppet-0950d09d12ec06e97915d264e8724e736c84e36a.tar.gz puppet-0950d09d12ec06e97915d264e8724e736c84e36a.tar.xz puppet-0950d09d12ec06e97915d264e8724e736c84e36a.zip |
(#6949) Fix passing positional arguments to actions.
We had a logic failure that didn't pass positional arguments at all, but which
our testing didn't verify. This entirely broke things. Now fixed, and a test
added to ensure we don't bug out further...
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
-rw-r--r-- | lib/puppet/application/string_base.rb | 14 | ||||
-rwxr-xr-x | spec/unit/application/string_base_spec.rb | 6 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/puppet/application/string_base.rb b/lib/puppet/application/string_base.rb index 06e5789be..76b0a46fd 100644 --- a/lib/puppet/application/string_base.rb +++ b/lib/puppet/application/string_base.rb @@ -104,16 +104,18 @@ class Puppet::Application::StringBase < Puppet::Application def setup Puppet::Util::Log.newdestination :console - # We copy all of the app options to the end of the call; This allows each - # action to read in the options. This replaces the older model where we - # would invoke the action with options set as global state in the - # interface object. --daniel 2011-03-28 - # + @arguments = command_line.args + # Note: because of our definition of where the action is set, we end up # with it *always* being the first word of the remaining set of command # line arguments. So, strip that off when we construct the arguments to # pass down to the string action. --daniel 2011-04-04 - @arguments = command_line.args[1, -1] || [] + @arguments.delete_at(0) + + # We copy all of the app options to the end of the call; This allows each + # action to read in the options. This replaces the older model where we + # would invoke the action with options set as global state in the + # interface object. --daniel 2011-03-28 @arguments << options end diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb index 753d911d1..cd24b6c49 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/string_base_spec.rb @@ -127,6 +127,12 @@ describe Puppet::Application::StringBase do app.preinit and app.parse_options and app.setup app.arguments.should == [{ :mandatory => "--bar" }] end + + it "should pass positional arguments" do + app.command_line.stubs(:args).returns %w{--mandatory --bar foo bar baz quux} + app.preinit and app.parse_options and app.setup + app.arguments.should == ['bar', 'baz', 'quux', { :mandatory => "--bar" }] + end end describe "#main" do |