Code Coverage
 
Lines
Covered
69.23% covered (warning)
69.23%
45 / 65
1
module TheFox
1
module Timr
1
module Command
# Push a new [Track](rdoc-ref:TheFox::Timr::Model::Track) to the [Stack](rdoc-ref:TheFox::Timr::Model::Stack).
#
# Man page: [timr-push(1)](../../../../man/timr-push.1.html)
1
class PushCommand < BasicCommand
1
include TheFox::Timr::Helper
1
include TheFox::Timr::Error
# Path to man page.
1
MAN_PATH = 'man/timr-push.1'
1
def initialize(argv = Array.new)
10
super()
10
@help_opt = false
10
@foreign_id_opt = nil
10
@name_opt = nil
10
@description_opt = nil
10
@estimation_opt = nil
10
@hourly_rate_opt = nil
10
@has_flat_rate_opt = nil
10
@date_opt = nil
10
@time_opt = nil
10
@message_opt = nil
10
@edit_opt = false
10
@task_id_opt = nil
10
@track_id_opt = nil
10
@id_opts = Array.new
10
loop_c = 0 # Limit the loop.
10
while loop_c < 1024 && argv.length > 0
12
loop_c += 1
12
arg = argv.shift
12
case arg
when '-h', '--help'
1
@help_opt = true
when '--id'
0
@foreign_id_opt = argv.shift.strip
when '-n', '--name'
1
@name_opt = argv.shift
when '--desc', '--description'
1
@description_opt = argv.shift
when '-e', '--est', '--estimation'
0
@estimation_opt = argv.shift
when '-r', '--hourly-rate'
0
@hourly_rate_opt = argv.shift
when '--fr', '--flat', '--flat-rate'
0
@has_flat_rate_opt = true
when '-d', '--date'
1
@date_opt = argv.shift
when '-t', '--time'
1
@time_opt = argv.shift
when '-m', '--message'
1
@message_opt = argv.shift
when '--edit'
0
@edit_opt = true
else
6
if arg[0] == '-'
1
raise PushCommandError, "Unknown argument '#{arg}'. See 'timr push --help'."
else
5
if @id_opts.length < 2
4
@id_opts << arg
else
1
raise PushCommandError, "Unknown argument '#{arg}'. See 'timr push --help'."
end
end
end
end
8
check_foreign_id(@foreign_id_opt)
8
if @id_opts.length
8
@task_id_opt, @track_id_opt = @id_opts
end
end
# See BasicCommand#run.
1
def run
0
if @help_opt
0
help
0
return
end
0
@timr = Timr.new(@cwd)
0
run_edit
0
options = {
:foreign_id => @foreign_id_opt,
:name => @name_opt,
:description => @description_opt,
:estimation => @estimation_opt,
:hourly_rate => @hourly_rate_opt,
:has_flat_rate => @has_flat_rate_opt,
:date => @date_opt,
:time => @time_opt,
:message => @message_opt,
:task_id => @task_id_opt,
:track_id => @track_id_opt,
}
0
track = @timr.push(options)
0
unless track
0
raise TrackError, 'Could not start a new Track.'
end
0
puts '--- PUSHED ---'
0
puts track.to_compact_str
0
puts @timr.stack
end
1
private
1
def help
0
start_command = StartCommand.new(['--help'])
0
start_command.run
0
start_command.shutdown
end
end # class PushCommand
end # module Command
end # module Timr
end # module TheFox