Class: TheFox::Timr::Command::StartCommand

Inherits:
BasicCommand show all
Includes:
Error, Helper, Model
Defined in:
lib/timr/command/start_command.rb

Overview

Start a new [Track](TheFox::Timr::Model::Track).

Man page: [timr-start(1)](../../../../man/timr-start.1.html)

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-start.1'

Instance Attribute Summary

Attributes inherited from BasicCommand

#cwd

Instance Method Summary collapse

Methods inherited from BasicCommand

create_command_from_argv, get_command_class_by_name, #shutdown

Constructor Details

#initialize(argv = Array.new) ⇒ StartCommand

Returns a new instance of StartCommand.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/timr/command/start_command.rb', line 20

def initialize(argv = Array.new)
	super()
	
	@help_opt = false
	
	@foreign_id_opt = nil
	@name_opt = nil
	@description_opt = nil
	@estimation_opt = nil
	
	@hourly_rate_opt = nil
	@has_flat_rate_opt = nil
	
	@date_opt = nil
	@time_opt = nil
	@message_opt = nil
	@edit_opt = false
	
	@task_id_opt = nil
	@track_id_opt = nil
	@id_opts = Array.new
	
	loop_c = 0 # Limit the loop.
	while loop_c < 1024 && argv.length > 0
		loop_c += 1
		arg = argv.shift
		
		case arg
		when '-h', '--help'
			@help_opt = true
		
		when '--id'
			@foreign_id_opt = argv.shift.strip
		when '-n', '--name'
			@name_opt = argv.shift
		when '--desc', '--description'
			@description_opt = argv.shift
		when '-e', '--est', '--estimation'
			@estimation_opt = argv.shift
		
		when '-r', '--hourly-rate'
			@hourly_rate_opt = argv.shift
		when '--fr', '--flat', '--flat-rate'
			@has_flat_rate_opt = true
		
		when '-d', '--date'
			@date_opt = argv.shift
		when '-t', '--time'
			@time_opt = argv.shift
		when '-m', '--message'
			@message_opt = argv.shift
		when '--edit'
			@edit_opt = true
		else
			if arg[0] == '-'
				raise StartCommandError, "Unknown argument '#{arg}'. See 'timr start --help'."
			else
				if @id_opts.length < 2
					@id_opts << arg
				else
					raise StartCommandError, "Unknown argument '#{arg}'. See 'timr start --help'."
				end
			end
		end
	end
	
	check_foreign_id(@foreign_id_opt)
	
	if @id_opts.length
		@task_id_opt, @track_id_opt = @id_opts
	end
end

Instance Method Details

#runObject

See BasicCommand#run.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/timr/command/start_command.rb', line 94

def run
	if @help_opt
		help
		return
	end
	
	@timr = Timr.new(@cwd)
	
	run_edit
	
	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,
	}
	
	track = @timr.start(options)
	unless track
		raise TrackError, 'Could not start a new Track.'
	end
	
	puts track.to_compact_str
	puts @timr.stack
end