diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-02-23 00:20:15 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-02-23 00:20:15 -0800 |
| commit | 59a648502a8f09948bd2d25a72a9099f7740e108 (patch) | |
| tree | 3de97951a28a4710df603b86b69dec67211280bb /lib/puppet | |
| parent | 4fa54d02a2806e8fde54da9bb7e4d6735b3cffe4 (diff) | |
| download | puppet-59a648502a8f09948bd2d25a72a9099f7740e108.tar.gz puppet-59a648502a8f09948bd2d25a72a9099f7740e108.tar.xz puppet-59a648502a8f09948bd2d25a72a9099f7740e108.zip | |
Adding Application options to Interfaces
This allows all of the actions to react to the CLI
options.
I've also removed the unnecessary 'name' variables I
was using in various places - they were just the first
of the arguments, and they weren't actually always
names.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/application/interface_base.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/interface.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/indirector.rb | 20 |
3 files changed, 18 insertions, 14 deletions
diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb index 49c2e9622..044249d39 100644 --- a/lib/puppet/application/interface_base.rb +++ b/lib/puppet/application/interface_base.rb @@ -32,7 +32,7 @@ class Puppet::Application::InterfaceBase < Puppet::Application end - attr_accessor :interface, :type, :verb, :name, :arguments, :format + attr_accessor :interface, :type, :verb, :arguments, :format attr_writer :exit_code # This allows you to set the exit code if you don't want to just exit @@ -43,7 +43,7 @@ class Puppet::Application::InterfaceBase < Puppet::Application def main # Call the method associated with the provided action (e.g., 'find'). - if result = interface.send(verb, name, *arguments) + if result = interface.send(verb, *arguments) puts render(result) end exit(exit_code) @@ -58,7 +58,7 @@ class Puppet::Application::InterfaceBase < Puppet::Application def setup Puppet::Util::Log.newdestination :console - @verb, @name, @arguments = command_line.args + @verb, @arguments = command_line.args @arguments ||= [] @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym @@ -68,6 +68,10 @@ class Puppet::Application::InterfaceBase < Puppet::Application end @format ||= @interface.default_format + # We copy all of the app options to the interface. + # This allows each action to read in the options. + @interface.options = options + validate end diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index f8791e51f..3fb61c8a8 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -80,7 +80,7 @@ class Puppet::Interface @name || self.to_s.sub(/.+::/, '').downcase end - attr_accessor :type, :verb, :name, :arguments + attr_accessor :type, :verb, :name, :arguments, :options # Print the configuration for the current terminus class action :showconfig do |*args| diff --git a/lib/puppet/interface/indirector.rb b/lib/puppet/interface/indirector.rb index feb356d85..f106db4b8 100644 --- a/lib/puppet/interface/indirector.rb +++ b/lib/puppet/interface/indirector.rb @@ -10,20 +10,20 @@ class Puppet::Interface::Indirector < Puppet::Interface Puppet::Indirector::Terminus.terminus_classes(indirection.to_sym).collect { |t| t.to_s }.sort end - action :destroy do |name, *args| - call_indirection_method(:destroy, name, *args) + action :destroy do |*args| + call_indirection_method(:destroy, *args) end - action :find do |name, *args| - call_indirection_method(:find, name, *args) + action :find do |*args| + call_indirection_method(:find, *args) end - action :save do |name, *args| - call_indirection_method(:save, name, *args) + action :save do |*args| + call_indirection_method(:save, *args) end - action :search do |name, *args| - call_indirection_method(:search, name, *args) + action :search do |*args| + call_indirection_method(:search, *args) end attr_accessor :from @@ -55,9 +55,9 @@ class Puppet::Interface::Indirector < Puppet::Interface end end - def call_indirection_method(method, name, *args) + def call_indirection_method(method, *args) begin - result = indirection.send(method, name, *args) + result = indirection.send(method, *args) rescue => detail puts detail.backtrace if Puppet[:trace] raise "Could not call '#{method}' on '#{indirection_name}': #{detail}" |
