Class: BuildTool::Commands::History

Inherits:
Standard show all
Defined in:
lib/build-tool/commands/history.rb

Overview

BuildCommand

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from Standard

#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to

Methods inherited from Base

#<=>, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #quiet, #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

This class inherits a constructor from BuildTool::Commands::Standard

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/build-tool/commands/history.rb', line 46

def applicable?
    BuildTool::Application.instance.has_recipe?
end

#do_execute(args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/build-tool/commands/history.rb', line 50

def do_execute( args )
    case args.length

    when 0
        return show_command_history
    when 1
        return show_detailed_command_history( args[0] ) if args[0] =~ /^[0-9]+/
        case args[0][0,1]
        when '+'
            return show_detailed_command_history( args[0] )
        else
            return show_module_history( args[0] )
        end
    else
        return usage( "To many arguments" )
    end
end

#initialize_optionsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/build-tool/commands/history.rb', line 23

def initialize_options
    options.banner = "Usage: #{self.fullname} [OPTIONS]... [NUMBER|+NUMBER|MODULE]"
    options.separator( "" )
    options.separator( "Options" )

    # Show detailed history. Add start time, duration and success/failure
    @long = false
    options.on( "-l", "--long", "Use long list format." ) { |t|
        @long = true
        }
    super

    @lines = nil
    options.on( "-n", "--number COUNT", "Number of lines to show." ) { |n|
        if not /^[0-9]+$/.match( n )
            raise OptionParser::ParseError.new( 'value "%s" is not a number' % n )
        end

        @lines = n.to_i()
        }
    super
end

#show_command(cmd) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/build-tool/commands/history.rb', line 68

def show_command( cmd )
    if @long
        info( " %04d %s # %s [%s]" % [ cmd.id, cmd.started_at.strftime("%x %X"), cmd.command, cmd.state_str ] )
    else
        info( " %04d %s [%s]" % [ cmd.id, cmd.command, cmd.state_str ] )
    end
end

#show_command_historyObject



76
77
78
79
80
81
82
83
# File 'lib/build-tool/commands/history.rb', line 76

def show_command_history
    # *TODO* Make the number of printed command configurable
    BuildTool::History::CommandLog.last(@lines || 50 ).reverse().each do |cmd|
        show_command cmd
    end

    return 0
end

#show_detailed_command_history(id) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/build-tool/commands/history.rb', line 106

def show_detailed_command_history( id )
    if id[0,1] == '+'
        cmd = BuildTool::History::CommandLog.most_recent( id )
        return 0 if cmd.nil?
    else
        cmd = BuildTool::History::CommandLog.find( id )
        if cmd.nil?
            error( "No entry with id #{id.to_i} found in history!")
            return -1
        end
    end
    show_command( cmd )

    last_module=""
    cmd.module_logs.each do |e|
        if e.module != last_module
            info( blue { "\t#{e.module.name}" } )
            last_module = e.module
        end
        info( "\t\t %s %s (%s) [%s]" % [ e.duration, e.event, e.logfile, e.state_str ] )
    end

    return 0
end

#show_module_history(modname) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/build-tool/commands/history.rb', line 85

def show_module_history( modname )
    mod = complete_module( modname )
    if mod.nil?
        return usage( "Unknown module #{modname}" )
    end

    BuildTool::History::CommandLog.last_by_module( mod.name, @lines || 3 ).reverse.each do |cmd|
        show_command( cmd )

        last_module=""
        cmd.module_logs.where( :module => mod.name ).each do |e|
            if e.module != last_module
                info( blue { "\t#{e.module.name}" } )
                last_module = e.module
            end
            info( "\t\t %s %s (%s) [%s]" % [ e.duration, e.event, e.logfile, e.state_str ] )
        end
    end
    return 0
end