Code Coverage
 
Lines
Covered
23.58% covered (danger)
23.58%
29 / 123
1
require 'thefox-ext'
1
module TheFox
1
module Timr
1
module Command
# Print [Stack](rdoc-ref:TheFox::Timr::Model::Stack) Status.
#
# Man page: [timr-status(1)](../../../../man/timr-status.1.html)
1
class StatusCommand < BasicCommand
1
include TheFox::Timr::Error
# Path to man page.
1
MAN_PATH = 'man/timr-status.1'
1
def initialize(argv = Array.new)
5
super()
5
@help_opt = false
5
@verbose_opt = false
5
@full_opt = false
5
@reverse_opt = false
5
loop_c = 0 # Limit the loop.
5
while loop_c < 1024 && argv.length > 0
4
loop_c += 1
4
arg = argv.shift
4
case arg
when '-h', '--help'
1
@help_opt = true
when '-v', '--verbose'
0
@verbose_opt = true
when '-f', '--full'
1
@full_opt = true
when '-r', '--reverse'
1
@reverse_opt = true
else
1
raise StatusCommandError, "Unknown argument '#{arg}'. See 'timr stop --help'."
end
end
end
# See BasicCommand#run.
1
def run
0
if @help_opt
0
help
0
return
end
0
@timr = Timr.new(@cwd)
0
if @full_opt
0
print_full_table
else
0
print_small_table
end
end
1
private
1
def print_small_table
0
headings = Array.new
0
headings << {:format => '%2s', :label => '##'}
0
headings << {:format => '%1s', :label => 'S'}
0
headings << {:format => '%-5s', :label => 'START', :padding_left => ' '}
0
headings << {:format => '%-5s', :label => 'END'}
0
headings << {:format => '%8s', :label => 'DUR', :padding_right => ' '}
0
if @verbose_opt
0
headings << {:format => '%7s', :label => 'EST', :padding_right => ' '}
0
headings << {:format => '%7s', :label => 'ETR', :padding_right => ' '}
0
headings << {:format => '%7s', :label => 'ETR%', :padding_right => ' '}
end
0
headings << {:format => '%-6s', :label => 'TASK', :padding_right => ' '}
0
headings << {:format => '%s', :label => 'TRACK'}
0
table_options = {
:headings => headings,
}
0
table = Table.new(table_options)
0
table_has_rows = false
0
track_c = 0
0
get_tracks.each do |track|
0
track_c += 1
0
table_has_rows = true
0
task = track.task
0
status = track.status.short_status
0
duration = track.duration
0
estimation_s = task.estimation_s
0
remaining_time_s = task.remaining_time_s
0
remaining_time_percent_s = task.remaining_time_percent_s
0
if track.begin_datetime
0
begin_datetime_s = track.begin_datetime_s({:format => '%H:%M'})
end
0
if track.end_datetime
0
end_datetime_s = track.end_datetime_s({:format => '%H:%M'})
end
0
row = Array.new
0
row << track_c
0
row << status
0
row << begin_datetime_s
0
row << end_datetime_s
0
row << duration.to_human
0
if @verbose_opt
0
row << estimation_s
0
row << remaining_time_s
0
row << remaining_time_percent_s
end
0
row << task.id_foreign_or_short
0
if @verbose_opt
0
row << '%s %s' % [track.short_id, track.title]
else
0
row << '%s %s' % [track.short_id, track.title(12)]
end
0
table << row
end
0
if table_has_rows
0
puts table
else
0
print_no_tracks
end
end
1
def print_full_table
0
tracks = Array.new
0
track_c = 0
0
get_tracks.each do |track|
0
track_c += 1
0
track_s = Array.new
0
track_s << '--- #%d ---' % [track_c]
0
track_s.concat(track.to_detailed_array)
0
tracks << track_s
end
0
if tracks.count > 0
0
puts tracks.map{ |track_s| track_s.join("\n") }.join("\n\n")
else
0
print_no_tracks
end
end
1
def print_no_tracks
0
puts 'There is no running Track.'
end
1
def get_tracks
0
if @reverse_opt
0
@timr.stack.tracks.reverse
else
0
@timr.stack.tracks
end
end
1
def help
0
puts 'usage: timr status [-h|--help] [-f|--full] [-r|--reverse]'
0
puts
0
puts 'Options'
0
puts ' -v, --verbose Show more columns in table view.'
0
puts ' -f, --full Show full status.'
0
puts ' -r, --reverse Reverse the list.'
0
puts
0
puts 'Columns'
0
puts ' S Status'
0
puts ' START Track Start Date'
0
puts ' END Track End Date'
0
puts ' DUR Track Duration'
0
puts ' EST Task Estimation'
0
puts ' ETR Task Estimated Time Remaining'
0
puts ' ETR% Task Estimated Time Remaining in percent.'
0
puts ' TASK Task ID'
0
puts ' TRACK Track ID and Title.'
0
puts
0
puts 'Status'
0
puts ' R Running'
0
puts ' S Stopped'
0
puts ' U Unknown'
0
puts ' - Not started yet.'
0
puts
end
end # class StatusCommand
end # module Command
end # module Timr
end # module TheFox