abt-cli 0.0.11 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/bin/abt +1 -7
  3. data/lib/abt.rb +12 -3
  4. data/lib/abt/cli.rb +91 -53
  5. data/lib/abt/cli/arguments_parser.rb +70 -0
  6. data/lib/abt/cli/base_command.rb +61 -0
  7. data/lib/abt/cli/prompt.rb +124 -0
  8. data/lib/abt/docs.rb +24 -18
  9. data/lib/abt/docs/cli.rb +42 -11
  10. data/lib/abt/docs/markdown.rb +36 -10
  11. data/lib/abt/git_config.rb +34 -19
  12. data/lib/abt/helpers.rb +1 -1
  13. data/lib/abt/providers/asana/base_command.rb +24 -13
  14. data/lib/abt/providers/asana/commands/add.rb +75 -0
  15. data/lib/abt/providers/asana/commands/branch_name.rb +44 -0
  16. data/lib/abt/providers/asana/commands/clear.rb +17 -6
  17. data/lib/abt/providers/asana/commands/current.rb +6 -6
  18. data/lib/abt/providers/asana/commands/finalize.rb +4 -4
  19. data/lib/abt/providers/asana/commands/harvest_time_entry_data.rb +4 -3
  20. data/lib/abt/providers/asana/commands/init.rb +5 -5
  21. data/lib/abt/providers/asana/commands/pick.rb +16 -7
  22. data/lib/abt/providers/asana/commands/projects.rb +3 -3
  23. data/lib/abt/providers/asana/commands/share.rb +8 -8
  24. data/lib/abt/providers/asana/commands/start.rb +15 -9
  25. data/lib/abt/providers/asana/commands/tasks.rb +5 -3
  26. data/lib/abt/providers/asana/configuration.rb +8 -16
  27. data/lib/abt/providers/devops/api.rb +32 -2
  28. data/lib/abt/providers/devops/base_command.rb +32 -16
  29. data/lib/abt/providers/devops/commands/boards.rb +36 -0
  30. data/lib/abt/providers/devops/commands/branch_name.rb +45 -0
  31. data/lib/abt/providers/devops/commands/clear.rb +17 -6
  32. data/lib/abt/providers/devops/commands/current.rb +6 -10
  33. data/lib/abt/providers/devops/commands/harvest_time_entry_data.rb +5 -3
  34. data/lib/abt/providers/devops/commands/init.rb +5 -5
  35. data/lib/abt/providers/devops/commands/pick.rb +29 -20
  36. data/lib/abt/providers/devops/commands/share.rb +7 -13
  37. data/lib/abt/providers/devops/commands/work-items.rb +46 -0
  38. data/lib/abt/providers/devops/configuration.rb +7 -15
  39. data/lib/abt/providers/git.rb +19 -0
  40. data/lib/abt/providers/git/commands/branch.rb +74 -0
  41. data/lib/abt/providers/harvest/base_command.rb +24 -13
  42. data/lib/abt/providers/harvest/commands/clear.rb +17 -6
  43. data/lib/abt/providers/harvest/commands/current.rb +6 -6
  44. data/lib/abt/providers/harvest/commands/init.rb +5 -5
  45. data/lib/abt/providers/harvest/commands/pick.rb +15 -6
  46. data/lib/abt/providers/harvest/commands/projects.rb +3 -3
  47. data/lib/abt/providers/harvest/commands/share.rb +5 -5
  48. data/lib/abt/providers/harvest/commands/start.rb +6 -44
  49. data/lib/abt/providers/harvest/commands/stop.rb +3 -3
  50. data/lib/abt/providers/harvest/commands/tasks.rb +5 -3
  51. data/lib/abt/providers/harvest/commands/track.rb +50 -13
  52. data/lib/abt/providers/harvest/configuration.rb +7 -13
  53. data/lib/abt/version.rb +1 -1
  54. metadata +12 -7
  55. data/lib/abt/cli/dialogs.rb +0 -86
  56. data/lib/abt/cli/io.rb +0 -23
  57. data/lib/abt/providers/asana/commands/clear_global.rb +0 -24
  58. data/lib/abt/providers/devops/commands/clear_global.rb +0 -24
  59. data/lib/abt/providers/harvest/commands/clear_global.rb +0 -24
@@ -5,15 +5,15 @@ module Abt
5
5
  module Harvest
6
6
  module Commands
7
7
  class Stop < BaseCommand
8
- def self.command
9
- 'stop harvest'
8
+ def self.usage
9
+ 'abt stop harvest'
10
10
  end
11
11
 
12
12
  def self.description
13
13
  'Stop running harvest tracker'
14
14
  end
15
15
 
16
- def call
16
+ def perform
17
17
  cli.abort 'No running time entry' if time_entry.nil?
18
18
 
19
19
  stop_time_entry
@@ -5,15 +5,17 @@ module Abt
5
5
  module Harvest
6
6
  module Commands
7
7
  class Tasks < BaseCommand
8
- def self.command
9
- 'tasks harvest'
8
+ def self.usage
9
+ 'abt tasks harvest'
10
10
  end
11
11
 
12
12
  def self.description
13
13
  'List available tasks on project - useful for piping into grep etc.'
14
14
  end
15
15
 
16
- def call
16
+ def perform
17
+ require_project!
18
+
17
19
  tasks.each do |task|
18
20
  print_task(project, task)
19
21
  end
@@ -5,22 +5,30 @@ module Abt
5
5
  module Harvest
6
6
  module Commands
7
7
  class Track < BaseCommand
8
- def self.command
9
- 'track harvest[:<project-id>/<task-id>]'
8
+ def self.usage
9
+ 'abt track harvest[:<project-id>/<task-id>] [options]'
10
10
  end
11
11
 
12
12
  def self.description
13
- 'Start tracker for current or specified task. Add a relevant provider to link the time entry: E.g. `abt start harvest asana`' # rubocop:disable Layout/LineLength
13
+ 'Start tracker for current or specified task. Add a relevant scheme argument to link the time entry, e.g. `abt track harvest asana`'
14
14
  end
15
15
 
16
- def call
17
- abort 'No current/provided task' if task_id.nil?
18
- cli.abort('No task selected') if task_id.nil?
16
+ def self.flags
17
+ [
18
+ ['-s', '--set', 'Set specified task as current'],
19
+ ['-c', '--comment COMMENT', 'Override comment'],
20
+ ['-t', '--time HOURS', 'Set hours. Creates a stopped entry unless used with --running'],
21
+ ['-r', '--running', 'Used with --time, starts the created time entry']
22
+ ]
23
+ end
24
+
25
+ def perform
26
+ require_task!
19
27
 
20
28
  print_task(created_time_entry['project'], created_time_entry['task'])
21
29
 
22
- cli.warn 'Tracker successfully started'
23
- rescue Abt::HttpError::HttpError => e
30
+ maybe_override_current_task
31
+ rescue Abt::HttpError::HttpError => _e
24
32
  cli.abort 'Invalid task'
25
33
  end
26
34
 
@@ -31,6 +39,19 @@ module Abt
31
39
  end
32
40
 
33
41
  def create_time_entry
42
+ body = time_entry_base_data
43
+ body.merge!(hours: flags[:time]) if flags.key? :time
44
+
45
+ result = api.post('time_entries', Oj.dump(body, mode: :json))
46
+
47
+ if flags.key?(:time) && flags[:running]
48
+ api.patch("time_entries/#{result['id']}/restart")
49
+ end
50
+
51
+ result
52
+ end
53
+
54
+ def time_entry_base_data
34
55
  body = {
35
56
  project_id: project_id,
36
57
  task_id: task_id,
@@ -39,18 +60,24 @@ module Abt
39
60
  }
40
61
 
41
62
  if external_link_data
63
+ cli.warn <<~TXT
64
+ Linking to:
65
+ #{external_link_data[:notes]}
66
+ #{external_link_data[:external_reference][:permalink]}
67
+ TXT
42
68
  body.merge! external_link_data
43
69
  else
44
70
  cli.warn 'No external link provided'
45
- body[:notes] ||= cli.prompt('Fill in comment (optional)')
46
71
  end
47
72
 
48
- api.post('time_entries', Oj.dump(body, mode: :json))
73
+ body[:notes] = flags[:comment] if flags.key?(:comment)
74
+ body[:notes] ||= cli.prompt.text('Fill in comment (optional)')
75
+ body
49
76
  end
50
77
 
51
78
  def external_link_data
52
79
  @external_link_data ||= begin
53
- input = StringIO.new(cli.args.join(' '))
80
+ input = StringIO.new(cli.scheme_arguments.to_s)
54
81
  output = StringIO.new
55
82
  Abt::Cli.new(argv: ['harvest-time-entry-data'], output: output, input: input).perform
56
83
 
@@ -60,12 +87,22 @@ module Abt
60
87
 
61
88
  # TODO: Make user choose which reference to use by printing the urls
62
89
  if lines.length > 1
63
- cli.abort('Multiple providers had harvest reference data, only one is supported at a time') # rubocop:disable Layout/LineLength
90
+ cli.abort('Got reference data from multiple scheme providers, only one is supported at a time')
64
91
  end
65
92
 
66
- Oj.load(lines.first)
93
+ Oj.load(lines.first, symbol_keys: true)
67
94
  end
68
95
  end
96
+
97
+ def maybe_override_current_task
98
+ return unless flags[:set]
99
+ return if same_args_as_config?
100
+ return unless config.local_available?
101
+
102
+ input = StringIO.new("harvest:#{project_id}/#{task_id}")
103
+ output = StringIO.new
104
+ Abt::Cli.new(argv: ['current'], output: output, input: input).perform
105
+ end
69
106
  end
70
107
  end
71
108
  end
@@ -27,7 +27,7 @@ module Abt
27
27
  value = value.to_s unless value.nil?
28
28
  return if project_id == value
29
29
 
30
- clear_local
30
+ clear_local(verbose: false)
31
31
  git['projectId'] = value
32
32
  end
33
33
 
@@ -36,24 +36,18 @@ module Abt
36
36
  git['taskId'] = value
37
37
  end
38
38
 
39
- def clear_local
40
- cli.abort 'No local configuration was found' unless local_available?
41
-
42
- git['projectId'] = nil
43
- git['taskId'] = nil
39
+ def clear_local(verbose: true)
40
+ git.clear(output: verbose ? cli.err_output : nil)
44
41
  end
45
42
 
46
- def clear_global
47
- git.global.keys.each do |key|
48
- cli.puts 'Deleting configuration: ' + key
49
- git.global[key] = nil
50
- end
43
+ def clear_global(verbose: true)
44
+ git.global.clear(output: verbose ? cli.err_output : nil)
51
45
  end
52
46
 
53
47
  def access_token
54
48
  return git.global['accessToken'] unless git.global['accessToken'].nil?
55
49
 
56
- git.global['accessToken'] = cli.prompt([
50
+ git.global['accessToken'] = cli.prompt.text([
57
51
  'Please provide your personal access token for Harvest.',
58
52
  'If you don\'t have one, create one here: https://id.getharvest.com/developers',
59
53
  '',
@@ -64,7 +58,7 @@ module Abt
64
58
  def account_id
65
59
  return git.global['accountId'] unless git.global['accountId'].nil?
66
60
 
67
- git.global['accountId'] = cli.prompt([
61
+ git.global['accountId'] = cli.prompt.text([
68
62
  'Please provide harvest account id.',
69
63
  'This information is shown next to your generated access token',
70
64
  '',
data/lib/abt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Abt
4
- VERSION = '0.0.11'
4
+ VERSION = '0.0.16'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abt-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesper Sørensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -76,8 +76,9 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - "./lib/abt.rb"
78
78
  - "./lib/abt/cli.rb"
79
- - "./lib/abt/cli/dialogs.rb"
80
- - "./lib/abt/cli/io.rb"
79
+ - "./lib/abt/cli/arguments_parser.rb"
80
+ - "./lib/abt/cli/base_command.rb"
81
+ - "./lib/abt/cli/prompt.rb"
81
82
  - "./lib/abt/docs.rb"
82
83
  - "./lib/abt/docs/cli.rb"
83
84
  - "./lib/abt/docs/markdown.rb"
@@ -88,8 +89,9 @@ files:
88
89
  - "./lib/abt/providers/asana.rb"
89
90
  - "./lib/abt/providers/asana/api.rb"
90
91
  - "./lib/abt/providers/asana/base_command.rb"
92
+ - "./lib/abt/providers/asana/commands/add.rb"
93
+ - "./lib/abt/providers/asana/commands/branch_name.rb"
91
94
  - "./lib/abt/providers/asana/commands/clear.rb"
92
- - "./lib/abt/providers/asana/commands/clear_global.rb"
93
95
  - "./lib/abt/providers/asana/commands/current.rb"
94
96
  - "./lib/abt/providers/asana/commands/finalize.rb"
95
97
  - "./lib/abt/providers/asana/commands/harvest_time_entry_data.rb"
@@ -103,19 +105,22 @@ files:
103
105
  - "./lib/abt/providers/devops.rb"
104
106
  - "./lib/abt/providers/devops/api.rb"
105
107
  - "./lib/abt/providers/devops/base_command.rb"
108
+ - "./lib/abt/providers/devops/commands/boards.rb"
109
+ - "./lib/abt/providers/devops/commands/branch_name.rb"
106
110
  - "./lib/abt/providers/devops/commands/clear.rb"
107
- - "./lib/abt/providers/devops/commands/clear_global.rb"
108
111
  - "./lib/abt/providers/devops/commands/current.rb"
109
112
  - "./lib/abt/providers/devops/commands/harvest_time_entry_data.rb"
110
113
  - "./lib/abt/providers/devops/commands/init.rb"
111
114
  - "./lib/abt/providers/devops/commands/pick.rb"
112
115
  - "./lib/abt/providers/devops/commands/share.rb"
116
+ - "./lib/abt/providers/devops/commands/work-items.rb"
113
117
  - "./lib/abt/providers/devops/configuration.rb"
118
+ - "./lib/abt/providers/git.rb"
119
+ - "./lib/abt/providers/git/commands/branch.rb"
114
120
  - "./lib/abt/providers/harvest.rb"
115
121
  - "./lib/abt/providers/harvest/api.rb"
116
122
  - "./lib/abt/providers/harvest/base_command.rb"
117
123
  - "./lib/abt/providers/harvest/commands/clear.rb"
118
- - "./lib/abt/providers/harvest/commands/clear_global.rb"
119
124
  - "./lib/abt/providers/harvest/commands/current.rb"
120
125
  - "./lib/abt/providers/harvest/commands/init.rb"
121
126
  - "./lib/abt/providers/harvest/commands/pick.rb"
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- class Cli
5
- module Dialogs
6
- def prompt(question)
7
- err_output.print "#{question}: "
8
- read_user_input.strip
9
- end
10
-
11
- def prompt_boolean(text)
12
- warn text
13
-
14
- loop do
15
- err_output.print '(y / n): '
16
-
17
- case read_user_input.strip
18
- when 'y', 'Y' then return true
19
- when 'n', 'N' then return false
20
- else
21
- warn 'Invalid choice'
22
- next
23
- end
24
- end
25
- end
26
-
27
- def prompt_choice(text, options, allow_back_option = false)
28
- warn "#{text}:"
29
-
30
- if options.length.zero?
31
- abort 'No available options' unless allow_back_option
32
-
33
- warn 'No available options'
34
- return nil
35
- end
36
-
37
- print_options(options)
38
- select_options(options, allow_back_option)
39
- end
40
-
41
- private
42
-
43
- def print_options(options)
44
- options.each_with_index do |option, index|
45
- warn "(#{index + 1}) #{option['name']}"
46
- end
47
- end
48
-
49
- def select_options(options, allow_back_option)
50
- loop do
51
- number = read_option_number(options.length, allow_back_option)
52
- if number.nil?
53
- return nil if allow_back_option
54
-
55
- next
56
- end
57
-
58
- option = options[number - 1]
59
-
60
- warn "Selected: (#{number}) #{option['name']}"
61
- return option
62
- end
63
- end
64
-
65
- def read_option_number(options_length, allow_back_option)
66
- err_output.print "(1-#{options_length}#{allow_back_option ? ', q: back' : ''}): "
67
-
68
- input = read_user_input
69
-
70
- return nil if allow_back_option && input == 'q'
71
-
72
- option_number = input.to_i
73
- if option_number <= 0 || option_number > options_length
74
- warn 'Invalid selection'
75
- return nil
76
- end
77
-
78
- option_number
79
- end
80
-
81
- def read_user_input
82
- open('/dev/tty', &:gets).strip
83
- end
84
- end
85
- end
86
- end
data/lib/abt/cli/io.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- class Cli
5
- module Io
6
- def warn(*args)
7
- err_output.puts(*args)
8
- end
9
-
10
- def puts(*args)
11
- output.puts(*args)
12
- end
13
-
14
- def print(*args)
15
- output.print(*args)
16
- end
17
-
18
- def abort(message)
19
- raise AbortError, message
20
- end
21
- end
22
- end
23
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- module Providers
5
- module Asana
6
- module Commands
7
- class ClearGlobal < BaseCommand
8
- def self.command
9
- 'clear-global asana'
10
- end
11
-
12
- def self.description
13
- 'Clear all global configuration'
14
- end
15
-
16
- def call
17
- cli.warn 'Clearing Asana project configuration'
18
- config.clear_global
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- module Providers
5
- module Devops
6
- module Commands
7
- class ClearGlobal < BaseCommand
8
- def self.command
9
- 'clear-global devops'
10
- end
11
-
12
- def self.description
13
- 'Clear all global configuration'
14
- end
15
-
16
- def call
17
- cli.warn 'Clearing global DevOps configuration'
18
- config.clear_global
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- module Providers
5
- module Harvest
6
- module Commands
7
- class ClearGlobal < BaseCommand
8
- def self.command
9
- 'clear-global harvest'
10
- end
11
-
12
- def self.description
13
- 'Clear all global configuration'
14
- end
15
-
16
- def call
17
- cli.warn 'Clearing Harvest project configuration'
18
- config.clear_global
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end