diff options
author | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 23:04:45 -0800 |
---|---|---|
committer | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 23:04:45 -0800 |
commit | bec807e5a12e24c11aedb40a997b154f1bed62c0 (patch) | |
tree | d148005c4339498688116052ffaedc658efccaeb | |
parent | 368210e8a8a35cf2cae509b1d357337f9958cdff (diff) | |
download | puppet-bec807e5a12e24c11aedb40a997b154f1bed62c0.tar.gz puppet-bec807e5a12e24c11aedb40a997b154f1bed62c0.tar.xz puppet-bec807e5a12e24c11aedb40a997b154f1bed62c0.zip |
Fixing 'puppet interface list'
Also added a test to hopefully confirm it won't
break again.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
-rw-r--r-- | lib/puppet/application/interface.rb | 30 | ||||
-rw-r--r-- | lib/puppet/interface.rb | 56 | ||||
-rw-r--r-- | spec/unit/application/interface_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/interface_spec.rb | 2 |
4 files changed, 55 insertions, 43 deletions
diff --git a/lib/puppet/application/interface.rb b/lib/puppet/application/interface.rb index 8f26658c9..10823e920 100644 --- a/lib/puppet/application/interface.rb +++ b/lib/puppet/application/interface.rb @@ -1,4 +1,5 @@ require 'puppet/application' +require 'puppet/interface' class Puppet::Application::Interface < Puppet::Application @@ -24,6 +25,7 @@ class Puppet::Application::Interface < Puppet::Application terms = terminus_classes(name.to_sym) str << "\tTerminuses: #{terms.join(", ")}\n" rescue => detail + puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not load terminuses for #{name}: #{detail}" end end @@ -33,13 +35,13 @@ class Puppet::Application::Interface < Puppet::Application actions = actions(name.to_sym) str << "\tActions: #{actions.join(", ")}\n" rescue => detail + puts detail.backtrace if Puppet[:trace] $stderr.puts "Could not load actions for #{name}: #{detail}" end end print str end - exit(0) end attr_accessor :verb, :name, :arguments @@ -71,31 +73,7 @@ class Puppet::Application::Interface < Puppet::Application end def interfaces - # Load all of the interfaces - unless @interfaces - $LOAD_PATH.each do |dir| - next unless FileTest.directory?(dir) - Dir.chdir(dir) do - Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file| - begin - require file - rescue Error => detail - puts detail.backtrace if Puppet[:trace] - raise "Could not load #{file}: #{detail}" - end - end - end - end - - @interfaces = [] - Puppet::Interface.constants.each do |name| - klass = Puppet::Interface.const_get(name) - next if klass.abstract? # skip base classes - - @interfaces << name.downcase - end - end - @interfaces + Puppet::Interface.interfaces end def terminus_classes(indirection) diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index 70356debc..f8791e51f 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -12,6 +12,27 @@ class Puppet::Interface @autoloader ||= Puppet::Util::Autoload.new(:application, "puppet/interface") end + def self.interfaces + unless @loaded + @loaded = true + $LOAD_PATH.each do |dir| + next unless FileTest.directory?(dir) + Dir.chdir(dir) do + Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file| + iname = file.sub(/\.rb/, '') + begin + require iname + rescue Exception => detail + puts detail.backtrace if Puppet[:trace] + raise "Could not load #{iname} from #{dir}/#{file}: #{detail}" + end + end + end + end + end + @interfaces.keys + end + # Return an interface by name, loading from disk if necessary. def self.interface(name) @interfaces ||= {} @@ -24,21 +45,6 @@ class Puppet::Interface $stderr.puts "Unable to find interface '#{name.to_s}': #{detail}." end - # Try to find actions defined in other files. - def self.load_actions(name) - path = "puppet/interface/#{name}" - - autoloader.search_directories.each do |dir| - fdir = ::File.join(dir, path) - next unless FileTest.directory?(fdir) - - Dir.glob("#{fdir}/*.rb").each do |file| - Puppet.info "Loading actions for '#{name}' from '#{file}'" - require file - end - end - end - def self.register_interface(name, instance) @interfaces ||= {} @interfaces[unify_name(name)] = instance @@ -97,13 +103,31 @@ class Puppet::Interface # subclasses. Puppet::Interface.register_interface(name, self) - Puppet::Interface.load_actions(name) + load_actions if block_given? instance_eval(&block) end end + # Try to find actions defined in other files. + def load_actions + path = "puppet/interface/#{name}" + + self.class.autoloader.search_directories.each do |dir| + fdir = ::File.join(dir, path) + next unless FileTest.directory?(fdir) + + Dir.chdir(fdir) do + Dir.glob("*.rb").each do |file| + aname = file.sub(/\.rb/, '') + Puppet.debug "Loading action '#{aname}' for '#{name}' from '#{fdir}/#{file}'" + require "#{path}/#{aname}" + end + end + end + end + def to_s name.to_s end diff --git a/spec/unit/application/interface_spec.rb b/spec/unit/application/interface_spec.rb new file mode 100644 index 000000000..153e9bdc1 --- /dev/null +++ b/spec/unit/application/interface_spec.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/application/interface' + +describe Puppet::Application::Interface do + it "should be an application" do + Puppet::Application::Interface.superclass.should equal(Puppet::Application) + end +end diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb index 5d25623e7..774c0bd91 100644 --- a/spec/unit/interface_spec.rb +++ b/spec/unit/interface_spec.rb @@ -19,7 +19,7 @@ describe Puppet::Interface do end it "should load actions" do - Puppet::Interface.expects(:load_actions).with(:me) + Puppet::Interface.any_instance.expects(:load_actions) Puppet::Interface.new(:me) end |