Ravn::

CLI module

Command-line interface framework for Ravn utilities.

Constants

DEFAULT_REPO_LIST

The list of repositories to maintain with developer CLI commands. The defaults are all relative to the ::projects_dir, but they can be overridden with absolute paths as well.

EDITOR_ENV_VARS

The environment variables with the path to the user’s editor in the order they’ll be tried. These will be used when there is no Ravn::CLI.editor configured.

FALLBACK_EDITOR_COMMAND

The editor to use if all else fails

PROGRESSBAR_FORMAT

The format of progress bars

RAVN_GIT_URL

The base git URL for Ravn projects

Public Class Methods

add_registered_subcommands()

Add the commands from the registered subcommand modules.

# File lib/ravn/cli.rb, line 185
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/ravn/cli.rb, line 855
def self::commands_from( subdir )
        $LOAD_PATH.map {|path| Pathname(path) }.each do |libdir|
                command_dir = libdir.expand_path + subdir
                load_commands( command_dir )
        end
end
load_commands( path )

Custom command loader. The default one is silly.

# File lib/ravn/cli.rb, line 845
def self::load_commands( path )
        self.log.debug "Load commands from %s" % [ path ]
        Pathname.glob( path + '*.rb' ).each do |rbfile|
                self.log.debug "  loading %s..." % [ rbfile ]
                require( rbfile )
        end
end
load_config( global={} )

Load the config file using either Ravn’s config-loader if available, or fall back to DEFAULT_CONFIG_FILE

# File lib/ravn/cli.rb, line 259
def self::load_config( global={} )
        Ravn.load_config( global[:c] )

        self.projects_dir = global[:p] if global[:p]

        # Set up the logging formatter
        Loggability.format_with( :color ) if $stdout.tty?
end
pastel()

Return the Pastel colorizer.

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

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

# File lib/ravn/cli.rb, line 205
def self::prompt
        @prompt ||= TTY::Prompt.new
end
register_subcommands( mod )

Add the specified +mod+ule containing subcommands to the ‘ravn’ command.

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

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

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

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

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

Overridden – Add registered subcommands immediately before running.

# File lib/ravn/cli.rb, line 169
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/ravn/cli.rb, line 218
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/ravn/cli.rb, line 270
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

        $COLOR = global[ :color ]
end
setup_pastel_aliases()

Setup pastel color aliases

# File lib/ravn/cli.rb, line 238
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( :warn, :bold, :magenta )
        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/ravn/cli.rb, line 165
singleton_attr_accessor :subcommand_modules