summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-02-22 23:04:45 -0800
committerLuke Kanies <luke@puppetlabs.com>2011-02-22 23:04:45 -0800
commitbec807e5a12e24c11aedb40a997b154f1bed62c0 (patch)
treed148005c4339498688116052ffaedc658efccaeb /lib/puppet/interface.rb
parent368210e8a8a35cf2cae509b1d357337f9958cdff (diff)
downloadpuppet-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>
Diffstat (limited to 'lib/puppet/interface.rb')
-rw-r--r--lib/puppet/interface.rb56
1 files changed, 40 insertions, 16 deletions
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