[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:13:18 UTC 2011


The following commit has been merged in the experimental branch:
commit 14b1e008c1368e6c56d68f83999472351fd3327a
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Mon Apr 11 10:57:06 2011 -0700

    (#6992) Expose available_subcommands as a class method.
    
    We previously treated the list of legacy commands as an instance property of
    Puppet::Util::CommandLine.  This made it difficult to obtain that information
    outside the context of the instantiated application.
    
    In the longer term this should wither and die as we eliminate the legacy
    applications entirely, but until then exposing that on the class is the
    lightest mechanism for making that useful.
    
    Paired-With: Matt Robinson <matt at puppetlabs.com>

diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 52b5f81..2891030 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -33,14 +33,21 @@ module Puppet
         File.join('puppet', 'application')
       end
 
-      def available_subcommands
-        absolute_appdirs = $LOAD_PATH.collect do |x| 
+      def self.available_subcommands
+        absolute_appdirs = $LOAD_PATH.collect do |x|
           File.join(x,'puppet','application')
         end.select{ |x| File.directory?(x) }
         absolute_appdirs.inject([]) do |commands, dir|
           commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
         end.uniq
       end
+      # available_subcommands was previously an instance method, not a class
+      # method, and we have an unknown number of user-implemented applications
+      # that depend on that behaviour.  Forwarding allows us to preserve a
+      # backward compatible API. --daniel 2011-04-11
+      def available_subcommands
+        self.class.available_subcommands
+      end
 
       def usage_message
         usage = "Usage: puppet command <space separated arguments>"
diff --git a/spec/unit/util/command_line_spec.rb b/spec/unit/util/command_line_spec.rb
index ca5f054..c5c6e5f 100755
--- a/spec/unit/util/command_line_spec.rb
+++ b/spec/unit/util/command_line_spec.rb
@@ -111,6 +111,11 @@ describe Puppet::Util::CommandLine do
       @core_apps = %w{describe filebucket kick queue resource agent cert apply doc master}
       @command_line = Puppet::Util::CommandLine.new("foo", %w{ client --help whatever.pp }, @tty )
     end
+    it "should expose available_subcommands as a class method" do
+      @core_apps.each do |command|
+        @command_line.available_subcommands.should include command
+      end
+    end
     it 'should be able to find all existing commands' do
       @core_apps.each do |command|
         @command_line.available_subcommands.should include command

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list