avm-tools 0.76.0 → 0.76.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +7 -16
  3. data/lib/avm/tools/version.rb +1 -1
  4. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  5. data/vendor/eac_cli/lib/eac_cli/definition.rb +35 -3
  6. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  7. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  8. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  9. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  10. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  11. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +27 -64
  12. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +17 -0
  13. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +47 -19
  14. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  15. data/vendor/eac_cli/lib/eac_cli/runner.rb +4 -0
  16. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  17. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  18. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
  19. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +48 -40
  20. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  21. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  22. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  23. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  24. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  25. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  26. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  27. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  28. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 523777fd378f3ba655e65b12e452660f192e2875791439146808c472ee5cd982
4
- data.tar.gz: 253dabfb78beaefa4b40dcfe6f669ae0e74761cb63a2e3418fda41ca8e107d2f
3
+ metadata.gz: cd41b3c790de4a2264c78b5daa5afbd469de6ba2e74b616f096619d0a7bc5460
4
+ data.tar.gz: 0a1890b253e90debb2951fe90193fef541df4c4d0701dcf82712696377b1adbe
5
5
  SHA512:
6
- metadata.gz: 7208ff787a4d219d9a66b9e6e978dbf51cb142ea6af94b4347f9fc7f56c478962113b775896d52351fc35bea6fad3b796c9d5387af70c491a56542cd42872d25
7
- data.tar.gz: 77004875dc073ea43aca01a5a3c4bbbf178fed773056bae70206745ce6d677ebfdf797871a0e5a8196eac1fd30774ab49e0e6b7503009abc22e0f278e5e6aaf0
6
+ metadata.gz: 2ebb73966071bb959e16f10f37b784971f65b3f2cfede241fe4b02c127f24d057bbaedec098e900b8b69edf55e5951637f905a07d5a242d0b7bfd7b51907a3be
7
+ data.tar.gz: 510d2e7625a10c523269684a6e269212a5d8b027d671dc38e337be9c1015d9c69d4ba8f78049ee13090a9e6c733fabfd6b5d40541b6ddbd1e86cd8b4e524ba7c
@@ -1,23 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_cli/core_ext'
3
4
  require 'avm/eac_rails_base1/runner/code_runner'
4
- require 'eac_cli/default_runner'
5
5
 
6
6
  module Avm
7
7
  module Tools
8
8
  class Runner < ::EacRubyUtils::Console::DocoptRunner
9
9
  class EacRedmineBase0 < ::Avm::EacRailsBase1::Runner
10
- class ProjectRename < ::Avm::EacRailsBase1::Runner::CodeRunner
11
- include ::EacCli::DefaultRunner
12
-
13
- runner_definition do
10
+ class ProjectRename
11
+ runner_with ::Avm::EacRailsBase1::RunnerWith::Bundle do
14
12
  pos_arg :from
15
13
  pos_arg :to
16
14
  end
17
15
 
18
16
  def run
19
- start_banner
20
- command.system!
17
+ bundle_run
21
18
  end
22
19
 
23
20
  def start_banner
@@ -25,16 +22,10 @@ module Avm
25
22
  infov 'To', to
26
23
  end
27
24
 
28
- def from
29
- options.fetch('<from>')
30
- end
31
-
32
- def to
33
- options.fetch('<to>')
34
- end
25
+ delegate :from, :to, to: :parsed
35
26
 
36
- def command
37
- context(:instance).bundle('exec', 'rails', 'runner', code)
27
+ def bundle_args
28
+ %w[exec rails runner] + [code]
38
29
  end
39
30
 
40
31
  def code
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.76.0'
5
+ VERSION = '0.76.1'
6
6
  end
7
7
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*', 'Gemfile']
14
14
 
15
- s.add_dependency 'eac_ruby_utils', '~> 0.45'
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.50'
16
16
 
17
17
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
18
18
  end
@@ -8,6 +8,10 @@ require 'eac_ruby_utils/core_ext'
8
8
  module EacCli
9
9
  class Definition
10
10
  require_sub __FILE__
11
+
12
+ SUBCOMMAND_NAME_ARG = 'subcommand'
13
+ SUBCOMMAND_ARGS_ARG = 'subcommand_args'
14
+
11
15
  attr_accessor :description
12
16
  attr_accessor :options_argument
13
17
 
@@ -41,6 +45,10 @@ module EacCli
41
45
  self.description = description
42
46
  end
43
47
 
48
+ def help_formatter
49
+ @help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
50
+ end
51
+
44
52
  def options_arg(options_argument)
45
53
  self.options_argument = options_argument
46
54
  end
@@ -50,15 +58,33 @@ module EacCli
50
58
  end
51
59
 
52
60
  def pos_arg(name, arg_options = {})
53
- positional << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
61
+ new_pos_arg = ::EacCli::Definition::PositionalArgument.new(name, arg_options)
62
+ raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
63
+
64
+ pos_set << new_pos_arg
54
65
  end
55
66
 
56
67
  def positional
57
- @positional ||= []
68
+ pos_set.to_a
69
+ end
70
+
71
+ def positional_arguments_blocked?(new_pos_arg)
72
+ last = pos_set.last
73
+ return false unless last
74
+ return true if last.repeat?
75
+ return true if last.optional? && new_pos_arg.required?
76
+
77
+ false
58
78
  end
59
79
 
60
80
  def subcommands
61
- positional << ::EacCli::Definition::PositionalArgument.new('subcommand', subcommand: true)
81
+ pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
82
+ pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
83
+ optional: true, repeat: true)
84
+ end
85
+
86
+ def subcommands?
87
+ pos_set.any?(&:subcommand?)
62
88
  end
63
89
 
64
90
  def options_first(enable = true)
@@ -68,5 +94,11 @@ module EacCli
68
94
  def options_first?
69
95
  @options_first ? true : false
70
96
  end
97
+
98
+ private
99
+
100
+ def pos_set
101
+ @pos_set ||= []
102
+ end
71
103
  end
72
104
  end
@@ -5,19 +5,35 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  class Definition
7
7
  class BaseOption
8
+ DEFAULT_REQUIRED = false
9
+
10
+ enable_listable
11
+ lists.add_symbol :option, :optional, :usage, :required
8
12
  attr_reader :short, :long, :description, :options
9
13
 
10
14
  def initialize(short, long, description, options = {})
11
15
  @short = short
12
16
  @long = long
13
17
  @description = description
14
- @options = options.with_indifferent_access
18
+ @options = options.symbolize_keys
19
+ @options.assert_valid_keys(::EacCli::Definition::BaseOption.lists.option.values)
15
20
  end
16
21
 
17
22
  def identifier
18
23
  long.to_s.variableize.to_sym
19
24
  end
20
25
 
26
+ def required?
27
+ return true if options.key?(:required) && options.fetch(:required)
28
+ return false if options.key?(:optional) && options.fetch(:optional)
29
+
30
+ DEFAULT_REQUIRED
31
+ end
32
+
33
+ def to_s
34
+ "#{self.class.name.demodulize}[#{identifier}]"
35
+ end
36
+
21
37
  def show_on_usage?
22
38
  options[:usage]
23
39
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Definition
7
+ class HelpFormatter
8
+ SEP = ' '
9
+ IDENT = SEP * 2
10
+ OPTION_DESC_SEP = IDENT * 2
11
+
12
+ class << self
13
+ def option_long(option)
14
+ b = option.long
15
+ b += '=VALUE' if option.argument?
16
+ b
17
+ end
18
+
19
+ def option_short(option)
20
+ b = option.short
21
+ b += 'VALUE' if option.argument?
22
+ b
23
+ end
24
+ end
25
+
26
+ common_constructor :definition
27
+
28
+ def positional_argument(positional)
29
+ if positional.subcommand?
30
+ ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
31
+ else
32
+ r = "<#{positional.name}>"
33
+ r += '...' if positional.repeat?
34
+ r = "[#{r}]" if positional.optional?
35
+ r
36
+ end
37
+ end
38
+
39
+ def section(header, include_header = true)
40
+ b = include_header ? "#{header.humanize}:\n" : ''
41
+ b += send("self_#{header}") + "\n"
42
+ # TO-DO: implement alternatives
43
+ b
44
+ end
45
+
46
+ def self_options
47
+ definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
48
+ end
49
+
50
+ def self_usage
51
+ IDENT + self_usage_arguments.join(SEP)
52
+ end
53
+
54
+ def self_usage_arguments
55
+ [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
56
+ definition.options_argument.if_present([]) { |_v| ['[options]'] } +
57
+ self_usage_arguments_options +
58
+ self_usage_arguments_positional
59
+ end
60
+
61
+ def self_usage_arguments_options
62
+ definition.options.select(&:show_on_usage?).map do |option|
63
+ self.class.option_long(option)
64
+ end
65
+ end
66
+
67
+ def self_usage_arguments_positional
68
+ definition.positional.map { |p| positional_argument(p) }
69
+ end
70
+
71
+ def to_banner
72
+ "#{definition.description}\n\n#{section('usage')}"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -5,22 +5,39 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  class Definition
7
7
  class PositionalArgument
8
- common_constructor :name, :options, default: [{}]
8
+ DEFAULT_REQUIRED = true
9
+
10
+ enable_listable
11
+ lists.add_symbol :option, :optional, :repeat, :required, :subcommand
12
+ common_constructor :name, :options, default: [{}] do
13
+ options.assert_valid_keys(self.class.lists.option.values)
14
+ end
9
15
 
10
16
  def identifier
11
17
  name.to_s.variableize.to_sym
12
18
  end
13
19
 
14
20
  def optional?
15
- options[:optional]
21
+ !required?
16
22
  end
17
23
 
18
24
  def repeat?
19
- options[:repeat]
25
+ options[OPTION_REPEAT]
26
+ end
27
+
28
+ def required?
29
+ return true if options.key?(OPTION_REQUIRED) && options.fetch(OPTION_REQUIRED)
30
+ return false if options.key?(OPTION_OPTIONAL) && options.fetch(OPTION_OPTIONAL)
31
+
32
+ DEFAULT_REQUIRED
20
33
  end
21
34
 
22
35
  def subcommand?
23
- options[:subcommand]
36
+ options[OPTION_SUBCOMMAND]
37
+ end
38
+
39
+ def to_s
40
+ "#{self.class.name.demodulize}[#{identifier}]"
24
41
  end
25
42
  end
26
43
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_cli/docopt/doc_builder'
4
+ require 'eac_cli/runner'
4
5
  require 'eac_ruby_utils/console/docopt_runner'
5
6
 
6
7
  module EacCli
@@ -31,6 +31,10 @@ module EacCli
31
31
  end
32
32
  end
33
33
 
34
+ def supplied?(option)
35
+ data[option].present?
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def data
@@ -6,28 +6,46 @@ require 'optparse'
6
6
  module EacCli
7
7
  class Parser
8
8
  class OptionsCollection
9
- SEP = ' '
10
- IDENT = SEP * 2
11
- OPTION_DESC_SEP = IDENT * 2
12
-
13
9
  enable_simple_cache
14
10
  common_constructor(:definition, :argv, :collector) { collect }
15
11
  attr_reader :arguments
16
12
 
13
+ def options_first?
14
+ definition.options_first? || definition.subcommands?
15
+ end
16
+
17
17
  private
18
18
 
19
+ def check_required_options
20
+ definition.options.each do |option|
21
+ next unless option.required?
22
+ next if collector.supplied?(option)
23
+
24
+ raise ::EacCli::Parser::Error.new(
25
+ definition, argv, "Option \"#{option}\" is required and a value was not supplied"
26
+ )
27
+ end
28
+ end
29
+
19
30
  def collect
20
31
  build_banner
21
32
  build_options
22
- @arguments = option_parser.parse(argv)
33
+ parse_argv
34
+ check_required_options
23
35
  end
24
36
 
25
37
  def option_parser_uncached
26
38
  ::OptionParser.new
27
39
  end
28
40
 
41
+ def parse_argv
42
+ @arguments = options_first? ? option_parser.order(argv) : option_parser.parse(argv)
43
+ rescue ::OptionParser::InvalidOption => e
44
+ raise ::EacCli::Parser::Error.new(definition, argv, e.message)
45
+ end
46
+
29
47
  def build_banner
30
- option_parser.banner = "#{definition.description}\n\n#{section('usage')}"
48
+ option_parser.banner = definition.help_formatter.to_banner
31
49
  end
32
50
 
33
51
  def build_options
@@ -38,68 +56,13 @@ module EacCli
38
56
 
39
57
  def build_option(option)
40
58
  option_parser.on(
41
- *[option_short(option), option_long(option), option.description].reject(&:blank?)
59
+ *[::EacCli::Definition::HelpFormatter.option_short(option),
60
+ ::EacCli::Definition::HelpFormatter.option_long(option),
61
+ option.description].reject(&:blank?)
42
62
  ) do |value|
43
63
  collector.collect(option, value)
44
64
  end
45
65
  end
46
-
47
- def positional_argument(positional)
48
- if positional.subcommand?
49
- ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
50
- else
51
- r = "<#{positional.name}>"
52
- r += '...' if positional.repeat?
53
- r = "[#{r}]" if positional.optional?
54
- r
55
- end
56
- end
57
-
58
- def option_argument(option)
59
- option_long(option)
60
- end
61
-
62
- def option_long(option)
63
- b = option.long
64
- b += '=VALUE' if option.argument?
65
- b
66
- end
67
-
68
- def option_short(option)
69
- b = option.short
70
- b += 'VALUE' if option.argument?
71
- b
72
- end
73
-
74
- def section(header, include_header = true)
75
- b = include_header ? "#{header.humanize}:\n" : ''
76
- b += send("self_#{header}") + "\n"
77
- # TO-DO: implement alternatives
78
- b
79
- end
80
-
81
- def self_options
82
- definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
83
- end
84
-
85
- def self_usage
86
- IDENT + self_usage_arguments.join(SEP)
87
- end
88
-
89
- def self_usage_arguments
90
- [::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
91
- definition.options_argument.if_present([]) { |_v| ['[options]'] } +
92
- self_usage_arguments_options +
93
- self_usage_arguments_positional
94
- end
95
-
96
- def self_usage_arguments_options
97
- definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
98
- end
99
-
100
- def self_usage_arguments_positional
101
- definition.positional.map { |p| positional_argument(p) }
102
- end
103
66
  end
104
67
  end
105
68
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_cli/parser/error'
3
4
  require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module EacCli
@@ -8,6 +9,20 @@ module EacCli
8
9
  common_constructor :definition, :argv
9
10
 
10
11
  def result
12
+ result_or_error = parse(definition)
13
+ return result_or_error unless result_or_error.is_a?(::Exception)
14
+
15
+ definition.alternatives.each do |alternative|
16
+ alt_result_or_error = parse(alternative)
17
+ return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
18
+ end
19
+
20
+ raise result_or_error
21
+ end
22
+
23
+ private
24
+
25
+ def parse(definition)
11
26
  ::EacCli::Parser::Collector.to_data(definition) do |collector|
12
27
  ::EacCli::Parser::PositionalCollection.new(
13
28
  definition,
@@ -15,6 +30,8 @@ module EacCli
15
30
  collector
16
31
  )
17
32
  end
33
+ rescue ::EacCli::Parser::Error => e
34
+ e
18
35
  end
19
36
  end
20
37
  end
@@ -10,39 +10,67 @@ module EacCli
10
10
 
11
11
  private
12
12
 
13
+ def argv_enum
14
+ @argv_enum ||= argv.each
15
+ end
16
+
17
+ def argv_pending?
18
+ argv_enum.ongoing?
19
+ end
20
+
21
+ def argv_pending_check
22
+ return unless argv_pending?
23
+ return unless positional_enum.stopped?
24
+
25
+ raise ::EacCli::Parser::Error.new(
26
+ definition, argv, "No positional left for argv \"#{argv_enum.current}\""
27
+ )
28
+ end
29
+
13
30
  def collected
14
31
  @collected ||= ::Set.new
15
32
  end
16
33
 
17
34
  def collect
18
- argv.each { |argv_value| colect_argv_value(argv_value) }
19
- return unless pending_required_positional?
35
+ loop do
36
+ break unless enums('pending?').any?
20
37
 
21
- raise ::EacCli::Parser::Error.new(
22
- definition, argv, 'No value for required positional ' \
23
- "\"#{current_positional.identifier}\""
24
- )
38
+ enums('pending_check')
39
+ collect_argv_value
40
+ end
41
+ end
42
+
43
+ def collect_argv_value
44
+ collector.collect(*enums('enum', &:peek))
45
+ collected << positional_enum.peek
46
+ positional_enum.next unless positional_enum.peek.repeat?
47
+ argv_enum.next
25
48
  end
26
49
 
27
- def colect_argv_value(argv_value)
28
- collector.collect(current_positional, argv_value)
29
- collected << current_positional
30
- positional_enumerator.next unless current_positional.repeat?
50
+ def enums(method_suffix, &block)
51
+ %w[positional argv].map do |method_prefix|
52
+ v = send("#{method_prefix}_#{method_suffix}")
53
+ block ? block.call(v) : v
54
+ end
31
55
  end
32
56
 
33
- def pending_required_positional?
34
- !(current_positional.blank? || current_positional.optional? ||
35
- collected.include?(current_positional))
57
+ def positional_enum
58
+ @positional_enum ||= definition.positional.each
36
59
  end
37
60
 
38
- def positional_enumerator
39
- @positional_enumerator ||= definition.positional.each
61
+ def positional_pending?
62
+ !(positional_enum.stopped? || positional_enum.current.optional? ||
63
+ collected.include?(positional_enum.current))
40
64
  end
41
65
 
42
- def current_positional
43
- positional_enumerator.peek
44
- rescue ::StopIteration
45
- nil
66
+ def positional_pending_check
67
+ return unless positional_pending?
68
+ return unless argv_enum.stopped?
69
+
70
+ raise ::EacCli::Parser::Error.new(
71
+ definition, argv, 'No value for required positional ' \
72
+ "\"#{positional_enum.current.identifier}\""
73
+ )
46
74
  end
47
75
  end
48
76
  end
@@ -5,13 +5,14 @@ require 'eac_cli/runner'
5
5
  require 'eac_cli/runner_with'
6
6
 
7
7
  class Object
8
- def runner_with(*runners)
8
+ def runner_with(*runners, &block)
9
9
  include ::EacCli::Runner
10
10
  enable_simple_cache
11
11
  enable_console_speaker
12
12
  runners.each do |runner|
13
13
  include runner_with_to_module(runner)
14
14
  end
15
+ runner_definition(&block) if block
15
16
  end
16
17
 
17
18
  private
@@ -18,6 +18,10 @@ module EacCli
18
18
  end
19
19
  end
20
20
 
21
+ def runner?(object)
22
+ object.is_a?(::Class) && object.included_modules.include?(::EacCli::Runner)
23
+ end
24
+
21
25
  private
22
26
 
23
27
  def alias_class_method(klass, from, to)
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module Subcommands
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+ end
12
+
13
+ EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
14
+
15
+ def available_subcommands
16
+ @available_subcommands ||= available_subcommands_auto.merge(available_subcommands_extra)
17
+ end
18
+
19
+ def available_subcommands_auto
20
+ self.class.constants
21
+ .map { |name| [name.to_s.underscore.gsub('_', '-'), self.class.const_get(name)] }
22
+ .select { |c| ::EacCli::Runner.runner?(c[1]) }
23
+ .to_h.with_indifferent_access
24
+ end
25
+
26
+ def available_subcommands_extra
27
+ if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
28
+ send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
29
+ else
30
+ {}
31
+ end
32
+ end
33
+
34
+ def method_missing(method_name, *arguments, &block)
35
+ return run_with_subcommand(*arguments, &block) if
36
+ run_with_subcommand_alias_run?(method_name)
37
+
38
+ super
39
+ end
40
+
41
+ def respond_to_missing?(method_name, include_private = false)
42
+ run_with_subcommand_alias_run?(method_name) || super
43
+ end
44
+
45
+ def run_with_subcommand
46
+ if subcommand_name
47
+ subcommand_runner.run
48
+ else
49
+ run_without_subcommand
50
+ end
51
+ end
52
+
53
+ def run_with_subcommand_alias_run?(method_name)
54
+ subcommands? && method_name.to_sym == :run
55
+ end
56
+
57
+ def run_without_subcommand
58
+ "Method #{__method__} should be overrided in #{self.class.name}"
59
+ end
60
+
61
+ def subcommands?
62
+ self.class.runner_definition.subcommands?
63
+ end
64
+
65
+ def subcommand_args
66
+ parsed.fetch(::EacCli::Definition::SUBCOMMAND_ARGS_ARG)
67
+ end
68
+
69
+ def subcommand_class
70
+ available_subcommands[subcommand_name].if_present { |v| return v }
71
+
72
+ raise(::EacCli::Parser::Error.new(
73
+ self.class.runner_definition, runner_context.argv,
74
+ "Subcommand \"#{subcommand_name}\" not found " \
75
+ "(Available: #{available_subcommands.keys}"
76
+ ))
77
+ end
78
+
79
+ def subcommand_name
80
+ parsed.fetch(::EacCli::Definition::SUBCOMMAND_NAME_ARG)
81
+ end
82
+
83
+ def subcommand_program
84
+ subcommand_name
85
+ end
86
+
87
+ def subcommand_runner
88
+ @subcommand_runner ||= subcommand_class.create(
89
+ argv: subcommand_args,
90
+ program_name: subcommand_program,
91
+ parent: self
92
+ )
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.9.0'
4
+ VERSION = '0.11.1'
5
5
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/docopt/runner_extension'
4
+
5
+ RSpec.describe ::EacCli::Docopt::RunnerExtension do
6
+ let(:stub_runner) do
7
+ r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
8
+ def run; end
9
+ end
10
+ r.include ::EacCli::Runner
11
+ r.runner_definition do
12
+ desc 'A stub runner.'
13
+ arg_opt '-o', '--opt1', 'A argument option'
14
+ pos_arg 'pos1'
15
+ end
16
+ r
17
+ end
18
+
19
+ let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
20
+
21
+ before { instance.run }
22
+
23
+ it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
24
+ it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
25
+ end
@@ -4,67 +4,75 @@ require 'eac_ruby_utils/console/docopt_runner'
4
4
  require 'eac_cli/runner'
5
5
 
6
6
  RSpec.describe ::EacCli::Runner do
7
- let(:stub_runner) do
8
- r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
7
+ let(:runner_class) do
8
+ the_module = described_class
9
+ ::Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--opt1', 'A arg option.'
14
+ bool_opt '-o', '--opt2', 'A boolean option'
15
+ pos_arg :pos1
16
+ pos_arg :pos2, repeat: true, optional: true
17
+ alt do
18
+ bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
19
+ end
20
+ end
21
+
9
22
  def run; end
10
23
  end
11
- r.include described_class
12
- r.runner_definition do
13
- desc 'A stub runner.'
14
- arg_opt '-o', '--opt1', 'A argument option'
15
- pos_arg 'pos1'
16
- end
17
- r
18
24
  end
19
25
 
20
- let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
26
+ context 'when all args are supplied' do
27
+ let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
28
+
29
+ it { expect(instance.parsed.opt1).to eq('aaa') }
30
+ it { expect(instance.parsed.opt2?).to eq(true) }
31
+ it { expect(instance.parsed.pos1).to eq('bbb') }
32
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
33
+ end
34
+
35
+ context 'when only required args are supplied' do
36
+ let(:instance) { runner_class.create(%w[bbb]) }
37
+
38
+ it { expect(instance.parsed.opt1).to be_nil }
39
+ it { expect(instance.parsed.opt2?).to eq(false) }
40
+ it { expect(instance.parsed.pos1).to eq('bbb') }
41
+ it { expect(instance.parsed.pos2).to eq([]) }
42
+ end
43
+
44
+ context 'when required args are not supplied' do
45
+ let(:instance) { runner_class.create(%w[]) }
21
46
 
22
- before { instance.run }
47
+ it do
48
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
49
+ end
50
+ end
51
+
52
+ context 'when alternative args are supplied' do
53
+ let(:instance) { runner_class.create(%w[--opt3]) }
23
54
 
24
- it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
25
- it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
55
+ it { expect(instance.parsed.opt3?).to eq(true) }
56
+ end
26
57
 
27
- context 'without docopt runner' do
58
+ context 'when extra args are not supplied' do
28
59
  let(:runner_class) do
29
60
  the_module = described_class
30
61
  ::Class.new do
31
62
  include the_module
32
63
 
33
64
  runner_definition do
34
- arg_opt '-o', '--opt1', 'A arg option.'
35
- bool_opt '-o', '--opt2', 'A boolean option'
36
65
  pos_arg :pos1
37
- pos_arg :pos2, repeat: true, optional: true
38
66
  end
39
67
 
40
68
  def run; end
41
69
  end
42
70
  end
43
71
 
44
- context 'when all args are supplied' do
45
- let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
46
-
47
- it { expect(instance.parsed.opt1).to eq('aaa') }
48
- it { expect(instance.parsed.opt2?).to eq(true) }
49
- it { expect(instance.parsed.pos1).to eq('bbb') }
50
- it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
51
- end
72
+ let(:instance) { runner_class.create(%w[aaa bbb]) }
52
73
 
53
- context 'when only required args are supplied' do
54
- let(:instance) { runner_class.create(%w[bbb]) }
55
-
56
- it { expect(instance.parsed.opt1).to be_nil }
57
- it { expect(instance.parsed.opt2?).to eq(false) }
58
- it { expect(instance.parsed.pos1).to eq('bbb') }
59
- it { expect(instance.parsed.pos2).to eq([]) }
60
- end
61
-
62
- context 'when required args are not supplied' do
63
- let(:instance) { runner_class.create(%w[]) }
64
-
65
- it do
66
- expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
67
- end
74
+ it do
75
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
68
76
  end
69
77
  end
70
78
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_cli/runner_with/subcommands'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Subcommands do
7
+ let(:parent_runner) do
8
+ the_module = described_class
9
+ the_child = child_runner
10
+ Class.new do
11
+ include ::EacCli::Runner
12
+ include the_module
13
+ const_set('ChildCmd', the_child)
14
+
15
+ runner_definition do
16
+ desc 'A stub root runner.'
17
+ arg_opt '-r', '--root-var', 'A root variable.'
18
+ subcommands
19
+ end
20
+
21
+ delegate :root_var, to: :parsed
22
+ end
23
+ end
24
+
25
+ let(:child_runner) do
26
+ ::Class.new do
27
+ include ::EacCli::Runner
28
+
29
+ runner_definition do
30
+ bool_opt '-c', '--child-opt', 'A boolean option.'
31
+ pos_arg :child_var
32
+ end
33
+
34
+ def run; end
35
+ end
36
+ end
37
+
38
+ let(:instance) { parent_runner.create(argv: parent_argv) }
39
+
40
+ context 'when subcommand is supplied' do
41
+ let(:parent_argv) { %w[--root-var 123 child-cmd --child-opt 456] }
42
+
43
+ it { expect(instance.parsed.root_var).to eq('123') }
44
+ it { expect(instance.parsed.subcommand).to eq('child-cmd') }
45
+ it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
46
+ it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
47
+ it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
48
+ end
49
+
50
+ context 'when subcommand is not supplied' do
51
+ let(:instance) { parent_runner.create(%w[456]) }
52
+
53
+ it do
54
+ expect { instance.run }.to raise_error(::EacCli::Parser::Error)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Enumerator
4
+ def current(default_value = nil)
5
+ peek
6
+ rescue ::StopIteration
7
+ default_value
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Enumerator
4
+ def ongoing?
5
+ !stopped?
6
+ end
7
+
8
+ def stopped?
9
+ peek
10
+ false
11
+ rescue ::StopIteration
12
+ true
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ def print_debug
5
+ STDERR.write(to_debug + "\n")
6
+
7
+ self
8
+ end
9
+
10
+ def to_debug
11
+ "|#{self.class}|#{self}|"
12
+ end
13
+
14
+ def raise_debug
15
+ raise to_debug
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.49.1'
4
+ VERSION = '0.51.0'
5
5
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerator/current'
4
+
5
+ RSpec.describe ::Enumerator do
6
+ let(:list) { %w[a b] }
7
+ let(:instance) { list.each }
8
+
9
+ it { expect(instance).to be_a(described_class) }
10
+ it { expect(instance.current).to eq('a') }
11
+
12
+ context 'with first next' do
13
+ before { instance.next }
14
+
15
+ it { expect(instance.current).to eq('b') }
16
+ end
17
+
18
+ context 'with last next' do
19
+ before do
20
+ instance.next
21
+ instance.next
22
+ end
23
+
24
+ it { expect(instance.current).to eq(nil) }
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerator/stopped'
4
+
5
+ RSpec.describe ::Enumerator do
6
+ let(:list) { %w[a b] }
7
+ let(:instance) { list.each }
8
+
9
+ it { expect(instance).to be_a(described_class) }
10
+ it { expect(instance.peek).to eq('a') }
11
+ it { expect(instance).to be_ongoing }
12
+ it { expect(instance).not_to be_stopped }
13
+
14
+ context 'with first next' do
15
+ before { instance.next }
16
+
17
+ it { expect(instance.peek).to eq('b') }
18
+ it { expect(instance).to be_ongoing }
19
+ it { expect(instance).not_to be_stopped }
20
+ end
21
+
22
+ context 'with last next' do
23
+ before do
24
+ instance.next
25
+ instance.next
26
+ end
27
+
28
+ it { expect { instance.peek }.to raise_error(::StopIteration) }
29
+ it { expect(instance).not_to be_ongoing }
30
+ it { expect(instance).to be_stopped }
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.76.0
4
+ version: 0.76.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-14 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -601,6 +601,7 @@ files:
601
601
  - vendor/eac_cli/lib/eac_cli/definition/argument_option.rb
602
602
  - vendor/eac_cli/lib/eac_cli/definition/base_option.rb
603
603
  - vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb
604
+ - vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb
604
605
  - vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb
605
606
  - vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb
606
607
  - vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb
@@ -618,8 +619,11 @@ files:
618
619
  - vendor/eac_cli/lib/eac_cli/runner_with.rb
619
620
  - vendor/eac_cli/lib/eac_cli/runner_with/help.rb
620
621
  - vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb
622
+ - vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb
621
623
  - vendor/eac_cli/lib/eac_cli/version.rb
624
+ - vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb
622
625
  - vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb
626
+ - vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb
623
627
  - vendor/eac_cli/spec/rubocop_spec.rb
624
628
  - vendor/eac_cli/spec/spec_helper.rb
625
629
  - vendor/eac_docker/Gemfile
@@ -959,6 +963,9 @@ files:
959
963
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb
960
964
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb
961
965
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb
966
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb
967
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb
968
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb
962
969
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb
963
970
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb
964
971
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb
@@ -972,6 +979,7 @@ files:
972
979
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/simple_cache.rb
973
980
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb
974
981
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
982
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
975
983
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
976
984
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
977
985
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb
@@ -1030,6 +1038,8 @@ files:
1030
1038
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb
1031
1039
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
1032
1040
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb
1041
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb
1042
+ - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb
1033
1043
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb
1034
1044
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb
1035
1045
  - vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/console_speaker_spec.rb