Class: BuildTool::Commands::Standard
- Defined in:
- lib/build-tool/commands.rb
Direct Known Subclasses
Environments::List, Environments::Set, Files, Help, History, Info, Lsfeatures, ModuleBasedCommand, Modules::List, Modules::Shell, Recipes::Add, Recipes::Incoming, Recipes::Info, Recipes::Install, Recipes::List
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #complete_module(name, include_templates = false) ⇒ Object
-
#complete_modules(name, include_templates = false) ⇒ Object
Gathers all modules currently known.
-
#initialize(*args) ⇒ Standard
constructor
A new instance of Standard.
- #initialize_options ⇒ Object
-
#log_directory ⇒ Object
On demand initialization.
- #while_logging_to(dir, fname, level, &block) ⇒ Object
Methods inherited from Base
#<=>, #applicable?, #cleanup_after_vcs_access, #complete, #complete_arguments, #complete_readline_1_8, #complete_readline_1_9, #configuration, #do_complete_1_8, #do_complete_1_9, #do_execute, #each_option, #execute, #fullname, #log?, #say, #setup_command, #show_help, #skip_command, #summarize, #teardown_command, #usage
Methods included from HelpText
#cmdalias, #description, included, #long_description, #name
Constructor Details
#initialize(*args) ⇒ Standard
Returns a new instance of Standard.
344 345 346 347 348 |
# File 'lib/build-tool/commands.rb', line 344 def initialize( *args ) # Only used by child classes but needed for complete_modules @all = false super( *args ) end |
Instance Method Details
#complete_module(name, include_templates = false) ⇒ Object
416 417 418 419 420 421 422 423 |
# File 'lib/build-tool/commands.rb', line 416 def complete_module( name, include_templates = false ) modules = complete_modules( name, include_templates ) case modules.size when 0 then return nil when 1 then return modules[0] else raise UsageError, "#{name} is ambiguous. Please be more specific" end end |
#complete_modules(name, include_templates = false) ⇒ Object
Gathers all modules currently known.
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/build-tool/commands.rb', line 371 def complete_modules( name, include_templates = false ) res = [] found = false should_be_unique = false configuration.modules.each do |mod| next if ( !include_templates and mod.is_template? ) # We match on the following conditions: # 1. name = mod.name # 2. name/ matches beginning of mod.name # 3. name equals last part of mod.name (behind /) and is unique if name.end_with?('/') and ( mod.name.index "/#{name}" or mod.name.start_with? name ) found = true # Now check if it is active. next if !( mod.active? || @all ) res << mod elsif mod.name == name found = true should_be_unique = true # Now check if it is active. next if !( mod.active? || @all ) res << mod elsif mod.name.end_with?( "/#{name}" ) found = true should_be_unique = true # Now check if it is active. next if !( mod.active? || @all ) res << mod end end # Raise an error if the module was not found if !found raise UsageError, "Unknown module/package #{name}" end # Raise an error if the result should be unique but is not. if should_be_unique and res.size > 1 raise UsageError, "#{name} is ambiguos. Please be more specific." end # Give a warning if all modules where logger.warn "All modules for #{name} are inactive! Will ignore it." if res.empty? return res end |
#initialize_options ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/build-tool/commands.rb', line 350 def .separator "Common options" .on( "-v", "--verbose", "Enable verbose output" ) do Logging.appenders['stdout'].level = [ Logging.appenders['stdout'].level-1, 0 ].max Logging.logger['MJ::Logging::LoggerAdapter'].level = [ Logging.logger['MJ::Logging::LoggerAdapter'].level - 1, 0 ].max end .on( nil, "--dry-run", "Enable dry run." ) do $noop = true end .on( "-h", "--help", "Show this help text" ) do show_help end end |
#log_directory ⇒ Object
On demand initialization
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/build-tool/commands.rb', line 455 def log_directory return @log_directory if @log_directory # Get the root logfile directory logdir = configuration.log_directory # Try to find the next log directory for today. i = -1 begin @log_directory = logdir.join( "#{Date.today.to_s}-%02d" % i+=1 ) end until !@log_directory.exist? # If noop is active we are finished return @log_directory if $noop # Ensure the base log directory exists. if !File.exist? "#{logdir}" FileUtils.mkdir_p "#{logdir}" end # Create the latest symbolic link FileUtils.mkdir_p( @log_directory.to_s ) FileUtils.rm_f( "#{logdir}/latest" ) FileUtils.ln_sf( @log_directory.to_s, "#{logdir}/latest" ) @log_directory end |
#while_logging_to(dir, fname, level, &block) ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/build-tool/commands.rb', line 425 def while_logging_to( dir, fname, level, &block ) got_exception = false # Only create a logfile if we do real work if log? dirname = log_directory.to_s dirname = "#{log_directory.to_s}/#{dir}" if dir FileUtils.mkdir_p( dirname ) Logging.logger['root'].add_appenders( Logging.appenders.file( fname, :filename => dirname + '/' + fname, :layout => Logging::Layouts::Pattern.new( :pattern => '%m\n' ), :level => level )) end begin yield rescue Interrupt => e logger.error "User Interrupt!" rescue Exception => e logger.error "#{e.class}:#{e.}" got_exception = true raise e ensure Logging.logger['root'].remove_appenders( fname ) logger.info("More information in #{dirname}/#{fname}") if got_exception end end |