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


The following commit has been merged in the experimental branch:
commit 1b4d7a51d10b217c7f67f3876242fff6dc694faa
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Mon Apr 4 16:46:09 2011 -0700

    (#6962) Create the basic shape of the help face.
    
    This implements the basic help face, along with the start of the support
    structures; we include the basic application, and the default help action that
    just emits a listing of faces and other discovered stuff...
    
    Reviewed-By: Matt Robinson <matt at puppetlabs.com>

diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb
new file mode 100644
index 0000000..69905af
--- /dev/null
+++ b/lib/puppet/application/help.rb
@@ -0,0 +1,7 @@
+require 'puppet/application/faces_base'
+
+class Puppet::Application::Help < Puppet::Application::FacesBase
+  def render(result)
+    puts result.join("\n")
+  end
+end
diff --git a/lib/puppet/faces/help.rb b/lib/puppet/faces/help.rb
new file mode 100644
index 0000000..e986d19
--- /dev/null
+++ b/lib/puppet/faces/help.rb
@@ -0,0 +1,52 @@
+require 'puppet/faces'
+
+Puppet::Faces.define(:help, '0.0.1') do
+  summary "Displays help about puppet subcommands"
+
+  action(:help) do
+    option "--version VERSION" do
+      desc "Which version of the interface to show help for"
+    end
+
+    when_invoked do |*args|
+      # Check our invocation, because we want varargs and can't do defaults
+      # yet.  REVISIT: when we do option defaults, and positional options, we
+      # should rewrite this to use those. --daniel 2011-04-04
+      options = args.pop
+      if options.nil? or args.length > 2 then
+        raise ArgumentError, "help only takes two (optional) arguments, a face name, and an action"
+      end
+
+      if options[:version] and options[:version] !~ /^current$/i then
+        version = options[:version]
+      else
+        version = :current
+      end
+
+      message = []
+      if args.length == 0 then
+        message << "Use: puppet [options] <subcommand> <action>"
+        message << ""
+        message << "Available commands, from Puppet Faces:"
+        Puppet::Faces.faces.sort.each do |name|
+          face = Puppet::Faces[name, :current]
+          message << format("  %-15s %s", face.name, 'REVISIT: face.desc')
+        end
+      else
+        face = Puppet::Faces[args[0].to_sym, version]
+        if args[1] then
+          action = face.get_action args[1].to_sym
+        else
+          action = nil
+        end
+
+        help = []
+        face.actions.each do |action|
+          help << "Action: #{action}"
+        end
+      end
+
+      message
+    end
+  end
+end
diff --git a/spec/unit/faces/help_spec.rb b/spec/unit/faces/help_spec.rb
new file mode 100644
index 0000000..5b611a0
--- /dev/null
+++ b/spec/unit/faces/help_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+require 'puppet/faces/help'
+
+describe Puppet::Faces[:help, '0.0.1'] do
+  it "should have a help action" do
+    subject.should be_action :help
+  end
+
+  it "should have a default action of help" do
+    pending "REVISIT: we don't support default actions yet"
+  end
+
+  it "should accept a call with no arguments" do
+    expect { subject.help() }.should_not raise_error
+  end
+
+  it "should accept a face name" do
+    expect { subject.help(:help) }.should_not raise_error
+  end
+
+  it "should accept a face and action name" do
+    expect { subject.help(:help, :help) }.should_not raise_error
+  end
+
+  it "should fail if more than a face and action are given" do
+    expect { subject.help(:help, :help, :for_the_love_of_god) }.
+      should raise_error ArgumentError
+  end
+
+  it "should treat :current and 'current' identically" do
+    subject.help(:help, :current).should ==
+      subject.help(:help, 'current')
+  end
+
+  it "should complain when the request version of a face is missing" do
+    expect { subject.help(:huzzah, :bar, :version => '17.0.0') }.
+      should raise_error Puppet::Error
+  end
+
+  it "should find a face by version" do
+    face = Puppet::Faces[:huzzah, :current]
+    subject.help(:huzzah, face.version).should == subject.help(:huzzah, :current)
+  end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list