Class: Inversion::CLI
- Inherits:
-
Object
- Object
- Inversion::CLI
- Extended by:
- GLI::App, MethodUtilities, Loggability
- Defined in:
- lib/inversion/cli.rb
Overview
Command class for the ‘inversion’ command-line tool.
Defined Under Namespace
Modules: ApiCommand, Subcommand, TagTokensCommand, TreeCommand
Class Method Summary collapse
-
.add_registered_subcommands ⇒ Object
Add the commands from the registered subcommand modules.
-
.commands_from(subdir) ⇒ Object
Load commands from any files in the specified directory relative to LOAD_PATHs.
-
.pastel ⇒ Object
Return the Pastel colorizer.
-
.prompt ⇒ Object
Return the TTY prompt used by the command to communicate with the user.
-
.register_subcommands(mod) ⇒ Object
Add the specified ‘mod`ule containing subcommands to the ’inversion’ command.
-
.require_additional_libs(requires) ⇒ Object
Load any additional Ruby libraries given with the -r global option.
-
.reset_prompt ⇒ Object
Discard the existing HighLine prompt object if one existed.
-
.run ⇒ Object
Overridden – Add registered subcommands immediately before running.
-
.set_logging_level(level = nil) ⇒ Object
Set the global logging ‘level` if it’s defined.
-
.setup_output(global) ⇒ Object
Set up the output levels and globals based on the associated ‘global` options.
-
.setup_pastel_aliases ⇒ Object
Setup pastel color aliases.
Instance Method Summary collapse
-
#subcommand_modules ⇒ Object
Registered subcommand modules.
Methods included from MethodUtilities
singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer
Class Method Details
.add_registered_subcommands ⇒ Object
Add the commands from the registered subcommand modules.
139 140 141 142 143 144 145 146 147 |
# File 'lib/inversion/cli.rb', line 139 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) ⇒ Object
Load commands from any files in the specified directory relative to LOAD_PATHs
396 397 398 399 400 401 |
# File 'lib/inversion/cli.rb', line 396 def self::commands_from( subdir ) Gem.find_latest_files( File.join(subdir, '*.rb') ).each do |rbfile| self.log.debug " loading %s..." % [ rbfile ] require( rbfile ) end end |
.pastel ⇒ Object
Return the Pastel colorizer.
152 153 154 |
# File 'lib/inversion/cli.rb', line 152 def self::pastel @pastel ||= Pastel.new( enabled: $stdout.tty? ) end |
.prompt ⇒ Object
Return the TTY prompt used by the command to communicate with the user.
159 160 161 |
# File 'lib/inversion/cli.rb', line 159 def self::prompt @prompt ||= TTY::Prompt.new( output: $stderr ) end |
.register_subcommands(mod) ⇒ Object
Add the specified ‘mod`ule containing subcommands to the ’inversion’ command.
130 131 132 133 134 135 |
# File 'lib/inversion/cli.rb', line 130 def self::register_subcommands( mod ) self.subcommand_modules ||= [] self.subcommand_modules.push( mod ) mod.extend( GLI::DSL, GLI::AppSupport, Loggability ) mod.log_to( :inversion ) end |
.require_additional_libs(requires) ⇒ Object
Load any additional Ruby libraries given with the -r global option.
182 183 184 185 186 187 |
# File 'lib/inversion/cli.rb', line 182 def self::require_additional_libs( requires) requires.each do |path| path = "inversion/#{path}" unless path.start_with?( 'inversion/' ) require( path ) end end |
.reset_prompt ⇒ Object
Discard the existing HighLine prompt object if one existed. Mostly useful for testing.
166 167 168 |
# File 'lib/inversion/cli.rb', line 166 def self::reset_prompt @prompt = nil end |
.run ⇒ Object
Overridden – Add registered subcommands immediately before running.
123 124 125 126 |
# File 'lib/inversion/cli.rb', line 123 def self::run( * ) self.add_registered_subcommands super end |
.set_logging_level(level = nil) ⇒ Object
Set the global logging ‘level` if it’s defined.
172 173 174 175 176 177 178 |
# File 'lib/inversion/cli.rb', line 172 def self::set_logging_level( level=nil ) if level Loggability.level = level.to_sym else Loggability.level = :fatal end end |
.setup_output(global) ⇒ Object
Set up the output levels and globals based on the associated ‘global` options.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/inversion/cli.rb', line 211 def self::setup_output( global ) if global[:verbose] $VERBOSE = true Loggability.level = :info end if global[:debug] $DEBUG = true Loggability.level = :debug end if global[:loglevel] Loggability.level = global[:loglevel] end end |
.setup_pastel_aliases ⇒ Object
Setup pastel color aliases
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/inversion/cli.rb', line 192 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( :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 |
Instance Method Details
#subcommand_modules ⇒ Object
Registered subcommand modules
119 |
# File 'lib/inversion/cli.rb', line 119 singleton_attr_accessor :subcommand_modules |