From 12098f2d54e8e00a687f42837deeef65c7759389 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 18 Apr 2011 17:21:28 -0700 Subject: (#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 --- lib/puppet/application/face_base.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 456f0c610..6b13e16d4 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 } -- cgit