Class MCollective::Applications
In: lib/mcollective/applications.rb
Parent: Object

Methods

[]   list   load_application   load_config   run  

Public Class methods

[Source]

   # File lib/mcollective/applications.rb, line 3
3:         def self.[](appname)
4:             load_application(appname)
5:             PluginManager["#{appname}_application"]
6:         end

Returns an array of applications found in the lib dirs

[Source]

    # File lib/mcollective/applications.rb, line 25
25:         def self.list
26:             load_config
27: 
28:             applist = []
29: 
30:             Config.instance.libdir.each do |libdir|
31:                 applicationdir = "#{libdir}/mcollective/application"
32:                 raise("Cannot find applications directory: '#{applicationdir}'") unless File.directory?(applicationdir)
33: 
34:                 Dir.entries(applicationdir).grep(/\.rb$/).each do |application|
35:                     applist << File.basename(application, ".rb")
36:                 end
37:             end
38: 
39:             applist
40:         rescue
41:             return []
42:         end

[Source]

    # File lib/mcollective/applications.rb, line 15
15:         def self.load_application(appname)
16:             return if PluginManager.include?("#{appname}_application")
17: 
18:             load_config
19: 
20:             PluginManager.loadclass "MCollective::Application::#{appname.capitalize}"
21:             PluginManager << {:type => "#{appname}_application", :class => "MCollective::Application::#{appname.capitalize}"}
22:         end

Loads the config and checks if —config or -c is given

This is mostly a hack, when we‘re redoing how config works this stuff should be made less sucky

[Source]

    # File lib/mcollective/applications.rb, line 48
48:         def self.load_config
49:             return if Config.instance.configured
50: 
51:             original_argv = ARGV.clone
52:             configfile = nil
53: 
54:             parser = OptionParser.new
55:             parser.on("--config CONFIG", "-c", "Config file") do |f|
56:                 configfile = f
57:             end
58: 
59:             parser.program_name = $0
60: 
61:             parser.on("--help")
62: 
63:             # avoid option parsers own internal version handling that sux
64:             parser.on("-v", "--verbose")
65: 
66:             parser.environment("MCOLLECTIVE_EXTRA_OPTS")
67: 
68:             begin
69:                 parser.parse!
70:             rescue OptionParser::InvalidOption
71:                 retry
72:             end
73: 
74:             ARGV.clear
75:             original_argv.each {|a| ARGV << a}
76: 
77:             configfile = Util.config_file_for_user unless configfile
78: 
79:             Config.instance.loadconfig(configfile)
80:         end

[Source]

    # File lib/mcollective/applications.rb, line 8
 8:         def self.run(appname)
 9:             load_config
10: 
11:             load_application(appname)
12:             PluginManager["#{appname}_application"].run
13:         end

[Validate]