Code Coverage
 
Lines
Covered
48.96% covered (danger)
48.96%
47 / 96
1
require 'tempfile'
1
module TheFox
1
module Timr
1
module Command
# Start a new [Track](rdoc-ref:TheFox::Timr::Model::Track).
#
# Man page: [timr-start(1)](../../../../man/timr-start.1.html)
1
class StartCommand < BasicCommand
1
include TheFox::Timr::Model
1
include TheFox::Timr::Helper
1
include TheFox::Timr::Error
# Path to man page.
1
MAN_PATH = 'man/timr-start.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 StartCommandError, "Unknown argument '#{arg}'. See 'timr start --help'."
else
5
if @id_opts.length < 2
4
@id_opts << arg
else
1
raise StartCommandError, "Unknown argument '#{arg}'. See 'timr start --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.start(options)
0
unless track
0
raise TrackError, 'Could not start a new Track.'
end
0
puts track.to_compact_str
0
puts @timr.stack
end
1
private
1
def help
0
puts 'usage: timr start [--id <str>]'
0
puts ' [-n|--name <name>] [--desc|--description <description>]'
0
puts ' [[-d|--date <date>] -t|--time <time>]'
0
puts ' [-m|--message <message>] [--edit] [--estimation <time>]'
0
puts ' [--hourly-rate <value>] [--flat-rate]'
0
puts ' [<task_id> [<track_id>]]'
0
puts ' or: timr start [-h|--help]'
0
puts
0
puts "Note: 'timr push' uses the same options."
0
puts
0
puts 'Task Options'
0
puts ' --id <str> Your ID to identify the Task.'
0
puts ' -n, --name <name> The name of the new Task.'
0
puts ' --desc, --description <str> Longer description of the new Task.'
0
puts ' -e, --est, --estimation <time> Task Estimation. See details below.'
0
puts ' -r, --hourly-rate <float> Set the Hourly Rate.'
0
puts ' --fr, --flat-rate, --flat Has Task a Flat Rate?'
0
puts
0
puts 'Track Options'
0
puts ' -m, --message <message> Track Message. What have you done?'
0
puts ' You can overwrite this on stop command.'
0
puts ' --edit Edit Track Message when providing <track_id>.'
0
puts ' EDITOR environment variable must be set.'
0
puts ' -d, --date <date> Track Start Date. Default: today'
0
puts ' -t, --time <time> Track Start Time. Default: now'
0
puts
0
puts 'Arguments'
0
HelpCommand.print_id_help
0
puts
0
HelpCommand.print_datetime_help
0
puts
0
HelpCommand.print_estimation_help
0
puts
end
end # class StartCommand
end # module Command
end # module Timr
end # module TheFox