abt-cli 0.0.20 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
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 +71 -56
  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 -14
  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 +37 -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: 6348f086170cb21625ec22595423cebbca76b0455f6dc2ad552ef072019b3929
4
- data.tar.gz: e53c442f505ba9141e62d2b4c7883ec010c966b4d1deef0d71651b94ea11db93
3
+ metadata.gz: 3af480b982ad0feef367f157d2658f5dd7a3059de13f7098ff267fd06b53fd47
4
+ data.tar.gz: 15b6177165d60fa0bc76c0ac201755d9fb987c62b98e97784ebd2eb5748f12bf
5
5
  SHA512:
6
- metadata.gz: 977ff0fbc908433afdf996cdd354bd33ea9a315cfebcbc456f42df731309f0502801516995f0ded85a58f8efcfeb0fe9830dd31c51efcb05f4acb58ddb3e3833
7
- data.tar.gz: 45d25bbae2c077af24c304132703ca8ebc7a0968c04aafc598ca48a66cd3f303fe5cc108e193e24bd8f5cbb09e37d831eeba3518c360bafb1112f4ae443138cd
6
+ metadata.gz: 9eb5c49b996574004c1abffffad6aef76e3bc8ad7ea3fcbf0e05e2b0b33788d01cd041e031f5e98c85b86b7aee442ce8b2ac11995944a1e8d8674053736a6f9b
7
+ data.tar.gz: 16278e95b9d5e25a7b2fb7dc931e140b732638ce767e99b20a9b7b442a560b6e56abf982f42a65b7dd97973d58332854915421d26cac686a8af8965a0dcaa148
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