abt-cli 0.0.18 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/bin/abt +3 -3
  3. data/lib/abt.rb +6 -6
  4. data/lib/abt/ari.rb +20 -0
  5. data/lib/abt/ari_list.rb +13 -0
  6. data/lib/abt/base_command.rb +63 -0
  7. data/lib/abt/cli.rb +51 -52
  8. data/lib/abt/cli/arguments_parser.rb +7 -26
  9. data/lib/abt/cli/global_commands.rb +23 -0
  10. data/lib/abt/cli/global_commands/commands.rb +23 -0
  11. data/lib/abt/cli/global_commands/examples.rb +23 -0
  12. data/lib/abt/cli/global_commands/help.rb +23 -0
  13. data/lib/abt/cli/global_commands/readme.rb +23 -0
  14. data/lib/abt/cli/global_commands/share.rb +36 -0
  15. data/lib/abt/cli/global_commands/version.rb +23 -0
  16. data/lib/abt/cli/prompt.rb +64 -51
  17. data/lib/abt/docs.rb +48 -25
  18. data/lib/abt/docs/cli.rb +3 -3
  19. data/lib/abt/docs/markdown.rb +11 -8
  20. data/lib/abt/git_config.rb +21 -39
  21. data/lib/abt/helpers.rb +26 -8
  22. data/lib/abt/providers/asana/api.rb +9 -9
  23. data/lib/abt/providers/asana/base_command.rb +20 -38
  24. data/lib/abt/providers/asana/commands/add.rb +18 -15
  25. data/lib/abt/providers/asana/commands/branch_name.rb +13 -8
  26. data/lib/abt/providers/asana/commands/clear.rb +8 -7
  27. data/lib/abt/providers/asana/commands/current.rb +22 -38
  28. data/lib/abt/providers/asana/commands/finalize.rb +17 -18
  29. data/lib/abt/providers/asana/commands/harvest_time_entry_data.rb +20 -13
  30. data/lib/abt/providers/asana/commands/init.rb +8 -41
  31. data/lib/abt/providers/asana/commands/pick.rb +27 -26
  32. data/lib/abt/providers/asana/commands/projects.rb +5 -5
  33. data/lib/abt/providers/asana/commands/share.rb +6 -8
  34. data/lib/abt/providers/asana/commands/start.rb +33 -24
  35. data/lib/abt/providers/asana/commands/tasks.rb +6 -5
  36. data/lib/abt/providers/asana/configuration.rb +46 -44
  37. data/lib/abt/providers/asana/path.rb +36 -0
  38. data/lib/abt/providers/devops/api.rb +23 -11
  39. data/lib/abt/providers/devops/base_command.rb +22 -43
  40. data/lib/abt/providers/devops/commands/boards.rb +5 -7
  41. data/lib/abt/providers/devops/commands/branch_name.rb +14 -10
  42. data/lib/abt/providers/devops/commands/clear.rb +8 -7
  43. data/lib/abt/providers/devops/commands/current.rb +24 -49
  44. data/lib/abt/providers/devops/commands/harvest_time_entry_data.rb +26 -16
  45. data/lib/abt/providers/devops/commands/init.rb +33 -26
  46. data/lib/abt/providers/devops/commands/pick.rb +23 -24
  47. data/lib/abt/providers/devops/commands/share.rb +7 -6
  48. data/lib/abt/providers/devops/commands/{work-items.rb → work_items.rb} +3 -3
  49. data/lib/abt/providers/devops/configuration.rb +27 -56
  50. data/lib/abt/providers/devops/path.rb +51 -0
  51. data/lib/abt/providers/git/commands/branch.rb +25 -19
  52. data/lib/abt/providers/harvest/api.rb +8 -8
  53. data/lib/abt/providers/harvest/base_command.rb +20 -36
  54. data/lib/abt/providers/harvest/commands/clear.rb +8 -7
  55. data/lib/abt/providers/harvest/commands/current.rb +27 -35
  56. data/lib/abt/providers/harvest/commands/init.rb +10 -40
  57. data/lib/abt/providers/harvest/commands/pick.rb +15 -12
  58. data/lib/abt/providers/harvest/commands/projects.rb +5 -5
  59. data/lib/abt/providers/harvest/commands/share.rb +6 -8
  60. data/lib/abt/providers/harvest/commands/start.rb +5 -3
  61. data/lib/abt/providers/harvest/commands/stop.rb +13 -13
  62. data/lib/abt/providers/harvest/commands/tasks.rb +9 -6
  63. data/lib/abt/providers/harvest/commands/track.rb +60 -38
  64. data/lib/abt/providers/harvest/configuration.rb +28 -37
  65. data/lib/abt/providers/harvest/path.rb +36 -0
  66. data/lib/abt/version.rb +1 -1
  67. metadata +18 -6
  68. data/lib/abt/cli/base_command.rb +0 -61
@@ -8,32 +8,18 @@ module Abt
8
8
 
9
9
  def initialize(cli:)
10
10
  @cli = cli
11
- @git = GitConfig.new(namespace: 'abt.harvest')
12
11
  end
13
12
 
14
13
  def local_available?
15
- GitConfig.local_available?
14
+ git.available?
16
15
  end
17
16
 
18
- def project_id
19
- local_available? ? git['projectId'] : nil
17
+ def path
18
+ Path.new(local_available? && git["path"] || "")
20
19
  end
21
20
 
22
- def task_id
23
- local_available? ? git['taskId'] : nil
24
- end
25
-
26
- def project_id=(value)
27
- value = value.to_s unless value.nil?
28
- return if project_id == value
29
-
30
- clear_local(verbose: false)
31
- git['projectId'] = value
32
- end
33
-
34
- def task_id=(value)
35
- value = value.to_s unless value.nil?
36
- git['taskId'] = value
21
+ def path=(new_path)
22
+ git["path"] = new_path
37
23
  end
38
24
 
39
25
  def clear_local(verbose: true)
@@ -41,44 +27,49 @@ module Abt
41
27
  end
42
28
 
43
29
  def clear_global(verbose: true)
44
- git.global.clear(output: verbose ? cli.err_output : nil)
30
+ git_global.clear(output: verbose ? cli.err_output : nil)
45
31
  end
46
32
 
47
33
  def access_token
48
- return git.global['accessToken'] unless git.global['accessToken'].nil?
34
+ return git_global["accessToken"] unless git_global["accessToken"].nil?
49
35
 
50
- git.global['accessToken'] = cli.prompt.text([
51
- 'Please provide your personal access token for Harvest.',
52
- 'If you don\'t have one, create one here: https://id.getharvest.com/developers',
53
- '',
54
- 'Enter access token'
36
+ git_global["accessToken"] = cli.prompt.text([
37
+ "Please provide your personal access token for Harvest.",
38
+ "If you don't have one, create one here: https://id.getharvest.com/developers",
39
+ "",
40
+ "Enter access token"
55
41
  ].join("\n"))
56
42
  end
57
43
 
58
44
  def account_id
59
- return git.global['accountId'] unless git.global['accountId'].nil?
45
+ return git_global["accountId"] unless git_global["accountId"].nil?
60
46
 
61
- git.global['accountId'] = cli.prompt.text([
62
- 'Please provide harvest account id.',
63
- 'This information is shown next to your generated access token',
64
- '',
65
- 'Enter account id'
47
+ git_global["accountId"] = cli.prompt.text([
48
+ "Please provide harvest account id.",
49
+ "This information is shown next to your generated access token",
50
+ "",
51
+ "Enter account id"
66
52
  ].join("\n"))
67
53
  end
68
54
 
69
55
  def user_id
70
- return git.global['userId'] unless git.global['userId'].nil?
56
+ return git_global["userId"] unless git_global["userId"].nil?
71
57
 
72
- git.global['userId'] = api.get('users/me')['id'].to_s
58
+ git_global["userId"] = api.get("users/me")["id"].to_s
73
59
  end
74
60
 
75
61
  private
76
62
 
77
- attr_reader :git
63
+ def git
64
+ @git ||= GitConfig.new("local", "abt.harvest")
65
+ end
66
+
67
+ def git_global
68
+ @git_global ||= GitConfig.new("global", "abt.harvest")
69
+ end
78
70
 
79
71
  def api
80
- @api ||=
81
- Abt::Providers::Harvest::Api.new(access_token: access_token, account_id: account_id)
72
+ @api ||= Api.new(access_token: access_token, account_id: account_id)
82
73
  end
83
74
  end
84
75
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ module Providers
5
+ module Harvest
6
+ class Path < String
7
+ PATH_REGEX = %r{^(?<project_id>\d+)?/?(?<task_id>\d+)?$}.freeze
8
+
9
+ def self.from_ids(project_id: nil, task_id: nil)
10
+ path = project_id ? [project_id, *task_id].join("/") : ""
11
+ new(path)
12
+ end
13
+
14
+ def initialize(path = "")
15
+ raise Abt::Cli::Abort, "Invalid path: #{path}" unless PATH_REGEX.match?(path)
16
+
17
+ super
18
+ end
19
+
20
+ def project_id
21
+ match[:project_id]
22
+ end
23
+
24
+ def task_id
25
+ match[:task_id]
26
+ end
27
+
28
+ private
29
+
30
+ def match
31
+ @match ||= PATH_REGEX.match(self)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
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.18'
4
+ VERSION = "0.0.23"
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.18
4
+ version: 0.0.23
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-02-12 00:00:00.000000000 Z
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -75,9 +75,18 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - "./lib/abt.rb"
78
+ - "./lib/abt/ari.rb"
79
+ - "./lib/abt/ari_list.rb"
80
+ - "./lib/abt/base_command.rb"
78
81
  - "./lib/abt/cli.rb"
79
82
  - "./lib/abt/cli/arguments_parser.rb"
80
- - "./lib/abt/cli/base_command.rb"
83
+ - "./lib/abt/cli/global_commands.rb"
84
+ - "./lib/abt/cli/global_commands/commands.rb"
85
+ - "./lib/abt/cli/global_commands/examples.rb"
86
+ - "./lib/abt/cli/global_commands/help.rb"
87
+ - "./lib/abt/cli/global_commands/readme.rb"
88
+ - "./lib/abt/cli/global_commands/share.rb"
89
+ - "./lib/abt/cli/global_commands/version.rb"
81
90
  - "./lib/abt/cli/prompt.rb"
82
91
  - "./lib/abt/docs.rb"
83
92
  - "./lib/abt/docs/cli.rb"
@@ -102,6 +111,7 @@ files:
102
111
  - "./lib/abt/providers/asana/commands/start.rb"
103
112
  - "./lib/abt/providers/asana/commands/tasks.rb"
104
113
  - "./lib/abt/providers/asana/configuration.rb"
114
+ - "./lib/abt/providers/asana/path.rb"
105
115
  - "./lib/abt/providers/devops.rb"
106
116
  - "./lib/abt/providers/devops/api.rb"
107
117
  - "./lib/abt/providers/devops/base_command.rb"
@@ -113,8 +123,9 @@ files:
113
123
  - "./lib/abt/providers/devops/commands/init.rb"
114
124
  - "./lib/abt/providers/devops/commands/pick.rb"
115
125
  - "./lib/abt/providers/devops/commands/share.rb"
116
- - "./lib/abt/providers/devops/commands/work-items.rb"
126
+ - "./lib/abt/providers/devops/commands/work_items.rb"
117
127
  - "./lib/abt/providers/devops/configuration.rb"
128
+ - "./lib/abt/providers/devops/path.rb"
118
129
  - "./lib/abt/providers/git.rb"
119
130
  - "./lib/abt/providers/git/commands/branch.rb"
120
131
  - "./lib/abt/providers/harvest.rb"
@@ -131,6 +142,7 @@ files:
131
142
  - "./lib/abt/providers/harvest/commands/tasks.rb"
132
143
  - "./lib/abt/providers/harvest/commands/track.rb"
133
144
  - "./lib/abt/providers/harvest/configuration.rb"
145
+ - "./lib/abt/providers/harvest/path.rb"
134
146
  - "./lib/abt/version.rb"
135
147
  - bin/abt
136
148
  homepage: https://github.com/abtion/abt
@@ -147,14 +159,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
159
  requirements:
148
160
  - - ">="
149
161
  - !ruby/object:Gem::Version
150
- version: '0'
162
+ version: 2.5.0
151
163
  required_rubygems_version: !ruby/object:Gem::Requirement
152
164
  requirements:
153
165
  - - ">="
154
166
  - !ruby/object:Gem::Version
155
167
  version: '0'
156
168
  requirements: []
157
- rubygems_version: 3.0.3
169
+ rubygems_version: 3.1.4
158
170
  signing_key:
159
171
  specification_version: 4
160
172
  summary: Versatile scripts
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Abt
4
- class Cli
5
- class BaseCommand
6
- def self.usage
7
- raise NotImplementedError, 'Command classes must implement .command'
8
- end
9
-
10
- def self.description
11
- raise NotImplementedError, 'Command classes must implement .description'
12
- end
13
-
14
- def self.flags
15
- []
16
- end
17
-
18
- attr_reader :path, :flags, :cli
19
-
20
- def initialize(path:, flags:, cli:)
21
- @cli = cli
22
- @path = path
23
- @flags = parse_flags(flags)
24
- end
25
-
26
- def perform
27
- raise NotImplementedError, 'Command classes must implement #perform'
28
- end
29
-
30
- private
31
-
32
- def parse_flags(flags)
33
- result = {}
34
-
35
- flag_parser.parse!(flags.dup, into: result)
36
-
37
- cli.exit_with_message(flag_parser.help) if result[:help]
38
-
39
- result
40
- rescue OptionParser::InvalidOption => e
41
- cli.abort e.message
42
- end
43
-
44
- def flag_parser
45
- @flag_parser ||= OptionParser.new do |opts|
46
- opts.banner = <<~TXT
47
- #{self.class.description}
48
-
49
- Usage: #{self.class.usage}
50
- TXT
51
-
52
- opts.on('-h', '--help')
53
-
54
- self.class.flags.each do |(*flag)|
55
- opts.on(*flag)
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end