Strelka::CLI::

Subcommand

module

Convenience module for subcommand registration syntax sugar.

Public Class Methods

anchor
extended( mod )

Extension callback – register the extending object as a subcommand.

# File lib/strelka/cli.rb, line 277
def self::extended( mod )
        Strelka::CLI.log.debug "Registering subcommands from %p" % [ mod ]
        Strelka::CLI.register_subcommands( mod )
end

Public Instance Methods

anchor
display_table( rows )

Output a table with the given rows.

# File lib/strelka/cli.rb, line 325
def display_table( rows )
        colwidths = rows.transpose.map do |colvals|
                colvals.map {|val| visible_chars(val) }.max
        end

        rows.each do |row|
                row_string = row.zip( colwidths ).inject( '' ) do |accum, (val, colsize)|
                        padding = ' ' * (colsize - visible_chars(val) + 2)
                        accum + val.to_s + padding
                end

                Strelka::CLI.prompt.say( row_string + "\n" )
        end
end
anchor
error_string( string )

Return the specified string in the 'error' ANSI color.

# File lib/strelka/cli.rb, line 319
def error_string( string )
        return hl( string ).color( :error )
end
anchor
headline_string( string )

Return the specified string in the 'headline' ANSI color.

# File lib/strelka/cli.rb, line 301
def headline_string( string )
        return hl( string ).color( :headline )
end
anchor
highlight_string( string )

Return the specified string in the 'highlight' ANSI color.

# File lib/strelka/cli.rb, line 307
def highlight_string( string )
        return hl( string ).color( :highlight )
end
anchor
hl( text )

Return the specified text as a Highline::String for convenient formatting, color, etc.

# File lib/strelka/cli.rb, line 295
def hl( text )
        return HighLine::String.new( text.to_s )
end
anchor
prompt()

Get the prompt (a Highline object)

# File lib/strelka/cli.rb, line 288
def prompt
        return Strelka::CLI.prompt
end
anchor
success_string( string )

Return the specified string in the 'success' ANSI color.

# File lib/strelka/cli.rb, line 313
def success_string( string )
        return hl( string ).color( :success )
end
anchor
unless_dry_run( description, return_value=true )
Alias for: unless_dryrun
anchor
unless_dryrun( description, return_value=true ) { || ... }

In dry-run mode, output the description instead of running the provided block and return the return_value. If dry-run mode is not enabled, yield to the block.

# File lib/strelka/cli.rb, line 350
def unless_dryrun( description, return_value=true )
        if $DRYRUN
                self.log.warn( "DRYRUN> #{description}" )
                return return_value
        else
                return yield
        end
end
Also aliased as: unless_dry_run
anchor
visible_chars( string )

Return the count of visible (i.e., non-control) characters in the given string.

# File lib/strelka/cli.rb, line 342
def visible_chars( string )
        return string.to_s.gsub(/\e\[.*?m/, '').scan( /\P{Cntrl}/ ).size
end