diff options
author | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 23:49:01 -0800 |
---|---|---|
committer | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 23:49:01 -0800 |
commit | 4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4 (patch) | |
tree | 71ac52c4fadb9617fc8f8925b682b3ac9e832c26 /lib/puppet/application | |
parent | bec807e5a12e24c11aedb40a997b154f1bed62c0 (diff) | |
download | puppet-4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4.tar.gz puppet-4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4.tar.xz puppet-4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4.zip |
Adding render and exit_code override support
This is mostly in response to feature requests from
Dan.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet/application')
-rw-r--r-- | lib/puppet/application/interface_base.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb index 9e8ea9948..49c2e9622 100644 --- a/lib/puppet/application/interface_base.rb +++ b/lib/puppet/application/interface_base.rb @@ -33,12 +33,26 @@ class Puppet::Application::InterfaceBase < Puppet::Application attr_accessor :interface, :type, :verb, :name, :arguments, :format + attr_writer :exit_code + + # This allows you to set the exit code if you don't want to just exit + # immediately but you need to indicate a failure. + def exit_code + @exit_code || 0 + end def main # Call the method associated with the provided action (e.g., 'find'). - result = interface.send(verb, name, *arguments) + if result = interface.send(verb, name, *arguments) + puts render(result) + end + exit(exit_code) + end + + # Override this if you need custom rendering. + def render(result) render_method = Puppet::Network::FormatHandler.format(format).render_method - puts result.send(render_method) if result + result.send(render_method) end def setup |