Code Coverage
 
Lines
Covered
40.48% covered (danger)
40.48%
34 / 84
1
module TheFox
1
module Timr
1
module Command
# This command pops the Top [Track](rdoc-ref:TheFox::Timr::Model::Track), makes a duplication
# of the next Track on the [Stack](rdoc-ref:TheFox::Timr::Model::Stack), pops the next,
# and pushes the duplication Track back on the Stack. There are at least 3 Tracks involved.
#
# Man page: [timr-pop(1)](../../../../man/timr-pop.1.html)
#
# ### Example
#
# Example Stack before pop:
#
# ```
# Track 1234 stopped
# Track 2345 stopped
# Track 3456 running
# ```
#
# Pop Execution
#
# 1. Make duplication of Track `3456` -> new Track `4567`.
# Because Track `3456` is the latest Track on the Stack. Sometimes call *Top Track*.
# 2. Pop Track `3456` from Stack.
# 3. Push new Track `4567` to Stack.
#
# Example Stack after pop:
#
# ```
# Track 1234 stopped
# Track 2345 stopped
# Track 4567 running
# ```
1
class PopCommand < BasicCommand
1
include TheFox::Timr::Helper
1
include TheFox::Timr::Error
# Path to man page.
1
MAN_PATH = 'man/timr-pop.1'
1
def initialize(argv = Array.new)
5
super()
5
@help_opt = false
5
@start_date_opt = nil
5
@start_time_opt = nil
5
@end_date_opt = nil
5
@end_time_opt = nil
5
@date_opt = nil
5
@time_opt = nil
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 '--sd', '--start-date'
0
@start_date_opt = argv.shift
when '--st', '--start-time'
0
@start_time_opt = argv.shift
when '--ed', '--end-date'
0
@end_date_opt = argv.shift
when '--et', '--end-time'
0
@end_time_opt = argv.shift
when '-d', '--date'
1
@date_opt = argv.shift
when '-t', '--time'
1
@time_opt = argv.shift
else
1
raise PopCommandError, "Unknown argument '#{arg}'. See 'timr pop --help'."
end
end
4
if @date_opt
1
@start_date_opt = @date_opt
1
@end_date_opt = @date_opt
end
4
if @time_opt
1
@start_time_opt = @time_opt
1
@end_time_opt = @time_opt
end
end
# See BasicCommand#run.
1
def run
0
if @help_opt
0
help
0
return
end
0
@timr = Timr.new(@cwd)
# Stop
0
options = {
:date => @end_date_opt,
:time => @end_time_opt,
}
0
track = @timr.stop(options)
0
unless track
0
puts 'No running Track to pop/stop.'
0
return
end
0
task = track.task
0
unless task
0
raise TrackError, "Track #{track.id} has no Task."
end
0
puts '--- POPED ---'
0
puts track.to_compact_str
0
puts
# Continue
0
options = {
:date => @start_date_opt,
:time => @start_time_opt,
}
0
track = @timr.continue(options)
0
unless track
0
puts 'No running Track left on Stack to continue.'
0
return
end
0
task = track.task
0
unless task
0
raise TrackError, "Track #{track.id} has no Task."
end
0
puts '--- CONTINUED ---'
0
puts track.to_compact_str
0
puts
0
puts @timr.stack
end
1
private
1
def help
0
puts 'usage: timr pop [--sd|--start-date <date>] [--st|--start-time <time>]'
0
puts ' [--ed|--end-date <date>] [--et|--end-time <time>]'
0
puts ' or: timr pop [-d|--date <date>] [-t|--time <time>]'
0
puts ' or: timr pop [-h|--help]'
0
puts
0
puts 'Track Options'
0
puts ' --sd, --start-date <date> Start Date for the next underlying Track.'
0
puts ' --st, --start-time <time> Start Time for the next underlying Track.'
0
puts
0
puts ' --ed, --end-date <date> End Date for the current running Track.'
0
puts ' --et, --end-time <time> End Time for the current running Track.'
0
puts
0
puts " -d, --date <date> Alias for"
0
puts " '--end-date <date> --start-date <date>'."
0
puts " -t, --time <time> Alias for"
0
puts " '--end-time <time> --start-time <time>'."
0
puts
0
HelpCommand.print_datetime_help
0
puts
end
end # class PopCommand
end # module Command
end # module Timr
end # module TheFox