Class: TheFox::Timr::Command::PushCommand

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

Overview

Push a new [Track](TheFox::Timr::Model::Track) to the [Stack](TheFox::Timr::Model::Stack).

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

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-push.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) ⇒ PushCommand

Returns a new instance of PushCommand.



17
18
19
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
# File 'lib/timr/command/push_command.rb', line 17

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 PushCommandError, "Unknown argument '#{arg}'. See 'timr push --help'."
			else
				if @id_opts.length < 2
					@id_opts << arg
				else
					raise PushCommandError, "Unknown argument '#{arg}'. See 'timr push --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.



92
93
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
# File 'lib/timr/command/push_command.rb', line 92

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.push(options)
	unless track
		raise TrackError, 'Could not start a new Track.'
	end
	
	puts '--- PUSHED ---'
	puts track.to_compact_str
	puts @timr.stack
end