module Strelka::CLI

The command-line interface to Strelka.

Constants

COLOR_SCHEME

Make a HighLine color scheme

Public Class Methods

add_registered_subcommands() click to toggle source

Add the commands from the registered subcommand modules.

# File lib/strelka/cli.rb, line 155
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/strelka/cli.rb, line 382
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
install_highline_colorscheme() click to toggle source

Install the color scheme used by HighLine

# File lib/strelka/cli.rb, line 197
def self::install_highline_colorscheme
        HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
                cs[:headline]   = [ :bold, :white, :on_black ]
                cs[:success]    = [ :green ]
                cs[:error]      = [ :bold, :red ]
                cs[:highlight]  = [ :bold, :yellow ]
                cs[:search_hit] = [ :black, :on_white ]
                cs[:prompt]     = [ :cyan ]
                cs[:even_row]   = [ :bold ]
                cs[:odd_row]    = [ :normal ]
        end
end
load_commands( path ) click to toggle source

Custom command loader. The default one is silly.

# File lib/strelka/cli.rb, line 372
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={} ) click to toggle source

Load the config file using either strelka-base's config-loader if available, or fall back to DEFAULT_CONFIG_FILE

# File lib/strelka/cli.rb, line 213
def self::load_config( global={} )
        Strelka.load_config( global.config ) if global.config

        # Set up the logging formatter
        Loggability.format_with( :color ) if $stdout.tty?
end
outfile() click to toggle source

If the command's output was redirected to a file, return the open File object for it.

# File lib/strelka/cli.rb, line 175
def self::outfile
        return @outfile
end
prompt() click to toggle source

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

# File lib/strelka/cli.rb, line 168
def self::prompt
        @prompt ||= HighLine.new( $stdin, $stderr )
end
register( &block ) click to toggle source

Register one or more subcommands with the 'strelka' command shell. The given block will be evaluated in the context of Strelka::CLI.

# File lib/strelka/cli.rb, line 366
def self::register( &block )
        self.instance_eval( &block )
end
register_subcommands( mod ) click to toggle source

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

# File lib/strelka/cli.rb, line 146
def self::register_subcommands( mod )
        self.subcommand_modules ||= []
        self.subcommand_modules.push( mod )
        mod.extend( GLI::App, GLI::AppSupport, Strelka::Constants, Loggability )
        mod.log_to( :strelka )
end
require_additional_libs( requires) click to toggle source

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

# File lib/strelka/cli.rb, line 188
def self::require_additional_libs( requires)
        requires.each do |path|
                path = "strelka/#{path}" unless path.start_with?( 'strelka/' )
                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/strelka/cli.rb, line 182
def self::reset_prompt
        @prompt = nil
end
run( * ) click to toggle source

Overridden – Add registered subcommands immediately before running.

Calls superclass method
# File lib/strelka/cli.rb, line 139
def self::run( * )
        self.add_registered_subcommands
        super
end
setup_output( global ) click to toggle source

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

# File lib/strelka/cli.rb, line 222
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 (( filename = global[:o] ))
                if filename.to_s == '-'
                        @prompt = HighLine.new( $stdin, $stdout )
                else
                        @outfile = filename.open( 'w', encoding: 'utf-8' )
                        HighLine.use_color = false
                        @prompt = HighLine.new( $stdin, @outfile )
                end
        end
end

Public Instance Methods

outfile() click to toggle source

The IO opened to the output file

# File lib/strelka/cli.rb, line 135
singleton_attr_accessor :outfile
subcommand_modules() click to toggle source

Registered subcommand modules

# File lib/strelka/cli.rb, line 131
singleton_attr_accessor :subcommand_modules