Class: BuildTool::Commands::History
- Inherits:
-
Standard
show all
- Includes:
- ANSI::Code
- Defined in:
- lib/build-tool/commands/history.rb
Overview
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, #complete_arguments, #complete_readline_1_8, #complete_readline_1_9, #configuration, #do_complete_1_8, #do_complete_1_9, #each_option, #execute, #fullname, #initialize, #log?, #say, #setup_command, #show_help, #skip_command, #summarize, #teardown_command, #usage
Methods included from HelpText
#cmdalias, #description, included, #long_description, #name
Instance Method Details
#do_execute(args) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/build-tool/commands/history.rb', line 45
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_options ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/build-tool/commands/history.rb', line 23
def initialize_options
@options.banner = "Usage: #{Pathname.new($0).basename} #{self.fullname} [NUMBER|+NUMBER|MODULE]"
@options.separator "Options:"
@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." ) { |t|
@lines = t.to_i
}
super
end
|
#show_command(cmd) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/build-tool/commands/history.rb', line 63
def show_command( cmd )
if @long
say " %04d %s # %s [%s]" % [ cmd.id, cmd.started_at.strftime("%x %X"), cmd.command, cmd.state_str ]
else
say " %04d %s [%s]" % [ cmd.id, cmd.command, cmd.state_str ]
end
end
|
#show_command_history ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/build-tool/commands/history.rb', line 71
def show_command_history
BuildTool::History::CommandLog.last(@lines || 50 ).reverse().each do |cmd|
show_command cmd
end
return 0
end
|
#show_detailed_command_history(id) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/build-tool/commands/history.rb', line 101
def show_detailed_command_history( id )
if id[0,1] == '+'
cmd = BuildTool::History::CommandLog.most_recent( id.to_i )
return 0 if cmd.nil?
else
cmd = BuildTool::History::CommandLog[id.to_i]
if cmd.nil?
logger.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
say blue { "\t#{e.module}" }
last_module = e.module
end
say "\t\t %s %s (%s) [%s]" % [ e.duration, e.event, e.logfile, e.state_str ]
end
return 0
end
|
#show_module_history(modname) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/build-tool/commands/history.rb', line 80
def show_module_history( modname )
mod = Application::instance.configuration.module( modname )
if mod.nil?
return usage( "Unknown module #{modname}" )
end
BuildTool::History::CommandLog.last_by_module( modname, @lines || 3 ).reverse.each do |cmd|
show_command( cmd )
last_module=""
cmd.module_logs_dataset.filter( :module => modname ).each do |e|
if e.module != last_module
say blue { "\t#{e.module}" }
last_module = e.module
end
say "\t\t %s %s (%s) [%s]" % [ e.duration, e.event, e.logfile, e.state_str ]
end
end
return 0
end
|