Class: Abt::Providers::Harvest::Commands::Track

Inherits:
BaseCommand show all
Defined in:
lib/abt/providers/harvest/commands/track.rb

Overview

rubocop:disable Metrics/ClassLength

Direct Known Subclasses

Start

Instance Attribute Summary

Attributes inherited from BaseCommand

#config, #path

Attributes inherited from BaseCommand

#ari, #cli, #flags

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Abt::Providers::Harvest::BaseCommand

Class Method Details

.descriptionObject



12
13
14
15
16
# File 'lib/abt/providers/harvest/commands/track.rb', line 12

def self.description
  <<~TXT
    Start tracker for current or specified task. Add a relevant ARI to link the time entry, e.g. `abt track harvest asana`
  TXT
end

.flagsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/abt/providers/harvest/commands/track.rb', line 18

def self.flags
  [
    ["-s", "--set", "Set specified task as current"],
    ["-c", "--comment COMMENT", "Override comment"],
    ["-t", "--time HOURS",
     "Track amount of hours, this will create a stopped entry."],
    ["-i", "--since HH:MM",
     "Start entry today at specified time. The computed duration will be deducted from the running entry if one exists."] # rubocop:disable Layout/LineLength
  ]
end

.usageObject



8
9
10
# File 'lib/abt/providers/harvest/commands/track.rb', line 8

def self.usage
  "abt track harvest[:<project-id>/<task-id>] [options]"
end

Instance Method Details

#performObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/abt/providers/harvest/commands/track.rb', line 29

def perform
  abort("Flags --time and --since cannot be used together") if flags[:time] && flags[:since]

  require_task!

  maybe_adjust_previous_entry
  entry = create_entry!

  print_task(entry["project"], entry["task"])

  maybe_override_current_task
rescue Abt::HttpError::HttpError => _e
  abort("Invalid task")
end