module Strelka::CLI::Subcommand
Convenience module for subcommand registration syntax sugar.
Public Class Methods
extended( mod )
click to toggle source
Extension callback – register the extending object as a subcommand.
# File lib/strelka/cli.rb, line 278 def self::extended( mod ) Strelka::CLI.log.debug "Registering subcommands from %p" % [ mod ] Strelka::CLI.register_subcommands( mod ) end
Public Instance Methods
display_table( rows )
click to toggle source
Output a table with the given rows
.
# File lib/strelka/cli.rb, line 326 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
error_string( string )
click to toggle source
Return the specified string
in the 'error' ANSI color.
# File lib/strelka/cli.rb, line 320 def error_string( string ) return hl( string ).color( :error ) end
headline_string( string )
click to toggle source
Return the specified string
in the 'headline' ANSI color.
# File lib/strelka/cli.rb, line 302 def headline_string( string ) return hl( string ).color( :headline ) end
highlight_string( string )
click to toggle source
Return the specified string
in the 'highlight' ANSI color.
# File lib/strelka/cli.rb, line 308 def highlight_string( string ) return hl( string ).color( :highlight ) end
hl( text )
click to toggle source
Return the specified text
as a Highline::String for convenient formatting, color, etc.
# File lib/strelka/cli.rb, line 296 def hl( text ) return HighLine::String.new( text.to_s ) end
prompt()
click to toggle source
Get the prompt (a Highline object)
# File lib/strelka/cli.rb, line 289 def prompt return Strelka::CLI.prompt end
success_string( string )
click to toggle source
Return the specified string
in the 'success' ANSI color.
# File lib/strelka/cli.rb, line 314 def success_string( string ) return hl( string ).color( :success ) end
unless_dryrun( description, return_value=true ) { || ... }
click to toggle source
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 351 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
visible_chars( string )
click to toggle source
Return the count of visible (i.e., non-control) characters in the given string
.
# File lib/strelka/cli.rb, line 343 def visible_chars( string ) return string.to_s.gsub(/\e\[.*?m/, '').scan( /\P{Cntrl}/ ).size end