Module: Arborist::CLI
- Extended by:
- MethodUtilities, GLI::App, Loggability
- Defined in:
- lib/arborist/cli.rb
Overview
The command-line interface to Arborist.
Defined Under Namespace
Modules: Ack, Client, Config, Reset, RunOnce, Start, Subcommand, Summary, Tree, Watch
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.
-
.load_config(global = {}) ⇒ Object
Load the config file using either arborist-base’s config-loader if available, or fall back to DEFAULT_CONFIG_FILE.
-
.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 module containing subcommands to the ‘arborist’ 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
attr_predicate, attr_predicate_accessor, dsl_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader
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/arborist/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
390 391 392 393 394 395 |
# File 'lib/arborist/cli.rb', line 390 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 |
.load_config(global = {}) ⇒ Object
Load the config file using either arborist-base’s config-loader if available, or fall back to DEFAULT_CONFIG_FILE
213 214 215 216 217 218 |
# File 'lib/arborist/cli.rb', line 213 def self::load_config( global={} ) Arborist.load_config( global[:c] ) # Set up the logging formatter Loggability.format_with( :color ) if $stdout.tty? end |
.pastel ⇒ Object
Return the Pastel colorizer.
152 153 154 |
# File 'lib/arborist/cli.rb', line 152 def self::pastel @pastel ||= Pastel.new( enabled: $stdout.tty? && $COLOR ) end |
.prompt ⇒ Object
Return the TTY prompt used by the command to communicate with the user.
159 160 161 |
# File 'lib/arborist/cli.rb', line 159 def self::prompt @prompt ||= TTY::Prompt.new end |
.register_subcommands(mod) ⇒ Object
Add the specified module containing subcommands to the ‘arborist’ command.
130 131 132 133 134 135 |
# File 'lib/arborist/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( :arborist ) 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/arborist/cli.rb', line 182 def self::require_additional_libs( requires) requires.each do |path| path = "arborist/#{path}" unless path.start_with?( 'arborist/' ) 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/arborist/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/arborist/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/arborist/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.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/arborist/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 $COLOR = global[ :color ] 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 208 |
# File 'lib/arborist/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( :warn, :bold, :magenta ) 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/arborist/cli.rb', line 119 singleton_attr_accessor :subcommand_modules |