| Class | Mongrel::Command::Registry |
| In: |
lib/mongrel/command.rb
lib/mongrel/command.rb |
| Parent: | Object |
A Singleton class that manages all of the available commands and handles running them.
Prints a list of available commands.
# File lib/mongrel/command.rb, line 157
157: def print_command_list
158: puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"
159:
160: self.commands.each do |name|
161: if /mongrel::/ =~ name
162: name = name[9 .. -1]
163: end
164:
165: puts " - #{name[1 .. -1]}\n"
166: end
167:
168: puts "\nEach command takes -h as an option to get help."
169:
170: end
Prints a list of available commands.
# File lib/mongrel/command.rb, line 157
157: def print_command_list
158: puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"
159:
160: self.commands.each do |name|
161: if /mongrel::/ =~ name
162: name = name[9 .. -1]
163: end
164:
165: puts " - #{name[1 .. -1]}\n"
166: end
167:
168: puts "\nEach command takes -h as an option to get help."
169:
170: 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 175
175: def run(args)
176: # find the command
177: cmd_name = args.shift
178:
179: if !cmd_name or cmd_name == "?" or cmd_name == "help"
180: print_command_list
181: return true
182: elsif cmd_name == "--version"
183: puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}"
184: return true
185: end
186:
187: begin
188: # quick hack so that existing commands will keep working but the Mongrel:: ones can be moved
189: if ["start", "stop", "restart"].include? cmd_name
190: cmd_name = "mongrel::" + cmd_name
191: end
192:
193: command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args)
194: rescue OptionParser::InvalidOption
195: STDERR.puts "#$! for command '#{cmd_name}'"
196: STDERR.puts "Try #{cmd_name} -h to get help."
197: return false
198: rescue
199: STDERR.puts "ERROR RUNNING '#{cmd_name}': #$!"
200: STDERR.puts "Use help command to get help"
201: return false
202: end
203:
204: # Normally the command is NOT valid right after being created
205: # but sometimes (like with -h or -v) there's no further processing
206: # needed so the command is already valid so we can skip it.
207: if not command.done_validating
208: if not command.validate
209: STDERR.puts "#{cmd_name} reported an error. Use mongrel_rails #{cmd_name} -h to get help."
210: return false
211: else
212: command.run
213: end
214: end
215:
216: return true
217: 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 175
175: def run(args)
176: # find the command
177: cmd_name = args.shift
178:
179: if !cmd_name or cmd_name == "?" or cmd_name == "help"
180: print_command_list
181: return true
182: elsif cmd_name == "--version"
183: puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}"
184: return true
185: end
186:
187: begin
188: # quick hack so that existing commands will keep working but the Mongrel:: ones can be moved
189: if ["start", "stop", "restart"].include? cmd_name
190: cmd_name = "mongrel::" + cmd_name
191: end
192:
193: command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args)
194: rescue OptionParser::InvalidOption
195: STDERR.puts "#$! for command '#{cmd_name}'"
196: STDERR.puts "Try #{cmd_name} -h to get help."
197: return false
198: rescue
199: STDERR.puts "ERROR RUNNING '#{cmd_name}': #$!"
200: STDERR.puts "Use help command to get help"
201: return false
202: end
203:
204: # Normally the command is NOT valid right after being created
205: # but sometimes (like with -h or -v) there's no further processing
206: # needed so the command is already valid so we can skip it.
207: if not command.done_validating
208: if not command.validate
209: STDERR.puts "#{cmd_name} reported an error. Use mongrel_rails #{cmd_name} -h to get help."
210: return false
211: else
212: command.run
213: end
214: end
215:
216: return true
217: end