[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Luke Kanies
luke at puppetlabs.com
Tue May 10 08:05:18 UTC 2011
The following commit has been merged in the experimental branch:
commit 59a648502a8f09948bd2d25a72a9099f7740e108
Author: Luke Kanies <luke at puppetlabs.com>
Date: Wed Feb 23 00:20:15 2011 -0800
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 at puppetlabs.com>
diff --git a/lib/puppet/application/interface_base.rb b/lib/puppet/application/interface_base.rb
index 49c2e96..044249d 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 f8791e5..3fb61c8 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 feb356d..f106db4 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}"
diff --git a/spec/unit/application/interface_base_spec.rb b/spec/unit/application/interface_base_spec.rb
index c20be11..4ef3869 100644
--- a/spec/unit/application/interface_base_spec.rb
+++ b/spec/unit/application/interface_base_spec.rb
@@ -11,6 +11,7 @@ end
describe Puppet::Application::InterfaceBase do
before do
@app = Puppet::Application::InterfaceBase::Basetest.new
+ @app.stubs(:interface).returns base_interface
@app.stubs(:exit)
@app.stubs(:puts)
end
@@ -18,8 +19,7 @@ describe Puppet::Application::InterfaceBase do
describe "when calling main" do
before do
@app.verb = :find
- @app.name = "myname"
- @app.arguments = "myarg"
+ @app.arguments = ["myname", "myarg"]
@app.interface.stubs(:find)
end
@@ -33,4 +33,18 @@ describe Puppet::Application::InterfaceBase do
it "should exit with the current exit code"
end
+
+ describe "during setup" do
+ before do
+ @app.command_line.stubs(:args).returns("find", "myname", "myarg")
+ @app.stubs(:validate)
+ end
+
+ it "should set the options on the interface" do
+ @app.options[:foo] = "bar"
+ @app.setup
+
+ @app.interface.options.should == @app.options
+ end
+ end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list