Class: TheFox::Timr::Command::StopCommand

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

Overview

Stop the current running [Track](TheFox::Timr::Model::Track).

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

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-stop.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) ⇒ StopCommand

Returns a new instance of StopCommand.



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

def initialize(argv = Array.new)
  super()
  
  @help_opt = false
  
  @start_date_opt = nil
  @start_time_opt = nil
  @end_date_opt = nil
  @end_time_opt = nil
  
  @message_opt = nil
  @edit_opt = false
  
  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 '--sd', '--start-date'
      @start_date_opt = argv.shift
    when '--st', '--start-time'
      @start_time_opt = argv.shift
    
    when '--ed', '--end-date', '-d', '--date'
      @end_date_opt = argv.shift
    when '--et', '--end-time', '-t', '--time'
      @end_time_opt = argv.shift
    
    when '-m', '--message'
      @message_opt = argv.shift
    when '--edit'
      @edit_opt = true
    else
      raise StopCommandError, "Unknown argument '#{arg}'. See 'timr stop --help'."
    end
  end
end

Instance Method Details

#runObject

See BasicCommand#run.



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

def run
  if @help_opt
    help
    return
  end
  
  @timr = Timr.new(@cwd)
  
  track = @timr.stack.current_track
  if track
    task = track.task
    if task
      run_edit(task.id, track.id)
    end
  end
  
  options = {
    :start_date => @start_date_opt,
    :start_time => @start_time_opt,
    
    :end_date => @end_date_opt,
    :end_time => @end_time_opt,
    
    :message => @message_opt,
  }
  
  track = @timr.stop(options)
  unless track
    puts 'No running Track to stop.'
    return
  end
  
  puts track.to_compact_str
  puts @timr.stack
end