abt-cli 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6348f086170cb21625ec22595423cebbca76b0455f6dc2ad552ef072019b3929
4
- data.tar.gz: e53c442f505ba9141e62d2b4c7883ec010c966b4d1deef0d71651b94ea11db93
3
+ metadata.gz: ce59010855d53bf8b8731a680d7adcd21cef4eb93d421174aee893f27350cb1e
4
+ data.tar.gz: 8ac30f3ada5fcc7c75f7a9a91110340d579fd79d8c6226dd4f92a24bdf070d88
5
5
  SHA512:
6
- metadata.gz: 977ff0fbc908433afdf996cdd354bd33ea9a315cfebcbc456f42df731309f0502801516995f0ded85a58f8efcfeb0fe9830dd31c51efcb05f4acb58ddb3e3833
7
- data.tar.gz: 45d25bbae2c077af24c304132703ca8ebc7a0968c04aafc598ca48a66cd3f303fe5cc108e193e24bd8f5cbb09e37d831eeba3518c360bafb1112f4ae443138cd
6
+ metadata.gz: 0cdbbd886589a06d20281e67a8376b3292cd61e432b7b672c968e2c5730a65707cc60d31d179acdcd7ad2a5eab9ebffe15866e08f5001b1922f291007146038b
7
+ data.tar.gz: d0e568a9db4e57207f1cd8d72c789fea3c456f282c6cc1b4a46694767317a0b5c4055d90d53903779c20cd7ecf3c5a0803b07ebafb03b9e07d5ed99f3be14a88
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
@@ -52,7 +52,7 @@ module Abt
52
52
  Usage: #{self.class.usage}
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir.glob("#{File.expand_path(__dir__)}/cli/*.rb").sort.each do |file|
3
+ Dir.glob("#{File.expand_path(__dir__)}/cli/**/*.rb").sort.each do |file|
4
4
  require file
5
5
  end
6
6
 
@@ -9,6 +9,20 @@ module Abt
9
9
  class Abort < StandardError; end
10
10
  class Exit < StandardError; end
11
11
 
12
+ def self.global_command_names
13
+ GlobalCommands.constants.sort.map { |constant_name| Helpers.const_to_command(constant_name) }
14
+ end
15
+
16
+ def self.global_command_class(name)
17
+ name = 'help' if [nil, '-h', '--help'].include?(name)
18
+ name = 'version' if ['-v', '--version'].include?(name)
19
+
20
+ const_name = Helpers.command_to_const(name)
21
+ return unless GlobalCommands.const_defined?(const_name)
22
+
23
+ GlobalCommands.const_get(const_name)
24
+ end
25
+
12
26
  attr_reader :command, :aris, :input, :output, :err_output, :prompt
13
27
 
14
28
  def initialize(argv: ARGV, input: STDIN, output: STDOUT, err_output: STDERR)
@@ -21,11 +35,16 @@ module Abt
21
35
  end
22
36
 
23
37
  def perform
24
- return if handle_global_commands!
25
-
26
- abort('No ARIs') if aris.empty?
38
+ if command.nil?
39
+ warn("No command specified, printing help\n\n")
40
+ @command = 'help'
41
+ end
27
42
 
28
- process_aris
43
+ if global_command?
44
+ process_global_command
45
+ else
46
+ process_aris
47
+ end
29
48
  end
30
49
 
31
50
  def print_ari(scheme, path, description = nil)
@@ -56,29 +75,25 @@ module Abt
56
75
 
57
76
  private
58
77
 
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
78
+ def global_command?
79
+ return true if aris.empty?
80
+ return true if aris.first.scheme.nil?
81
+
82
+ false
83
+ end
84
+
85
+ def process_global_command
86
+ command_class = self.class.global_command_class(command)
87
+
88
+ if command_class.nil?
89
+ abort "No such global command: #{command}, perhaps you forgot to add an ARI?"
90
+ end
91
+
92
+ begin
93
+ ari = aris.first || Abt::Ari.new
94
+ command_class.new(cli: self, ari: ari).perform
95
+ rescue Exit => e
96
+ puts e.message
82
97
  end
83
98
  end
84
99
 
@@ -13,6 +13,13 @@ module Abt
13
13
  result = AriList.new
14
14
  rest = arguments.dup
15
15
 
16
+ # If the arguments start with "-" it means that we are parsing flags for a global command
17
+ if rest.any? && rest.first[0] == '-'
18
+ flags = take_flags(rest)
19
+
20
+ return [Ari.new(flags: flags)]
21
+ end
22
+
16
23
  until rest.empty?
17
24
  (scheme, path) = rest.shift.split(':')
18
25
  flags = take_flags(rest)
@@ -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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abt
4
+ class Cli
5
+ module GlobalCommands
6
+ class Version < Abt::BaseCommand
7
+ def self.usage
8
+ 'abt version'
9
+ end
10
+
11
+ def self.description
12
+ 'Print abt version'
13
+ end
14
+
15
+ attr_reader :cli
16
+
17
+ def perform
18
+ puts(Abt::VERSION)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/abt/docs.rb CHANGED
@@ -45,8 +45,24 @@ module Abt
45
45
  end
46
46
 
47
47
  def providers
48
- @providers ||= Abt.schemes.sort.each_with_object({}) do |scheme, definition|
49
- definition[scheme] = command_definitions(scheme)
48
+ @providers ||= begin
49
+ providers = {}
50
+
51
+ global_command_names = Abt::Cli.global_command_names
52
+ providers['Global'] = global_command_names.each_with_object({}) do |name, definition|
53
+ command_class = Abt::Cli.global_command_class(name)
54
+ full_name = "abt #{name}"
55
+
56
+ if command_class.respond_to?(:usage) && command_class.respond_to?(:description)
57
+ definition[full_name] = [command_class.usage, command_class.description]
58
+ end
59
+ end
60
+
61
+ Abt.schemes.sort.each_with_object(providers) do |scheme, definition|
62
+ definition[scheme] = command_definitions(scheme)
63
+ end
64
+
65
+ providers
50
66
  end
51
67
  end
52
68
 
@@ -14,9 +14,11 @@ module Abt
14
14
  end
15
15
 
16
16
  def perform
17
- require_project!
18
-
19
- cli.print_ari('asana', path)
17
+ if path != ''
18
+ cli.print_ari('asana', path)
19
+ elsif cli.output.isatty
20
+ warn 'No configuration for project. Did you initialize Asana?'
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -14,9 +14,11 @@ module Abt
14
14
  end
15
15
 
16
16
  def perform
17
- require_board!
18
-
19
- cli.print_ari('devops', path)
17
+ if path != ''
18
+ cli.print_ari('devops', path)
19
+ elsif cli.output.isatty
20
+ warn 'No configuration for project. Did you initialize DevOps?'
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -14,9 +14,11 @@ module Abt
14
14
  end
15
15
 
16
16
  def perform
17
- require_project!
18
-
19
- cli.print_ari('harvest', path)
17
+ if path != ''
18
+ cli.print_ari('harvest', path)
19
+ elsif cli.output.isatty
20
+ warn 'No configuration for project. Did you initialize Harvest?'
21
+ end
20
22
  end
21
23
  end
22
24
  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.20'
4
+ VERSION = '0.0.21'
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.20
4
+ version: 0.0.21
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-03-03 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector
@@ -80,6 +80,12 @@ files:
80
80
  - "./lib/abt/base_command.rb"
81
81
  - "./lib/abt/cli.rb"
82
82
  - "./lib/abt/cli/arguments_parser.rb"
83
+ - "./lib/abt/cli/global_commands/commands.rb"
84
+ - "./lib/abt/cli/global_commands/examples.rb"
85
+ - "./lib/abt/cli/global_commands/help.rb"
86
+ - "./lib/abt/cli/global_commands/readme.rb"
87
+ - "./lib/abt/cli/global_commands/share.rb"
88
+ - "./lib/abt/cli/global_commands/version.rb"
83
89
  - "./lib/abt/cli/prompt.rb"
84
90
  - "./lib/abt/docs.rb"
85
91
  - "./lib/abt/docs/cli.rb"