Code Coverage
 
Lines
Covered
44.29% covered (danger)
44.29%
31 / 70
1
module TheFox
1
module Timr
1
module Command
# Stop the current running [Track](rdoc-ref:TheFox::Timr::Model::Track).
#
# Man page: [timr-stop(1)](../../../../man/timr-stop.1.html)
1
class StopCommand < BasicCommand
1
include TheFox::Timr::Helper
1
include TheFox::Timr::Error
# Path to man page.
1
MAN_PATH = 'man/timr-stop.1'
1
def initialize(argv = Array.new)
8
super()
8
@help_opt = false
8
@start_date_opt = nil
8
@start_time_opt = nil
8
@end_date_opt = nil
8
@end_time_opt = nil
8
@message_opt = nil
8
@edit_opt = false
8
loop_c = 0 # Limit the loop.
8
while loop_c < 1024 && argv.length > 0
7
loop_c += 1
7
arg = argv.shift
7
case arg
when '-h', '--help'
1
@help_opt = true
when '--sd', '--start-date'
1
@start_date_opt = argv.shift
when '--st', '--start-time'
1
@start_time_opt = argv.shift
when '--ed', '--end-date', '-d', '--date'
1
@end_date_opt = argv.shift
when '--et', '--end-time', '-t', '--time'
1
@end_time_opt = argv.shift
when '-m', '--message'
1
@message_opt = argv.shift
when '--edit'
0
@edit_opt = true
else
1
raise StopCommandError, "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
track = @timr.stack.current_track
0
if track
0
task = track.task
0
if task
0
run_edit(task.id, track.id)
end
end
0
options = {
:start_date => @start_date_opt,
:start_time => @start_time_opt,
:end_date => @end_date_opt,
:end_time => @end_time_opt,
:message => @message_opt,
}
0
track = @timr.stop(options)
0
unless track
0
puts 'No running Track to stop.'
0
return
end
0
puts track.to_compact_str
0
puts @timr.stack
end
1
private
1
def help
0
puts 'usage: timr stop [-m|--message <message>] [--edit]'
0
puts ' [[--start-date <date>] --start-time <time>]'
0
puts ' [-d|--date <date>] [-t|--time <time>]'
0
puts ' or: timr stop [-h|--help]'
0
puts
0
puts 'Track Options'
0
puts ' -m, --message <message> Track Message. What have you done? This will'
0
puts ' overwrite the start message. See --edit option.'
0
puts ' --edit Edit Track Message.'
0
puts ' EDITOR environment variable must be set.'
0
puts
0
puts ' --sd, --start-date <date> Overwrite the Start date.'
0
puts ' --st, --start-time <time> Overwrite the Start time.'
0
puts
0
puts ' --ed, --end-date <date> Track End Date. Default: today'
0
puts ' --et, --end-time <time> Track End Time. Default: now'
0
puts
0
puts ' -d, --date <date> --end-date alias.'
0
puts ' -t, --time <time> --end-time alias.'
0
puts
0
HelpCommand.print_datetime_help
0
puts
end
end # class StopCommand
end # module Command
end # module Timr
end # module TheFox