[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:33:21 UTC 2010


The following commit has been merged in the upstream branch:
commit 5683fd983b9a165ffbb8f08e67cfe903ec0e41b7
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Fri Apr 30 15:47:15 2010 -0700

    Feature #2276 Single Executable: Pass a commandline object to the application
    
    Refactor so that the command line options only get parsed once
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 49a146f..f72714b 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -229,7 +229,7 @@ class Puppet::Application
         end
     end
 
-    attr_reader :options, :opt_parser
+    attr_reader :options, :opt_parser, :command_line
 
     # Every app responds to --version
     option("--version", "-V") do |arg|
@@ -250,7 +250,8 @@ class Puppet::Application
     def preinit
     end
 
-    def initialize
+    def initialize(command_line = nil)
+        @command_line = command_line || Puppet::Util::CommandLine.new
         @opt_parser = self.class.new_option_parser( self )
 
         @options = {}
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 88385f0..fde0c9b 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -66,10 +66,10 @@ class Puppet::Application::Apply < Puppet::Application
 
     def parseonly
         # Set our code or file to use.
-        if options[:code] or Puppet::Util::CommandLine.args.length == 0
+        if options[:code] or command_line.args.length == 0
             Puppet[:code] = options[:code] || STDIN.read
         else
-            Puppet[:manifest] = Puppet::Util::CommandLine.args.shift
+            Puppet[:manifest] = command_line.args.shift
         end
         begin
             Puppet::Resource::TypeCollection.new(Puppet[:environment]).perform_initial_import
@@ -82,10 +82,10 @@ class Puppet::Application::Apply < Puppet::Application
 
     def main
         # Set our code or file to use.
-        if options[:code] or Puppet::Util::CommandLine.args.length == 0
+        if options[:code] or command_line.args.length == 0
             Puppet[:code] = options[:code] || STDIN.read
         else
-            Puppet[:manifest] = Puppet::Util::CommandLine.args.shift
+            Puppet[:manifest] = command_line.args.shift
         end
 
         # Collect our facts.
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index 92da03c..a4ee5fe 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -44,7 +44,7 @@ class Puppet::Application::Cert < Puppet::Application
         if @all
             hosts = :all
         else
-            hosts = Puppet::Util::CommandLine.args.collect { |h| puts h; h.downcase }
+            hosts = command_line.args.collect { |h| puts h; h.downcase }
         end
         begin
             @ca.apply(:revoke, :to => hosts) if @mode == :destroy
diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb
index 45f017a..ae33fb9 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -203,7 +203,7 @@ class Puppet::Application::Describe < Puppet::Application
     end
 
     def setup
-        options[:types] = Puppet::Util::CommandLine.args.dup
+        options[:types] = command_line.args.dup
         unless options[:list] || options[:types].size > 0
             handle_help(nil)
         end
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb
index 295cd67..74cde98 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -70,7 +70,7 @@ class Puppet::Application::Doc < Puppet::Application
             files += env.modulepath
             files << File.dirname(env[:manifest])
         end
-        files += Puppet::Util::CommandLine.args
+        files += command_line.args
         Puppet.info "scanning: %s" % files.inspect
         Puppet.settings.setdefaults("puppetdoc",
             "document_all" => [false, "Document all resources"]
@@ -167,7 +167,7 @@ class Puppet::Application::Doc < Puppet::Application
 
     def setup
         # sole manifest documentation
-        if Puppet::Util::CommandLine.args.size > 0
+        if command_line.args.size > 0
             options[:mode] = :rdoc
             @manifest = true
         end
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index ddc46e3..8e930f5 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -15,7 +15,7 @@ class Puppet::Application::Filebucket < Puppet::Application
     attr :args
 
     def run_command
-        @args = Puppet::Util::CommandLine.args
+        @args = command_line.args
         command = args.shift
         return send(command) if %w[get backup restore].include? command
         help
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb
index 52320e7..6a8c4e4 100644
--- a/lib/puppet/application/resource.rb
+++ b/lib/puppet/application/resource.rb
@@ -38,7 +38,7 @@ class Puppet::Application::Resource < Puppet::Application
     end
 
     def main
-        args = Puppet::Util::CommandLine.args
+        args = command_line.args
         type = args.shift or raise "You must specify the type to display"
         typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}"
         name = args.shift
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 6e67fd7..e665698 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -75,7 +75,7 @@ module Puppet
                     puts self.class.usage_message
                 elsif self.class.available_subcommands.include?(subcommand_name) #subcommand
                     require File.join(self.class.appdir, subcommand_name)
-                    Puppet::Application[subcommand_name].run
+                    Puppet::Application.find(subcommand_name).new(self).run
                 else
                     abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
                 end
diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply.rb
index 10202e1..a1a7e7b 100755
--- a/spec/unit/application/apply.rb
+++ b/spec/unit/application/apply.rb
@@ -204,7 +204,7 @@ describe Puppet::Application::Apply do
             end
 
             it "should set the code to run from STDIN if no arguments" do
-                Puppet::Util::CommandLine.stubs(:args).returns([])
+                @apply.command_line.stubs(:args).returns([])
                 STDIN.stubs(:read).returns("code to run")
 
                 Puppet.expects(:[]=).with(:code,"code to run")
@@ -213,7 +213,7 @@ describe Puppet::Application::Apply do
             end
 
             it "should set the manifest if some files are passed on command line" do
-                Puppet::Util::CommandLine.stubs(:args).returns(['site.pp'])
+                @apply.command_line.stubs(:args).returns(['site.pp'])
 
                 Puppet.expects(:[]=).with(:manifest,"site.pp")
 
diff --git a/spec/unit/application/cert.rb b/spec/unit/application/cert.rb
index 3fb2f1e..5970355 100644
--- a/spec/unit/application/cert.rb
+++ b/spec/unit/application/cert.rb
@@ -110,7 +110,7 @@ describe Puppet::Application::Cert do
             @cert_app.all = false
             @ca = stub_everything 'ca'
             @cert_app.ca = @ca
-            Puppet::Util::CommandLine.stubs(:args).returns([])
+            @cert_app.command_line.stubs(:args).returns([])
         end
 
         it "should delegate to the CertificateAuthority" do
@@ -128,7 +128,7 @@ describe Puppet::Application::Cert do
         end
 
         it "should delegate to ca.apply with the hosts given on command line" do
-            Puppet::Util::CommandLine.stubs(:args).returns(["host"])
+            @cert_app.command_line.stubs(:args).returns(["host"])
 
             @ca.expects(:apply).with { |mode,to| to[:to] == ["host"]}
 
@@ -136,7 +136,7 @@ describe Puppet::Application::Cert do
         end
 
         it "should send the currently set digest" do
-            Puppet::Util::CommandLine.stubs(:args).returns(["host"])
+            @cert_app.command_line.stubs(:args).returns(["host"])
             @cert_app.handle_digest(:digest)
 
             @ca.expects(:apply).with { |mode,to| to[:digest] == :digest}
@@ -146,7 +146,7 @@ describe Puppet::Application::Cert do
 
         it "should delegate to ca.apply with current set mode" do
             @cert_app.mode = "currentmode"
-            Puppet::Util::CommandLine.stubs(:args).returns(["host"])
+            @cert_app.command_line.stubs(:args).returns(["host"])
 
             @ca.expects(:apply).with { |mode,to| mode == "currentmode" }
 
@@ -155,7 +155,7 @@ describe Puppet::Application::Cert do
 
         it "should revoke cert if mode is clean" do
             @cert_app.mode = :destroy
-            Puppet::Util::CommandLine.stubs(:args).returns(["host"])
+            @cert_app.command_line.stubs(:args).returns(["host"])
 
             @ca.expects(:apply).with { |mode,to| mode == :revoke }
             @ca.expects(:apply).with { |mode,to| mode == :destroy }
diff --git a/spec/unit/application/doc.rb b/spec/unit/application/doc.rb
index 3bda25f..c118492 100755
--- a/spec/unit/application/doc.rb
+++ b/spec/unit/application/doc.rb
@@ -128,11 +128,11 @@ describe Puppet::Application::Doc do
 
         before :each do
             Puppet::Log.stubs(:newdestination)
-            Puppet::Util::CommandLine.stubs(:args).returns([])
+            @doc.command_line.stubs(:args).returns([])
         end
 
         it "should default to rdoc mode if there are command line arguments" do
-            Puppet::Util::CommandLine.stubs(:args).returns(["1"])
+            @doc.command_line.stubs(:args).returns(["1"])
             @doc.stubs(:setup_rdoc)
 
             @doc.options.expects(:[]=).with(:mode,:rdoc)
@@ -304,7 +304,7 @@ describe Puppet::Application::Doc do
                 @doc.stubs(:exit)
                 File.stubs(:expand_path).with('modules').returns('modules')
                 File.stubs(:expand_path).with('manifests').returns('manifests')
-                Puppet::Util::CommandLine.stubs(:args).returns([])
+                @doc.command_line.stubs(:args).returns([])
             end
 
             it "should set document_all on --all" do
diff --git a/spec/unit/application/filebucket.rb b/spec/unit/application/filebucket.rb
index 68af45c..58c7f7c 100644
--- a/spec/unit/application/filebucket.rb
+++ b/spec/unit/application/filebucket.rb
@@ -152,7 +152,7 @@ describe Puppet::Application::Filebucket do
         end
 
         it "should use the first non-option parameter as the dispatch" do
-            Puppet::Util::CommandLine.stubs(:args).returns([:get])
+            @filebucket.command_line.stubs(:args).returns(['get'])
 
             @filebucket.expects(:get)
 
diff --git a/spec/unit/application/resource.rb b/spec/unit/application/resource.rb
index 2e90cc2..3487b2c 100755
--- a/spec/unit/application/resource.rb
+++ b/spec/unit/application/resource.rb
@@ -135,12 +135,12 @@ describe Puppet::Application::Resource do
 
         before :each do
             @type = stub_everything 'type', :properties => []
-            Puppet::Util::CommandLine.stubs(:args).returns(['type'])
+            @resource.command_line.stubs(:args).returns(['type'])
             Puppet::Type.stubs(:type).returns(@type)
         end
 
         it "should raise an error if no type is given" do
-            Puppet::Util::CommandLine.stubs(:args).returns([])
+            @resource.command_line.stubs(:args).returns([])
             lambda { @resource.main }.should raise_error
         end
 
@@ -168,19 +168,20 @@ describe Puppet::Application::Resource do
             end
 
             it "should search for resources" do
+                @resource.command_line.stubs(:args).returns(['type'])
                 Puppet::Resource.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([])
                 @resource.main
             end
 
             it "should describe the given resource" do
-                Puppet::Util::CommandLine.stubs(:args).returns(['type', 'name'])
+                @resource.command_line.stubs(:args).returns(['type', 'name'])
                 x = stub_everything 'resource'
                 Puppet::Resource.expects(:find).with('https://host:8139/production/resources/type/name').returns(x)
                 @resource.main
             end
 
             it "should add given parameters to the object" do
-                Puppet::Util::CommandLine.stubs(:args).returns(['type','name','param=temp'])
+                @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
 
                 res = stub "resource"
                 res.expects(:save).with('https://host:8139/production/resources/type/name').returns(res)
@@ -209,14 +210,14 @@ describe Puppet::Application::Resource do
             end
 
             it "should describe the given resource" do
-                Puppet::Util::CommandLine.stubs(:args).returns(['type','name'])
+                @resource.command_line.stubs(:args).returns(['type','name'])
                 x = stub_everything 'resource'
                 Puppet::Resource.expects(:find).with('type/name').returns(x)
                 @resource.main
             end
 
             it "should add given parameters to the object" do
-                Puppet::Util::CommandLine.stubs(:args).returns(['type','name','param=temp'])
+                @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
 
                 res = stub "resource"
                 res.expects(:save).with('type/name').returns(res)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list