[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:18:35 UTC 2011
The following commit has been merged in the experimental branch:
commit 80adaea6319b2aca81fd3d9b1d0061152b6c7db2
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Wed Apr 27 18:30:27 2011 -0700
(#7160) Support 'json' as a rendering method for CLI faces.
We already had some specialized support for rendering JSON using the PSON
libraries; this just extends that to recognize the request on the command line
for json to be identical to a request for pson.
Theoretically we should also support the format in our network rendering code,
but that is a much bigger change, in established code, that has more chance of
destabilizing the whole release.
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 257d51f..cc62257 100644
--- a/lib/puppet/application/face_base.rb
+++ b/lib/puppet/application/face_base.rb
@@ -36,15 +36,18 @@ class Puppet::Application::FaceBase < Puppet::Application
result = hook.call(result)
end
+ begin
+ render_method = Puppet::Network::FormatHandler.format(format).render_method
+ rescue
+ render_method = nil
+ end
+
if format == :for_humans then
render_for_humans(result)
+ elsif format == :json or render_method == "to_pson"
+ PSON::pretty_generate(result, :allow_nan => true, :max_nesting => false)
else
- render_method = Puppet::Network::FormatHandler.format(format).render_method
- if render_method == "to_pson"
- PSON::pretty_generate(result, :allow_nan => true, :max_nesting => false)
- else
- result.send(render_method)
- end
+ result.send(render_method)
end
end
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index 7b3a69f..e84e676 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -296,5 +296,13 @@ EOT
app.action.render_as = :for_humans
app.render("bi-polar?").should == "bi-winning!"
end
+
+ it "should render JSON when asked for json" do
+ app.action.render_as = :json
+ json = app.render({ :one => 1, :two => 2 })
+ json.should =~ /"one":\s*1\b/
+ json.should =~ /"two":\s*2\b/
+ PSON.parse(json).should == { "one" => 1, "two" => 2 }
+ end
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list