Inversion::

CLI class

Command class for the ‘inversion’ command-line tool.

Public Class Methods

add_registered_subcommands()

Add the commands from the registered subcommand modules.

# File lib/inversion/cli.rb, line 138
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 )

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

# File lib/inversion/cli.rb, line 395
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()

Return the Pastel colorizer.

# File lib/inversion/cli.rb, line 151
def self::pastel
        @pastel ||= Pastel.new( enabled: $stdout.tty? )
end
prompt()

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

# File lib/inversion/cli.rb, line 158
def self::prompt
        @prompt ||= TTY::Prompt.new( output: $stderr )
end
register_subcommands( mod )

Add the specified ‘mod`ule containing subcommands to the ’inversion’ command.

# File lib/inversion/cli.rb, line 129
def self::register_subcommands( mod )
        self.subcommand_modules ||= []
        self.subcommand_modules.push( mod )
        mod.extend( GLI::DSL, GLI::AppSupport, Loggability )
        mod.log_to( :inversion )
end
require_additional_libs( requires)

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

# File lib/inversion/cli.rb, line 181
def self::require_additional_libs( requires)
        requires.each do |path|
                path = "inversion/#{path}" unless path.start_with?( 'inversion/' )
                require( path )
        end
end
reset_prompt()

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

# File lib/inversion/cli.rb, line 165
def self::reset_prompt
        @prompt = nil
end
run( * )

Overridden – Add registered subcommands immediately before running.

# File lib/inversion/cli.rb, line 122
def self::run( * )
        self.add_registered_subcommands
        super
end
set_logging_level( level=nil )

Set the global logging ‘level` if it’s defined.

# File lib/inversion/cli.rb, line 171
def self::set_logging_level( level=nil )
        if level
                Loggability.level = level.to_sym
        else
                Loggability.level = :fatal
        end
end
setup_output( global )

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

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

        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()

Setup pastel color aliases

# File lib/inversion/cli.rb, line 191
def self::setup_pastel_aliases
        self.pastel.alias_color( :headline, :bold, :white, :on_black )
        self.pastel.alias_color( :success, :bold, :green )
        self.pastel.alias_color( :error, :bold, :red )
        self.pastel.alias_color( :up, :green )
        self.pastel.alias_color( :down, :red )
        self.pastel.alias_color( :unknown, :dark, :yellow )
        self.pastel.alias_color( :disabled, :dark, :white )
        self.pastel.alias_color( :quieted, :dark, :green )
        self.pastel.alias_color( :acked, :yellow )
        self.pastel.alias_color( :highlight, :bold, :yellow )
        self.pastel.alias_color( :search_hit, :black, :on_white )
        self.pastel.alias_color( :prompt, :cyan )
        self.pastel.alias_color( :even_row, :bold )
        self.pastel.alias_color( :odd_row, :reset )
end

Public Instance Methods

subcommand_modules()

Registered subcommand modules

# File lib/inversion/cli.rb, line 118
singleton_attr_accessor :subcommand_modules