A Singleton class that manages all of the available commands and handles running them.
Builds a list of possible commands from the Command derivates list
# File lib/mongrel/command.rb, line 148 148: def commands 149: pmgr = GemPlugin::Manager.instance 150: list = pmgr.plugins["/commands"].keys 151: return list.sort 152: end
Prints a list of available commands.
# File lib/mongrel/command.rb, line 155 155: def print_command_list 156: puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n" 157: 158: self.commands.each do |name| 159: if /mongrel::/ =~ name 160: name = name[9 .. 1] 161: end 162: 163: puts " - #{name[1 .. -1]}\n" 164: end 165: 166: puts "\nEach command takes -h as an option to get help." 167: 168: end
Runs the args against the first argument as the command name. If it has any errors it returns a false, otherwise it return true.
# File lib/mongrel/command.rb, line 173 173: def run(args) 174: # find the command 175: cmd_name = args.shift 176: 177: if !cmd_name or cmd_name == "?" or cmd_name == "help" 178: print_command_list 179: return true 180: elsif cmd_name == "--version" 181: puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}" 182: return true 183: end 184: 185: begin 186: # quick hack so that existing commands will keep working but the Mongrel:: ones can be moved 187: if ["start", "stop", "restart"].include? cmd_name 188: cmd_name = "mongrel::" + cmd_name 189: end 190: 191: command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args) 192: rescue OptionParser::InvalidOption 193: STDERR.puts "#$! for command '#{cmd_name}'" 194: STDERR.puts "Try #{cmd_name} -h to get help." 195: return false 196: rescue 197: STDERR.puts "ERROR RUNNING '#{cmd_name}': #$!" 198: STDERR.puts "Use help command to get help" 199: return false 200: end 201: 202: # Normally the command is NOT valid right after being created 203: # but sometimes (like with -h or -v) there's no further processing 204: # needed so the command is already valid so we can skip it. 205: if not command.done_validating 206: if not command.validate 207: STDERR.puts "#{cmd_name} reported an error. Use mongrel_rails #{cmd_name} -h to get help." 208: return false 209: else 210: command.run 211: end 212: end 213: 214: return true 215: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.