abt-cli 0.0.19 → 0.0.24

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 (67) 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 +2 -2
  5. data/lib/abt/ari_list.rb +1 -1
  6. data/lib/abt/base_command.rb +7 -7
  7. data/lib/abt/cli.rb +49 -47
  8. data/lib/abt/cli/arguments_parser.rb +6 -3
  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 -52
  17. data/lib/abt/docs.rb +48 -26
  18. data/lib/abt/docs/cli.rb +3 -3
  19. data/lib/abt/docs/markdown.rb +10 -7
  20. data/lib/abt/git_config.rb +4 -6
  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 +12 -10
  24. data/lib/abt/providers/asana/commands/add.rb +13 -12
  25. data/lib/abt/providers/asana/commands/branch_name.rb +8 -8
  26. data/lib/abt/providers/asana/commands/clear.rb +7 -8
  27. data/lib/abt/providers/asana/commands/current.rb +14 -15
  28. data/lib/abt/providers/asana/commands/finalize.rb +17 -18
  29. data/lib/abt/providers/asana/commands/harvest_time_entry_data.rb +18 -16
  30. data/lib/abt/providers/asana/commands/init.rb +8 -41
  31. data/lib/abt/providers/asana/commands/pick.rb +22 -26
  32. data/lib/abt/providers/asana/commands/projects.rb +5 -5
  33. data/lib/abt/providers/asana/commands/share.rb +7 -5
  34. data/lib/abt/providers/asana/commands/start.rb +28 -21
  35. data/lib/abt/providers/asana/commands/tasks.rb +6 -6
  36. data/lib/abt/providers/asana/configuration.rb +37 -29
  37. data/lib/abt/providers/asana/path.rb +6 -6
  38. data/lib/abt/providers/devops/api.rb +12 -12
  39. data/lib/abt/providers/devops/base_command.rb +14 -10
  40. data/lib/abt/providers/devops/commands/boards.rb +5 -7
  41. data/lib/abt/providers/devops/commands/branch_name.rb +9 -9
  42. data/lib/abt/providers/devops/commands/clear.rb +7 -8
  43. data/lib/abt/providers/devops/commands/current.rb +17 -18
  44. data/lib/abt/providers/devops/commands/harvest_time_entry_data.rb +21 -19
  45. data/lib/abt/providers/devops/commands/init.rb +21 -14
  46. data/lib/abt/providers/devops/commands/pick.rb +25 -19
  47. data/lib/abt/providers/devops/commands/share.rb +7 -5
  48. data/lib/abt/providers/devops/commands/{work-items.rb → work_items.rb} +3 -3
  49. data/lib/abt/providers/devops/configuration.rb +15 -15
  50. data/lib/abt/providers/devops/path.rb +7 -6
  51. data/lib/abt/providers/git/commands/branch.rb +23 -21
  52. data/lib/abt/providers/harvest/api.rb +8 -8
  53. data/lib/abt/providers/harvest/base_command.rb +10 -8
  54. data/lib/abt/providers/harvest/commands/clear.rb +7 -8
  55. data/lib/abt/providers/harvest/commands/current.rb +13 -14
  56. data/lib/abt/providers/harvest/commands/init.rb +10 -39
  57. data/lib/abt/providers/harvest/commands/pick.rb +15 -11
  58. data/lib/abt/providers/harvest/commands/projects.rb +5 -5
  59. data/lib/abt/providers/harvest/commands/share.rb +7 -5
  60. data/lib/abt/providers/harvest/commands/start.rb +5 -3
  61. data/lib/abt/providers/harvest/commands/stop.rb +12 -12
  62. data/lib/abt/providers/harvest/commands/tasks.rb +7 -7
  63. data/lib/abt/providers/harvest/commands/track.rb +52 -37
  64. data/lib/abt/providers/harvest/configuration.rb +18 -18
  65. data/lib/abt/providers/harvest/path.rb +6 -6
  66. data/lib/abt/version.rb +1 -1
  67. metadata +12 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 295db35510e60a5b46ea7f20caa01aaad247bb30cb60e61b912cab5f754637ac
4
- data.tar.gz: e686eb40fc1ac88315c138eac56b96500c29c3f012b4bdb1d97f993a507f80b7
3
+ metadata.gz: 6b21c8f210a7c29d5f43ef7c756cfdcc7d8ef2b13ef4dcaef1cec4f8bf2297a1
4
+ data.tar.gz: f7586aa063494d796ded7c2e8696d9bf834e24be3004c621408e2fdd58f9b516
5
5
  SHA512:
6
- metadata.gz: f18aa2b4f33bb6b51689522bca357ddb0fbe7a2d2e968bcc6754959f01bf6d54b9f93c387e8a050d165063cad26e6b360f245d2e7fa317bc1fbad8c0fa0d3379
7
- data.tar.gz: ab46d17a29d4e447472c8c4d9242aa2e96bd5195bad4083d0476054f312d358ad5555526b44edacdf2512713e646435200689f82e8a097c1dfa306ff2ae1c4df
6
+ metadata.gz: b9d5278daeec2067937212108eb0ba478c1ec80d45c14a94025f7d6d83c5a30c4cdb716d010a4dfc807166165cd04af8e7962ec2b776f9f2fb7feee7edb65194
7
+ data.tar.gz: 2faba55f9dcf4ee66f82a77b647fe367fbebeb74c70fde23edd6543ad83ce1f995bdeb01673555219c498a971919e0b2fd0ec1f8362484f56ba6a54a2b65503c
data/bin/abt CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/abt.rb'
4
+ require_relative "../lib/abt"
5
5
 
6
6
  begin
7
7
  Abt::Cli.new.perform
8
8
  rescue Abt::Cli::Abort => e
9
- abort e.message
9
+ abort(e.message.strip)
10
10
  rescue Interrupt
11
- abort 'Aborted'
11
+ abort("Aborted")
12
12
  end
data/lib/abt.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-inflector'
4
- require 'faraday'
5
- require 'oj'
6
- require 'open3'
7
- require 'stringio'
8
- require 'optparse'
3
+ require "dry-inflector"
4
+ require "faraday"
5
+ require "oj"
6
+ require "open3"
7
+ require "stringio"
8
+ require "optparse"
9
9
 
10
10
  Dir.glob("#{File.dirname(File.absolute_path(__FILE__))}/abt/*.rb").sort.each do |file|
11
11
  require file
data/lib/abt/ari.rb CHANGED
@@ -4,7 +4,7 @@ module Abt
4
4
  class Ari
5
5
  attr_reader :scheme, :path, :flags
6
6
 
7
- def initialize(scheme:, path: nil, flags: [])
7
+ def initialize(scheme: nil, path: nil, flags: [])
8
8
  @scheme = scheme
9
9
  @path = path
10
10
  @flags = flags
@@ -14,7 +14,7 @@ module Abt
14
14
  str = scheme
15
15
  str += ":#{path}" if path
16
16
 
17
- [str, *flags].join(' ')
17
+ [str, *flags].join(" ")
18
18
  end
19
19
  end
20
20
  end
data/lib/abt/ari_list.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Abt
4
4
  class AriList < Array
5
5
  def to_s
6
- map(&:to_s).join(' -- ')
6
+ map(&:to_s).join(" -- ")
7
7
  end
8
8
 
9
9
  def -(other)
@@ -5,11 +5,11 @@ module Abt
5
5
  extend Forwardable
6
6
 
7
7
  def self.usage
8
- raise NotImplementedError, 'Command classes must implement .usage'
8
+ raise NotImplementedError, "Command classes must implement .usage"
9
9
  end
10
10
 
11
11
  def self.description
12
- raise NotImplementedError, 'Command classes must implement .description'
12
+ raise NotImplementedError, "Command classes must implement .description"
13
13
  end
14
14
 
15
15
  def self.flags
@@ -27,7 +27,7 @@ module Abt
27
27
  end
28
28
 
29
29
  def perform
30
- raise NotImplementedError, 'Command classes must implement #perform'
30
+ raise NotImplementedError, "Command classes must implement #perform"
31
31
  end
32
32
 
33
33
  private
@@ -41,18 +41,18 @@ module Abt
41
41
 
42
42
  result
43
43
  rescue OptionParser::InvalidOption => e
44
- abort e.message
44
+ abort(e.message)
45
45
  end
46
46
 
47
47
  def flag_parser
48
48
  @flag_parser ||= OptionParser.new do |opts|
49
49
  opts.banner = <<~TXT
50
- #{self.class.description}
50
+ #{self.class.description.strip}
51
51
 
52
- Usage: #{self.class.usage}
52
+ Usage: #{self.class.usage.strip}
53
53
  TXT
54
54
 
55
- opts.on('-h', '--help')
55
+ opts.on("-h", "--help", "Display this help")
56
56
 
57
57
  self.class.flags.each do |(*flag)|
58
58
  opts.on(*flag)
data/lib/abt/cli.rb CHANGED
@@ -7,11 +7,12 @@ end
7
7
  module Abt
8
8
  class Cli
9
9
  class Abort < StandardError; end
10
+
10
11
  class Exit < StandardError; end
11
12
 
12
13
  attr_reader :command, :aris, :input, :output, :err_output, :prompt
13
14
 
14
- def initialize(argv: ARGV, input: STDIN, output: STDOUT, err_output: STDERR)
15
+ def initialize(argv: ARGV, input: $stdin, output: $stdout, err_output: $stderr)
15
16
  (@command, *remaining_args) = argv
16
17
  @input = input
17
18
  @output = output
@@ -21,11 +22,16 @@ module Abt
21
22
  end
22
23
 
23
24
  def perform
24
- return if handle_global_commands!
25
-
26
- abort('No ARIs') if aris.empty?
25
+ if command.nil?
26
+ warn("No command specified, printing help\n\n")
27
+ @command = "help"
28
+ end
27
29
 
28
- process_aris
30
+ if global_command?
31
+ process_global_command
32
+ else
33
+ process_aris
34
+ end
29
35
  end
30
36
 
31
37
  def print_ari(scheme, path, description = nil)
@@ -56,29 +62,23 @@ module Abt
56
62
 
57
63
  private
58
64
 
59
- def handle_global_commands!
60
- case command
61
- when nil
62
- warn("No command specified\n\n")
63
- puts(Abt::Docs::Cli.help)
64
- true
65
- when '--version', '-v', 'version'
66
- puts(Abt::VERSION)
67
- true
68
- when '--help', '-h', 'help'
69
- puts(Abt::Docs::Cli.help)
70
- true
71
- when 'commands'
72
- puts(Abt::Docs::Cli.commands)
73
- true
74
- when 'examples'
75
- puts(Abt::Docs::Cli.examples)
76
- true
77
- when 'readme'
78
- puts(Abt::Docs::Markdown.readme)
79
- true
80
- else
81
- false
65
+ def global_command?
66
+ return true if aris.empty?
67
+ return true if aris.first.scheme.nil?
68
+
69
+ false
70
+ end
71
+
72
+ def process_global_command
73
+ command_class = GlobalCommands.command_class(command)
74
+
75
+ abort("No such global command: #{command}, perhaps you forgot to add an ARI?") if command_class.nil?
76
+
77
+ begin
78
+ ari = aris.first || Abt::Ari.new
79
+ command_class.new(cli: self, ari: ari).perform
80
+ rescue Exit => e
81
+ puts e.message
82
82
  end
83
83
  end
84
84
 
@@ -88,16 +88,14 @@ module Abt
88
88
  @sanitized_piped_args ||= begin
89
89
  input_string = input.read.strip
90
90
 
91
- abort 'No input from pipe' if input_string.nil? || input_string.empty?
91
+ abort("No input from pipe") if input_string.nil? || input_string.empty?
92
92
 
93
93
  # Exclude comment part of piped input lines
94
- lines_without_comments = input_string.lines.map do |line|
95
- line.split(' # ').first
96
- end
94
+ lines_without_comments = input_string.lines.map { |line| line.split(" # ").first }
97
95
 
98
96
  # Allow multiple ARIs on a single piped input line
99
97
  # TODO: Force the user to pick a single ARI
100
- joined_lines = lines_without_comments.join(' ').strip
98
+ joined_lines = lines_without_comments.join(" ").strip
101
99
  joined_lines.split(/\s+/)
102
100
  end
103
101
  end
@@ -107,26 +105,30 @@ module Abt
107
105
 
108
106
  aris.each do |ari|
109
107
  if used_schemes.include?(ari.scheme)
110
- warn "Dropping command for already used scheme: #{ari}"
108
+ warn("Dropping command for already used scheme: #{ari}")
111
109
  next
112
110
  end
113
111
 
114
- command_class = get_command_class(ari.scheme)
115
- next if command_class.nil?
116
-
117
- print_command(command, ari) if output.isatty
118
- begin
119
- command_class.new(ari: ari, cli: self).perform
120
- rescue Exit => e
121
- puts e.message
122
- end
123
-
124
- used_schemes << ari.scheme
112
+ used_schemes << ari.scheme if process_ari(ari)
125
113
  end
126
114
 
127
115
  return unless used_schemes.empty? && output.isatty
128
116
 
129
- abort 'No providers found for command and ARI(s)'
117
+ abort("No providers found for command and ARI(s)")
118
+ end
119
+
120
+ def process_ari(ari)
121
+ command_class = get_command_class(ari.scheme)
122
+ return false if command_class.nil?
123
+
124
+ print_command(command, ari) if output.isatty
125
+ begin
126
+ command_class.new(ari: ari, cli: self).perform
127
+ rescue Exit => e
128
+ puts e.message
129
+ end
130
+
131
+ true
130
132
  end
131
133
 
132
134
  def get_command_class(scheme)
@@ -137,7 +139,7 @@ module Abt
137
139
  end
138
140
 
139
141
  def print_command(name, ari)
140
- warn "===== #{name.upcase} #{ari} ====="
142
+ warn("===== #{name.upcase} #{ari} =====")
141
143
  end
142
144
  end
143
145
  end
@@ -13,8 +13,11 @@ module Abt
13
13
  result = AriList.new
14
14
  rest = arguments.dup
15
15
 
16
+ # If the first arg is a flag, it's for a global command
17
+ result << Ari.new(flags: take_flags(rest)) if flag?(rest.first)
18
+
16
19
  until rest.empty?
17
- (scheme, path) = rest.shift.split(':')
20
+ (scheme, path) = rest.shift.split(":")
18
21
  flags = take_flags(rest)
19
22
 
20
23
  result << Ari.new(scheme: scheme, path: path, flags: flags)
@@ -37,11 +40,11 @@ module Abt
37
40
  end
38
41
 
39
42
  def flag?(part)
40
- part && part[0] == '-'
43
+ part && part[0] == "-"
41
44
  end
42
45
 
43
46
  def delimiter?(part)
44
- part == '--'
47
+ part == "--"
45
48
  end
46
49
  end
47
50
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir.glob("#{File.expand_path(__dir__)}/global_commands/*.rb").sort.each { |file| require file }
4
+
5
+ module Abt
6
+ class Cli
7
+ module GlobalCommands
8
+ def self.command_names
9
+ constants.sort.map { |constant_name| Helpers.const_to_command(constant_name) }
10
+ end
11
+
12
+ def self.command_class(name)
13
+ name = "help" if [nil, "-h", "--help"].include?(name)
14
+ name = "version" if ["-v", "--version"].include?(name)
15
+
16
+ const_name = Helpers.command_to_const(name)
17
+ return unless const_defined?(const_name)
18
+
19
+ const_get(const_name)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Commands < Abt::BaseCommand
7
+ def self.usage
8
+ "abt commands"
9
+ end
10
+
11
+ def self.description
12
+ "List all abt commands"
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ puts(Abt::Docs::Cli.commands)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Examples < Abt::BaseCommand
7
+ def self.usage
8
+ "abt examples"
9
+ end
10
+
11
+ def self.description
12
+ "Print command examples"
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ puts(Abt::Docs::Cli.examples)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Help < Abt::BaseCommand
7
+ def self.usage
8
+ "abt help"
9
+ end
10
+
11
+ def self.description
12
+ "Print abt usage text"
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ puts(Abt::Docs::Cli.help)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Readme < Abt::BaseCommand
7
+ def self.usage
8
+ "abt readme"
9
+ end
10
+
11
+ def self.description
12
+ "Print markdown readme"
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ puts(Abt::Docs::Markdown.readme)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Share < Abt::BaseCommand
7
+ def self.usage
8
+ "abt share"
9
+ end
10
+
11
+ def self.description
12
+ "Prints all project configuration as a single line of ARIs"
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ warn("Printing project configuration")
19
+ puts share_string
20
+ end
21
+
22
+ def share_string
23
+ @share_string ||= begin
24
+ aris = Abt.schemes.join(" ")
25
+
26
+ input = StringIO.new(aris)
27
+ output = StringIO.new
28
+ Abt::Cli.new(argv: ["share"], output: output, input: input).perform
29
+
30
+ output.string.strip.gsub(/\s+/, " ")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end