[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:20 UTC 2010


The following commit has been merged in the upstream branch:
commit 7656ba73ddfd883b36a01c81147ae69e80773bce
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Thu Apr 22 12:04:10 2010 -0700

    feature #2276 Single Executable: CommandLine can be instantiated
    
    refactor CommandLine to be an object
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/bin/puppet b/bin/puppet
index a326ba1..9b7c7d6 100755
--- a/bin/puppet
+++ b/bin/puppet
@@ -69,21 +69,5 @@
 
 #Puppet::Application[:apply].run # this is so the RDoc::usage hack can find this file
 
-appdir = File.join('puppet', 'application')
-absolute_appdir = $:.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) }
-builtins = Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
-
-usage = "Usage: puppet command <space separated arguments>"
-available = "Available commands are: #{builtins.sort.join(', ')}"
-
 require 'puppet/util/command_line'
-subcommand_name = Puppet::Util::CommandLine.subcommand_name
-
-if subcommand_name.nil?
-    puts usage, available
-elsif builtins.include?(subcommand_name) #subcommand
-    require File.join(appdir, subcommand_name)
-    Puppet::Application[subcommand_name].run
-else
-    abort "Error: Unknown command #{subcommand_name}.\n#{usage}\n#{available}"
-end
+Puppet::Util::CommandLine.new.execute
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 5fe07b2..6e67fd7 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -1,6 +1,6 @@
 module Puppet
     module Util
-        module CommandLine
+        class CommandLine
             def self.subcommand_name(*args)
                 subcommand_name, args = subcommand_and_args(*args)
                 return subcommand_name
@@ -42,6 +42,48 @@ module Puppet
                     [ zero, argv ]
                 end
             end
+
+            def self.appdir
+                File.join('puppet', 'application')
+            end
+
+            def self.available_subcommands
+                appdir = File.join('puppet', 'application')
+                absolute_appdir = $:.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) }
+                Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
+            end
+
+            def self.usage_message
+                usage = "Usage: puppet command <space separated arguments>"
+                available = "Available commands are: #{available_subcommands.sort.join(', ')}"
+                [usage, available].join("\n")
+            end
+
+            def initialize( zero = $0, argv = ARGV, stdin = STDIN )
+                @zero  = zero
+                @argv  = argv.dup
+                @stdin = stdin
+
+                @subcommand_name, @args = self.class.subcommand_and_args( @zero, @argv, @stdin )
+            end
+
+            attr :subcommand_name
+            attr :args
+
+            def execute
+                if subcommand_name.nil?
+                    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
+                else
+                    abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
+                end
+            end
+
+            def legacy_executable_name
+                LegacyName[ subcommand_name ]
+            end
         end
     end
 end
diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb
index a07438f..e20f51a 100644
--- a/spec/unit/util/command_line.rb
+++ b/spec/unit/util/command_line.rb
@@ -93,4 +93,21 @@ describe Puppet::Util::CommandLine do
         Puppet::Util::CommandLine.legacy_executable_name("puppetmasterd", [], @tty).should == "puppetmasterd"
     end
 
+    describe "when instantiated" do
+        it "should provide the results of subcommand and args" do
+            Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", [], @pipe).returns(["command", ['args']])
+            commandline = Puppet::Util::CommandLine.new("puppet", [], @pipe)
+
+            commandline.subcommand_name.should == 'command'
+            commandline.args.should == ['args']
+        end
+
+        it "should provide the legacy executable name" do
+            Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", ['master'], @pipe).returns(["master", []])
+            commandline = Puppet::Util::CommandLine.new("puppet", ['master'], @pipe)
+
+            commandline.legacy_executable_name.should == 'puppetmasterd'
+        end
+    end
+
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list