[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Luke Kanies luke at puppetlabs.com
Tue May 10 08:05:18 UTC 2011


The following commit has been merged in the experimental branch:
commit 4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Tue Feb 22 23:49:01 2011 -0800

    Adding render and exit_code override support
    
    This is mostly in response to feature requests from
    Dan.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb
index 9e8ea99..49c2e96 100644
--- a/lib/puppet/application/interface_base.rb
+++ b/lib/puppet/application/interface_base.rb
@@ -33,12 +33,26 @@ class Puppet::Application::InterfaceBase < Puppet::Application
 
 
   attr_accessor :interface, :type, :verb, :name, :arguments, :format
+  attr_writer :exit_code
+
+  # This allows you to set the exit code if you don't want to just exit
+  # immediately but you need to indicate a failure.
+  def exit_code
+    @exit_code || 0
+  end
 
   def main
     # Call the method associated with the provided action (e.g., 'find').
-    result = interface.send(verb, name, *arguments)
+    if result = interface.send(verb, name, *arguments)
+      puts render(result)
+    end
+    exit(exit_code)
+  end
+
+  # Override this if you need custom rendering.
+  def render(result)
     render_method = Puppet::Network::FormatHandler.format(format).render_method
-    puts result.send(render_method) if result
+    result.send(render_method)
   end
 
   def setup
diff --git a/spec/unit/application/interface_base_spec.rb b/spec/unit/application/interface_base_spec.rb
index ca1353d..c20be11 100644
--- a/spec/unit/application/interface_base_spec.rb
+++ b/spec/unit/application/interface_base_spec.rb
@@ -2,8 +2,35 @@
 
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
 require 'puppet/application/interface_base'
+require 'puppet/application/interface_base'
+
+base_interface = Puppet::Interface.new(:basetest)
+class Puppet::Application::InterfaceBase::Basetest < Puppet::Application::InterfaceBase
+end
 
 describe Puppet::Application::InterfaceBase do
-  describe "during setup" do
+  before do
+    @app = Puppet::Application::InterfaceBase::Basetest.new
+    @app.stubs(:exit)
+    @app.stubs(:puts)
+  end
+
+  describe "when calling main" do
+    before do
+      @app.verb = :find
+      @app.name = "myname"
+      @app.arguments = "myarg"
+      @app.interface.stubs(:find)
+    end
+
+    it "should send the specified verb and name to the interface" do
+      @app.interface.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
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list