Class: TheFox::Timr::Command::TrackCommand

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

Overview

  • Print informations about a specific [Track](TheFox::Timr::Model::Track).

  • Add/remove a Track.

  • Edit (set) a Track.

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

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-track.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) ⇒ TrackCommand

Returns a new instance of TrackCommand.



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

def initialize(argv = Array.new)
  super()
  
  @help_opt = false
  @show_opt = false
  @add_opt = false
  @remove_opt = false
  @set_opt = false
  
  @verbose_opt = false
  @tracks_opt = Set.new
  @task_opt = false
  @task_id_opt = nil
  
  @message_opt = nil
  @start_date_opt = nil
  @start_time_opt = nil
  @end_date_opt = nil
  @end_time_opt = nil
  @billed_opt = nil
  @unbilled_opt = nil
  
  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 '-v', '--verbose'
      @verbose_opt = true
    when '-t', '--task'
      if @set_opt
        @task_id_opt = argv.shift
      else
        @task_opt = true
      end
    
    when '-m', '--message'
      @message_opt = argv.shift
    when '--sd', '--start-date'
      @start_date_opt = argv.shift
    when '--st', '--start-time'
      @start_time_opt = argv.shift
    when '--ed', '--end-date'
      @end_date_opt = argv.shift
    when '--et', '--end-time'
      @end_time_opt = argv.shift
    when '-b', '--billed'
      @billed_opt = true
    when '--unbilled'
      @unbilled_opt = true
    
    when 'show'
      @show_opt = true
    when 'add'
      @add_opt = true
    when 'remove'
      @remove_opt = true
    when 'set'
      @set_opt = true
    
    else
      @tracks_opt << arg
    end
  end
  
  if @billed_opt && @unbilled_opt
    raise TrackCommandError, 'Cannot use --billed and --unbilled.'
  end
end

Instance Method Details

#runObject

See BasicCommand#run.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/timr/command/track_command.rb', line 96

def run
  if @help_opt
    help
    return
  end
  
  @timr = Timr.new(@cwd)
  @timr.load_all_tracks
  
  if @task_opt
    run_task_command
  elsif @add_opt
    run_add
  elsif @remove_opt
    run_remove
  elsif @set_opt
    run_set
  else
    run_show
  end
end