[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Daniel Pittman
daniel at puppetlabs.com
Tue May 10 08:10:49 UTC 2011
The following commit has been merged in the experimental branch:
commit 8b37d7038c89bd830b076e838686419ff0068b56
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Fri Apr 1 15:16:55 2011 -0700
(#6749) Polish the CLI option pre-parse implementation
This improves handling of the pre-parse of the command line to be
non-destructive, which cuts down the volume of garbage generated in the
process.
It also improves testing to verify that we get the darn thing right...
Reviewed-By: Pieter van de Bruggen <pieter at puppetlabs.com>
diff --git a/lib/puppet/application/string_base.rb b/lib/puppet/application/string_base.rb
index 09e42a5..6032e32 100644
--- a/lib/puppet/application/string_base.rb
+++ b/lib/puppet/application/string_base.rb
@@ -64,9 +64,9 @@ class Puppet::Application::StringBase < Puppet::Application
# arguments based on introspecting the action and all, and find the first
# non-option word to use as the action.
action = nil
- cli = command_line.args.dup # we destroy this copy, but...
- while @action.nil? and not cli.empty? do
- item = cli.shift
+ index = -1
+ while (index += 1) < command_line.args.length do
+ item = command_line.args[index]
if item =~ /^-/ then
option = @string.options.find { |a| item =~ /^-+#{a}\b/ }
if option then
@@ -74,7 +74,7 @@ class Puppet::Application::StringBase < Puppet::Application
# We don't validate if the argument is optional or mandatory,
# because it doesn't matter here. We just assume that errors will
# be caught later. --daniel 2011-03-30
- cli.shift unless cli.first =~ /^-/
+ index += 1 unless command_line.args[index + 1] =~ /^-/
end
else
raise ArgumentError, "Unknown option #{item.sub(/=.*$/, '').inspect}"
@@ -85,6 +85,7 @@ class Puppet::Application::StringBase < Puppet::Application
raise ArgumentError, "#{@string} does not have an #{item.inspect} action!"
end
@action = action
+ command_line.args.delete_at(index)
end
end
@@ -105,8 +106,8 @@ class Puppet::Application::StringBase < Puppet::Application
# 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 = Array(command_line.args) << options
- validate
+ @arguments = command_line.args
+ @arguments << options
end
@@ -117,9 +118,4 @@ class Puppet::Application::StringBase < Puppet::Application
end
exit(exit_code)
end
- def validate
- unless @action
- raise "You must specify #{string.actions.join(", ")} as a verb"
- end
- end
end
diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb
index 20185b5..62869fe 100755
--- a/spec/unit/application/string_base_spec.rb
+++ b/spec/unit/application/string_base_spec.rb
@@ -16,6 +16,11 @@ describe Puppet::Application::StringBase do
File.open(File.join(@dir, 'puppet', 'string', 'basetest.rb'), 'w') do |f|
f.puts "Puppet::String.define(:basetest, '0.0.1')"
end
+
+ Puppet::String[:basetest, '0.0.1'].action :foo do
+ option "--foo"
+ invoke { |*args| args.length }
+ end
end
after :all do
@@ -28,7 +33,6 @@ describe Puppet::Application::StringBase do
app.stubs(:exit)
app.stubs(:puts)
app.command_line.stubs(:subcommand_name).returns 'subcommand'
- app.command_line.stubs(:args).returns []
Puppet::Util::Log.stubs(:newdestination)
app
end
@@ -39,13 +43,6 @@ describe Puppet::Application::StringBase do
end
describe "parsing the command line" do
- before :all do
- Puppet::String[:basetest, '0.0.1'].action :foo do
- option "--foo"
- invoke { |options| options }
- end
- end
-
context "with just an action" do
before :all do
app.command_line.stubs(:args).returns %w{foo}
@@ -99,52 +96,22 @@ describe Puppet::Application::StringBase do
end
end
- describe "when calling main" do
- # before do
- # @app.verb = :find
- # @app.arguments = ["myname", "myarg"]
- # @app.string.stubs(:find)
- # end
-
- it "should send the specified verb and name to the string" do
- pending "REVISIT: disabled, needs to be rewritten for the new introspection model. --daniel 2011-03-31"
- @app.string.expects(:find).with("myname", "myarg")
- app.main
- end
-
- it "should use its render method to render any result"
-
- it "should exit with the current exit code"
- end
-
- describe "during setup" do
+ describe "#main" do
before do
- app.command_line.stubs(:args).returns(["find", "myname", "myarg"])
- app.stubs(:validate)
- end
-
- it "should set the verb from the command line arguments" do
- pending "REVISIT: needs updating too..."
-
- @app.setup
- @app.verb.should == "find"
+ app.string = Puppet::String[:basetest, '0.0.1']
+ app.action = app.string.get_action(:foo)
+ app.format = :pson
+ app.arguments = ["myname", "myarg"]
end
- it "should make sure arguments are an array" do
- pending "REVISIT: needs updating too..."
-
- @app.command_line.stubs(:args).returns(["find", "myname", "myarg"])
- @app.setup
- @app.arguments.should == ["myname", "myarg", {}]
+ it "should send the specified verb and name to the string" do
+ app.string.expects(:foo).with(*app.arguments)
+ app.main
end
- it "should pass options as the last argument" do
- pending "REVISIT: needs updating too..."
-
- @app.command_line.stubs(:args).returns(["find", "myname", "myarg", "--foo"])
- @app.parse_options
- @app.setup
- @app.arguments.should == ["myname", "myarg", { :foo => true }]
+ it "should use its render method to render any result" do
+ app.expects(:render).with(app.arguments.length + 1)
+ app.main
end
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list