Strelka::

CLI

module
Included Modules
Strelka::Constants
Extended With
Strelka::MethodUtilities
Strelka::CLI::Loggability
GLI::App
GLI::App

The command-line interface to Strelka.

Constants

COLOR_SCHEME

Make a HighLine color scheme

Public Class Methods

anchor
add_registered_subcommands()

Add the commands from the registered subcommand modules.

# File lib/strelka/cli.rb, line 154
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
anchor
commands_from( subdir )

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

# File lib/strelka/cli.rb, line 381
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
anchor
install_highline_colorscheme()

Install the color scheme used by HighLine

# File lib/strelka/cli.rb, line 196
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
anchor
load_commands( path )

Custom command loader. The default one is silly.

# File lib/strelka/cli.rb, line 371
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
anchor
load_config( global={} )

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 212
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
anchor
outfile()

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

# File lib/strelka/cli.rb, line 174
def self::outfile
        return @outfile
end
anchor
prompt()

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

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

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 365
def self::register( &block )
        self.instance_eval( &block )
end
anchor
register_subcommands( mod )

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

# File lib/strelka/cli.rb, line 145
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
anchor
require_additional_libs( requires)

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

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

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

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

Overridden – Add registered subcommands immediately before running.

# File lib/strelka/cli.rb, line 138
def self::run( * )
        self.add_registered_subcommands
        super
end
anchor
setup_output( global )

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

# File lib/strelka/cli.rb, line 221
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

anchor
outfile()

The IO opened to the output file

# File lib/strelka/cli.rb, line 134
singleton_attr_accessor :outfile
anchor
subcommand_modules()

Registered subcommand modules

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