module Mongrel2::CLI

A tool for interacting with a Mongrel2 config database and server. This isn't quite a replacement for the real m2sh yet; here's what I have working so far:

[√]    load  Load a config.
[√]  config  Alias for load.
[-]   shell  Starts an interactive shell.
[√]  access  Prints the access log.
[√] servers  Lists the servers in a config database.
[√]   hosts  Lists the hosts in a server.
[√]  routes  Lists the routes in a host.
[√]  commit  Adds a message to the log.
[√]     log  Prints the commit log.
[√]   start  Starts a server.
[√]    stop  Stops a server.
[√]  reload  Reloads a server.
[√] running  Tells you what's running.
[-] control  Connects to the control port.
[√] version  Prints the Mongrel2 and m2sh version.
[√]    help  Get help, lists commands.
[-]    uuid  Prints out a randomly generated UUID.

I just use 'uuidgen' to generate uuids (which is all m2sh does, as well), so I don't plan to implement that. The 'control' command is more-easily accessed via pry+Mongrel2::Control, so I'm not going to implement that, either. Everything else should be analagous to (or better than) the m2sh that comes with mongrel2. I implemented the 'shell' mode, but I found I never used it, and it introduced a dependency on the Termios library, so I removed it.

Public Class Methods

add_registered_subcommands() click to toggle source

Add the commands from the registered subcommand modules.

# File lib/mongrel2/cli.rb, line 169
def self::add_registered_subcommands
        self.subcommand_modules ||= []
        self.subcommand_modules.each do |mod|
                merged_commands = mod.commands.merge( self.commands )
                self.commands.update( merged_commands )
                command_objs = self.commands_declaration_order | self.commands.values
                self.commands_declaration_order.replace( command_objs )
        end
end
commands_from( subdir ) click to toggle source

Load commands from any files in the specified directory relative to LOAD_PATHs

# File lib/mongrel2/cli.rb, line 485
def self::commands_from( subdir )
        Gem.find_latest_files( File.join(subdir, '*.rb') ).each do |rbfile|
                self.log.debug "  loading %s..." % [ rbfile ]
                require( rbfile )
        end
end
pastel() click to toggle source

Return the Pastel colorizer.

# File lib/mongrel2/cli.rb, line 182
def self::pastel
        @pastel ||= Pastel.new( enabled: $stdout.tty? )
end
prompt() click to toggle source

Return the TTY prompt used by the command to communicate with the user.

# File lib/mongrel2/cli.rb, line 189
def self::prompt
        @prompt ||= TTY::Prompt.new( output: $stderr )
end
register_subcommands( mod ) click to toggle source

Add the specified +mod+ule containing subcommands to the 'mongrel2' command.

# File lib/mongrel2/cli.rb, line 160
def self::register_subcommands( mod )
        self.subcommand_modules ||= []
        self.subcommand_modules.push( mod )
        mod.extend( GLI::DSL, GLI::AppSupport, Loggability, CommandUtilities )
        mod.log_to( :mongrel2 )
end
require_additional_libs( requires) click to toggle source

Load any additional Ruby libraries given with the -r global option.

# File lib/mongrel2/cli.rb, line 212
def self::require_additional_libs( requires)
        requires.each do |path|
                path = "mongrel2/#{path}" unless path.start_with?( 'mongrel2/' )
                require( path )
        end
end
reset_prompt() click to toggle source

Discard the existing HighLine prompt object if one existed. Mostly useful for testing.

# File lib/mongrel2/cli.rb, line 196
def self::reset_prompt
        @prompt = nil
end
run( * ) click to toggle source

Overridden – Add registered subcommands immediately before running.

Calls superclass method
# File lib/mongrel2/cli.rb, line 153
def self::run( * )
        self.add_registered_subcommands
        super
end
set_logging_level( level=nil ) click to toggle source

Set the global logging level if it's defined.

# File lib/mongrel2/cli.rb, line 202
def self::set_logging_level( level=nil )
        if level
                Loggability.level = level.to_sym
        else
                Loggability.level = :fatal
        end
end
setup_output( global ) click to toggle source

Set up the output levels and globals based on the associated global options.

# File lib/mongrel2/cli.rb, line 234
def self::setup_output( global )

        # Turn on Ruby debugging and/or verbosity if specified
        if global[:n]
                $DRYRUN = true
                Loggability.level = :warn
        else
                $DRYRUN = false
        end

        if global[:verbose]
                $VERBOSE = true
                Loggability.level = :info
        end

        if global[:debug]
                $DEBUG = true
                Loggability.level = :debug
        end

        if global[:loglevel]
                Loggability.level = global[:loglevel]
        end

end
setup_pastel_aliases() click to toggle source

Setup pastel color aliases

# File lib/mongrel2/cli.rb, line 222
def self::setup_pastel_aliases
        self.pastel.alias_color( :headline, :bold, :white, :on_black )
        self.pastel.alias_color( :header, :bold, :white )
        self.pastel.alias_color( :success, :bold, :green )
        self.pastel.alias_color( :error, :bold, :red )
        self.pastel.alias_color( :key, :green )
        self.pastel.alias_color( :even_row, :bold )
        self.pastel.alias_color( :odd_row, :reset )
end

Public Instance Methods

unknown() click to toggle source

Registered subcommand modules

# File lib/mongrel2/cli.rb, line 149
singleton_class.attr_accessor :subcommand_modules