Class: BuildTool::Commands::Standard

Inherits:
Base
  • Object
show all
Defined in:
lib/build-tool/commands.rb

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from Base

#<=>, #applicable?, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #do_execute, #each_option, #error, #execute, #fullname, #info, #log?, #setup_command, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn

Methods included from HelpText

#cmdalias, #description, included, #long_description, #name

Constructor Details

#initialize(*args) ⇒ Standard

Returns a new instance of Standard.



356
357
358
359
360
# File 'lib/build-tool/commands.rb', line 356

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



386
387
388
# File 'lib/build-tool/commands.rb', line 386

def complete_module( name, include_templates = false )
    configuration.complete_module( name, include_templates, @all, @resume_from, @resume_after )
end

#complete_modules(name, include_templates = false) ⇒ Object

Gathers all modules currently known.

Parameters:

  • all

    Return template modules too.



382
383
384
# File 'lib/build-tool/commands.rb', line 382

def complete_modules( name, include_templates = false )
    configuration.complete_modules( name, include_templates, @all, @resume_from, @resume_after )
end

#initialize_optionsObject



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/build-tool/commands.rb', line 362

def initialize_options
    options.separator ''
    options.separator "Common options"

    options.on( "-v", "--verbose", "Enable verbose output" ) do
        Logging.appenders['stdout'].level = [ Logging.appenders['stdout'].level - 1, 0 ].max()
    end

    options.on( nil, "--dry-run", "Enable dry run." ) do
        $noop = true
    end

    options.on( "-h", "--help", "Show this help text" ) do
        show_help
    end
end

#log_directoryObject

On demand initialization



424
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
# File 'lib/build-tool/commands.rb', line 424

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



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
415
416
417
418
419
420
421
# File 'lib/build-tool/commands.rb', line 390

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
        dirname += 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
        error( "User Interrupt!" )
    rescue BuildTool::Error => e
        error( "#{e.message}" )
        got_exception = true
        raise e
    rescue Exception => e
        error( "#{e.class}:#{e.message}" )
        got_exception = true
        raise e
    ensure
        Logging.logger['root'].remove_appenders( fname )
        info( "More information in #{dirname}/#{fname}" ) if got_exception
    end
end