Class: Mongrel::Command::Registry

### Home Classes Methods

### In Files

- lib/mongrel/command.rb

### Parent

Object

### Methods

- #commands
- #print_command_list
- #run

### Included Modules

- Singleton

### Files

- CHANGELOG
- COPYING
- LICENSE
- README
- Makefile

### Class/Module Index

Quicksearch

- Mongrel
- Mongrel::CGIWrapper
- Mongrel::Camping
- Mongrel::Camping::CampingHandler
- Mongrel::Command
- Mongrel::Command::Base
- Mongrel::Command::Registry
- Mongrel::Configurator
- Mongrel::Const
- Mongrel::DeflateFilter
- Mongrel::DirHandler
- Mongrel::Error404Handler
- Mongrel::Gems
- Mongrel::HeaderOut
- Mongrel::HttpHandler
- Mongrel::HttpHandlerPlugin
- Mongrel::HttpParams
- Mongrel::HttpParser
- Mongrel::HttpParserError
- Mongrel::HttpRequest
- Mongrel::HttpResponse
- Mongrel::HttpServer
- Mongrel::Rails
- Mongrel::Rails::RailsConfigurator
- Mongrel::Rails::RailsHandler
- Mongrel::RedirectHandler
- Mongrel::StatisticsFilter
- Mongrel::Stats
- Mongrel::StatusHandler
- Mongrel::StopServer
- Mongrel::TimeoutError
- Mongrel::URIClassifier
- Mongrel::URIClassifier::RegistrationError
- Mongrel::URIClassifier::UsageError
- RequestLog
- RequestLog::Access
- RequestLog::Files
- RequestLog::Objects
- RequestLog::Params
- RequestLog::Threads
- IO
- Kernel
- MongrelDbg
- TCPServer

No matching classes.

# Mongrel::Command::Registry

A Singleton class that manages all of the available commands and handles running them.

### Public Instance Methods

commands() click to toggle source

Builds a list of possible commands from the Command derivates list

    # File lib/mongrel/command.rb, line 150
    def commands
      pmgr = GemPlugin::Manager.instance
      list = pmgr.plugins["/commands"].keys
      return list.sort
    end

print_command_list() click to toggle source

Prints a list of available commands.

    # File lib/mongrel/command.rb, line 157
    def print_command_list
      puts "#{Mongrel::Command::BANNER}\nAvailable commands are:\n\n"

      self.commands.each do |name|
        if /mongrel::/ =~ name
          name = name[9 .. -1]
        end

        puts " - #{name[1 .. -1]}\n"
      end

      puts "\nEach command takes -h as an option to get help."

    end

run(args) click to toggle source

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
    def run(args)
      # find the command
      cmd_name = args.shift

      if !cmd_name or cmd_name == "?" or cmd_name == "help"
        print_command_list
        return true
      elsif cmd_name == "--version"
        puts "Mongrel Web Server #{Mongrel::Const::MONGREL_VERSION}"
        return true
      end

      begin
        # quick hack so that existing commands will keep working but the Mongrel:: ones can be moved
        if ["start", "stop", "restart"].include? cmd_name
          cmd_name = "mongrel::" + cmd_name
        end

        command = GemPlugin::Manager.instance.create("/commands/#{cmd_name}", :argv => args)
      rescue OptionParser::InvalidOption
        STDERR.puts "#$! for command '#{cmd_name}'"
        STDERR.puts "Try #{cmd_name} -h to get help."
        return false
      rescue
        STDERR.puts "ERROR RUNNING '#{cmd_name}': #$!"
        STDERR.puts "Use help command to get help"
        return false
      end

      # Normally the command is NOT valid right after being created
      # but sometimes (like with -h or -v) there's no further processing
      # needed so the command is already valid so we can skip it.
      if not command.done_validating
        if not command.validate
          STDERR.puts "#{cmd_name} reported an error. Use mongrel_rails #{cmd_name} -h to get help."
          return false
        else
          command.run
        end
      end

      return true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.