[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:16:47 UTC 2011
The following commit has been merged in the experimental branch:
commit 12098f2d54e8e00a687f42837deeef65c7759389
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon Apr 18 17:21:28 2011 -0700
(#7013) Handle rendering modes out in the application layer.
We no longer establish the rendering mode in the actions; they just default to
"nothing", and let that flow on out to the application layer. That lets the
facade we put before the face determine the default behaviour.
This is mostly a no-op down in the CLI side, but it makes it much easier to
integrate into MCollective, HTTP-API, and for other non-CLI users of Faces.
Reviewed-By: Max Martin <max at puppetlabs.com>
diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb
index 456f0c6..6b13e16 100644
--- a/lib/puppet/application/face_base.rb
+++ b/lib/puppet/application/face_base.rb
@@ -37,21 +37,23 @@ class Puppet::Application::FaceBase < Puppet::Application
# Override this if you need custom rendering.
def render(result)
- if render_as then
- render_method = Puppet::Network::FormatHandler.format(render_as).render_method
+ format = render_as || action.render_as || :for_humans
+ if format == :for_humans then
+ render_for_humans(result)
+ else
+ render_method = Puppet::Network::FormatHandler.format(format).render_method
if render_method == "to_pson"
- jj result
+ PSON::pretty_generate(result, :allow_nan => true, :max_nesting => false)
else
result.send(render_method)
end
- else
- render_for_humans(result)
end
end
def render_for_humans(result)
# String to String
return result if result.is_a? String
+ return result if result.is_a? Numeric
# Simple hash to table
if result.is_a? Hash and result.keys.all? { |x| x.is_a? String or x.is_a? Numeric }
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 8bacc21..d9ba4eb 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -11,7 +11,6 @@ class Puppet::Interface::Action
@options = {}
@when_rendering = {}
- @render_as = :for_humans
end
# This is not nice, but it is the easiest way to make us behave like the
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index 6a46472..6dfde43 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -211,11 +211,18 @@ describe Puppet::Application::FaceBase do
end
describe "#render" do
- it "should just return a String" do
- app.render("hello").should == "hello"
+ before :each do
+ app.face = Puppet::Face[:basetest, '0.0.1']
+ app.action = app.face.get_action(:foo)
+ end
+
+ ["hello", 1, 1.0].each do |input|
+ it "should just return a #{input.class.name}" do
+ app.render(input).should == input
+ end
end
- [1, 1.000, [1, 2], ["one"], [{ 1 => 1 }]].each do |input|
+ [[1, 2], ["one"], [{ 1 => 1 }]].each do |input|
it "should render #{input.class} using the 'pp' library" do
app.render(input).should == input.pretty_inspect
end
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb
index c122d3e..bf7afa7 100755
--- a/spec/unit/interface/action_builder_spec.rb
+++ b/spec/unit/interface/action_builder_spec.rb
@@ -151,9 +151,9 @@ describe Puppet::Interface::ActionBuilder do
end
context "#render_as" do
- it "should default to :for_humans" do
+ it "should default to nil (eg: based on context)" do
action = Puppet::Interface::ActionBuilder.build(face, :foo) do end
- action.render_as.should == :for_humans
+ action.render_as.should be_nil
end
it "should fail if not rendering format is given" do
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list