From 80adaea6319b2aca81fd3d9b1d0061152b6c7db2 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 27 Apr 2011 18:30:27 -0700 Subject: (#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 --- lib/puppet/application/face_base.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 257d51f75..cc62257c7 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 -- cgit