diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-02-08 21:27:24 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-02-08 21:27:24 -0800 |
| commit | 3ffb9abd3a500f1fb3246e04f737b79d232c082d (patch) | |
| tree | 2d76baf7a8043c7ff6cc7d746798de8470108f13 /lib/puppet | |
| parent | 9cb594f898496e36c76f0717b73897f07e8aca5a (diff) | |
| download | puppet-3ffb9abd3a500f1fb3246e04f737b79d232c082d.tar.gz puppet-3ffb9abd3a500f1fb3246e04f737b79d232c082d.tar.xz puppet-3ffb9abd3a500f1fb3246e04f737b79d232c082d.zip | |
Moving 'format' support to the application
This allows easier use of the Interfaces in ruby.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/application/data_baseclass.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/interface.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/interface/facts.rb | 2 |
3 files changed, 17 insertions, 8 deletions
diff --git a/lib/puppet/application/data_baseclass.rb b/lib/puppet/application/data_baseclass.rb index 3f498f56f..e67b1b368 100644 --- a/lib/puppet/application/data_baseclass.rb +++ b/lib/puppet/application/data_baseclass.rb @@ -18,7 +18,7 @@ class Puppet::Application::DataBaseclass < Puppet::Application end option("--format FORMAT") do |arg| - @format = arg + @format = arg.to_sym end # XXX this doesn't work, I think @@ -46,11 +46,11 @@ class Puppet::Application::DataBaseclass < Puppet::Application def main # Call the method associated with the provided action (e.g., 'find'). - interface.send(verb, name, *arguments) + result = interface.send(verb, name, *arguments) + puts result.render(format) end def setup - @format ||= :yaml Puppet::Util::Log.newdestination :console @@ -60,7 +60,7 @@ class Puppet::Application::DataBaseclass < Puppet::Application @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym @interface = Puppet::Interface.interface(@type).new - @interface.format = format if format + @format ||= @interface.class.default_format || :pson validate diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index 6e132f645..f35a8bf44 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -1,6 +1,15 @@ require 'puppet' class Puppet::Interface + + class << self + attr_accessor :default_format + + def set_default_format(format) + self.default_format = format.to_sym + end + end + # This is just so we can search for actions. We only use its # list of directories to search. def self.autoloader @@ -67,7 +76,7 @@ class Puppet::Interface @name || self.to_s.sub(/.+::/, '').downcase end - attr_accessor :from, :type, :verb, :name, :arguments, :indirection, :format + attr_accessor :from, :type, :verb, :name, :arguments, :indirection def action?(name) self.class.actions.include?(name.to_sym) @@ -105,8 +114,6 @@ class Puppet::Interface def initialize(options = {}) options.each { |opt, val| send(opt.to_s + "=", val) } - @format ||= :yaml - Puppet::Util::Log.newdestination :console self.class.load_actions @@ -132,7 +139,7 @@ class Puppet::Interface raise "Could not #{method} #{indirection.name} for #{name}" end - puts result.render(format.to_sym) + result end def indirections diff --git a/lib/puppet/interface/facts.rb b/lib/puppet/interface/facts.rb index 411416710..e40bb56d0 100644 --- a/lib/puppet/interface/facts.rb +++ b/lib/puppet/interface/facts.rb @@ -1,6 +1,8 @@ require 'puppet/interface' class Puppet::Interface::Facts < Puppet::Interface + set_default_format :yaml + # Upload our facts to the server action(:upload) do |*args| Puppet::Node::Facts.indirection.terminus_class = :facter |
