Class: TheFox::Timr::Command::TaskCommand

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

Overview

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

  • Add/remove a Task.

  • Edit (set) a Task.

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

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-task.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) ⇒ TaskCommand



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

def initialize(argv = Array.new)
  super()
  # puts "argv #{argv}"
  
  @help_opt = false
  @show_opt = false
  @add_opt = false
  @remove_opt = false
  @set_opt = false
  
  @verbose_opt = false
  @tracks_opt = false
  
  @foreign_id_opt = nil
  @unset_foreign_id_opt = nil
  @name_opt = nil
  @description_opt = nil
  @estimation_opt = nil
  @billed_opt = nil
  @unbilled_opt = nil
  
  @hourly_rate_opt = nil
  @unset_hourly_rate_opt = nil
  @has_flat_rate_opt = nil
  @unset_flat_rate_opt = nil
  
  # Holds Task instances.
  @tasks_opt = Set.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 '-v', '--verbose'
      @verbose_opt = true
    when '-t', '--tracks'
      @tracks_opt = true
    
    when '--id'
      @foreign_id_opt = argv.shift.strip
    when '--no-id'
      @unset_foreign_id_opt = true
    when '-n', '--name'
      @name_opt = argv.shift
    when '--desc', '--description', '-d' # -d not official
      @description_opt = argv.shift
    when '-e', '--est', '--estimation'
      @estimation_opt = argv.shift
      # puts "est: #{@estimation_opt}"
    when '-b', '--billed'
      @billed_opt = true
    when '--unbilled'
      @unbilled_opt = true
    
    when '-r', '--hourly-rate'
      @hourly_rate_opt = argv.shift
    when '--no-hourly-rate'
      @unset_hourly_rate_opt = true
    when '--fr', '--flat', '--flat-rate'
      @has_flat_rate_opt = true
    when '--no-flat', '--no-flat-rate'
      @unset_flat_rate_opt = true
    
    when 'show'
      @show_opt = true
    when 'add'
      @add_opt = true
    when 'remove'
      @remove_opt = true
    when 'set'
      @set_opt = true
    
    when Task
      @tasks_opt << arg
    else
      @tasks_opt << arg
    end
    
    # puts "argv #{argv}"
  end
  
  if @foreign_id_opt && @unset_foreign_id_opt
    raise TaskCommandError, 'Cannot use --id and --no-id.'
  end
  if @billed_opt && @unbilled_opt
    raise TaskCommandError, 'Cannot use --billed and --unbilled.'
  end
  if !@hourly_rate_opt.nil? && @unset_hourly_rate_opt
    raise TaskCommandError, 'Cannot use --hourly-rate and --no-hourly-rate.'
  end
  if @has_flat_rate_opt && @unset_flat_rate_opt
    raise TaskCommandError, 'Cannot use --flat-rate and --no-flat-rate.'
  end
end

Instance Method Details

#runObject

See BasicCommand#run.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/timr/command/task_command.rb', line 123

def run
  if @help_opt
    help
    return
  end
  
  @timr = Timr.new(@cwd)
  
  if @add_opt
    run_add
  elsif @remove_opt
    run_remove
  elsif @set_opt
    run_set
  else
    if @tasks_opt.count == 0
      run_show_all
    else
      run_show
    end
  end
end