Module: Mongrel2::CLI

Extended by:
GLI::App, Loggability
Defined in:
lib/mongrel2/cli.rb

Overview

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:

[

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.

Defined Under Namespace

Modules: AccessCommand, BootstrapCommand, CommandUtilities, CommitCommand, HostsCommand, InitCommand, LoadCommand, LogCommand, QuickstartCommand, ReloadCommand, RoutesCommand, RunningCommand, ServersCommand, SettingsCommand, StartCommand, StopCommand, Subcommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#subcommand_modulesObject

Registered subcommand modules



150
151
152
# File 'lib/mongrel2/cli.rb', line 150

def subcommand_modules
  @subcommand_modules
end

Class Method Details

.add_registered_subcommandsObject

Add the commands from the registered subcommand modules.



170
171
172
173
174
175
176
177
178
# File 'lib/mongrel2/cli.rb', line 170

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) ⇒ Object

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



486
487
488
489
490
491
# File 'lib/mongrel2/cli.rb', line 486

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

.pastelObject

Return the Pastel colorizer.



183
184
185
# File 'lib/mongrel2/cli.rb', line 183

def self::pastel
  @pastel ||= Pastel.new( enabled: $stdout.tty? )
end

.promptObject

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



190
191
192
# File 'lib/mongrel2/cli.rb', line 190

def self::prompt
  @prompt ||= TTY::Prompt.new( output: $stderr )
end

.register_subcommands(mod) ⇒ Object

Add the specified module containing subcommands to the ‘mongrel2’ command.



161
162
163
164
165
166
# File 'lib/mongrel2/cli.rb', line 161

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) ⇒ Object

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



213
214
215
216
217
218
# File 'lib/mongrel2/cli.rb', line 213

def self::require_additional_libs( requires)
  requires.each do |path|
    path = "mongrel2/#{path}" unless path.start_with?( 'mongrel2/' )
    require( path )
  end
end

.reset_promptObject

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



197
198
199
# File 'lib/mongrel2/cli.rb', line 197

def self::reset_prompt
  @prompt = nil
end

.runObject

Overridden – Add registered subcommands immediately before running.



154
155
156
157
# File 'lib/mongrel2/cli.rb', line 154

def self::run( * )
  self.add_registered_subcommands
  super
end

.set_logging_level(level = nil) ⇒ Object

Set the global logging level if it’s defined.



203
204
205
206
207
208
209
# File 'lib/mongrel2/cli.rb', line 203

def self::set_logging_level( level=nil )
  if level
    Loggability.level = level.to_sym
  else
    Loggability.level = :fatal
  end
end

.setup_output(global) ⇒ Object

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



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/mongrel2/cli.rb', line 235

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_aliasesObject

Setup pastel color aliases



223
224
225
226
227
228
229
230
231
# File 'lib/mongrel2/cli.rb', line 223

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