eac_cli 0.27.3 → 0.27.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13923176efdc8317f5f39295cb3e11e4735d66e7997580af8a5f3c8f2f0c03f4
4
- data.tar.gz: 2f9edad2f2ea7484c88e9948f6c5ff47635b13ddfc2809fa2af481ebd0c347c9
3
+ metadata.gz: e6f469f383ca2343298743bc8ea036286aa17b853950c1fe6563a78a6aaeb00a
4
+ data.tar.gz: 52a728350332e7bb7782d9e9e5bf9302ef77f9101a3ec8bb6eaf230919452c5f
5
5
  SHA512:
6
- metadata.gz: '0918b4794d0ced61971d2f308bb92a731b2c70130774a4e3b68db807fcb94e4a3addaa78488b1a1ab4a38e76557f1bf7fd0a1b5198dc545eefbeecfc5db5b593'
7
- data.tar.gz: 6feb7e12b85ded5683858a2943390f95f092b79b4023f193c3792f24d3ed6e6294ea111f82c667c65dce50ccb005abea0c5db8233dadc6736442ab21c548c75f
6
+ metadata.gz: 32f0d4de473442cd637e159348af166aa6ae2611cd2f67b995f0fe0a4a190265dcd7de17eaadfc73322c35a05febe090a36225cb5b7258fdd39475ec7cd99ecb
7
+ data.tar.gz: 2f681a7a00aac52a079b2a5486654e9a9b2ae5f031aac037ad15e69b1f8840cf154f84041f9ad6a5903e06acabae2aa5b5d350de99341834711a0a24b147fba9
@@ -39,10 +39,6 @@ module EacCli
39
39
  self.description = description
40
40
  end
41
41
 
42
- def help_formatter
43
- @help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
44
- end
45
-
46
42
  def main_alternative
47
43
  @main_alternative ||= begin
48
44
  r = ::EacCli::Definition::Alternative.new
@@ -33,7 +33,7 @@ module EacCli
33
33
  # @return [EacCli::Definition::BaseOption] The option collected.
34
34
  def short_option_collect_char(char)
35
35
  option = find_short_option(char)
36
- raise_error "Invalid short option \"#{char}\"" unless option
36
+ raise_argv_current_invalid_option unless option
37
37
 
38
38
  option_collect_option(option)
39
39
  end
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/speaker'
4
- require 'eac_ruby_utils/speaker'
3
+ require 'eac_cli/definition'
4
+ require 'eac_cli/runner/class_runner'
5
5
 
6
6
  module EacCli
7
7
  module Runner
8
8
  module AfterClassMethods
9
+ # @return [EacCli::Runner::ClassRunner]
10
+ def class_runner(runner_context_args)
11
+ ::EacCli::Runner::ClassRunner.new(self, runner_context_args)
12
+ end
13
+
9
14
  def create(*runner_context_args)
10
- r = new
11
- r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
12
- r
15
+ class_runner(runner_context_args).create
13
16
  end
14
17
 
15
18
  def run(*runner_context_args)
16
- on_asserted_speaker do
17
- r = create(*runner_context_args)
18
- r.run_run
19
- r
20
- end
19
+ class_runner(runner_context_args).run
21
20
  end
22
21
 
23
22
  def runner_definition(&block)
@@ -29,18 +28,6 @@ module EacCli
29
28
  def super_runner_definition
30
29
  superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
31
30
  end
32
-
33
- private
34
-
35
- def on_asserted_speaker
36
- if ::EacRubyUtils::Speaker.context.optional_current
37
- yield
38
- else
39
- ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
40
- yield
41
- end
42
- end
43
- end
44
31
  end
45
32
  end
46
33
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/speaker'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/speaker'
6
+
7
+ module EacCli
8
+ module Runner
9
+ class ClassRunner
10
+ PARSER_ERROR_EXIT_CODE = 1
11
+
12
+ common_constructor :klass, :context_args
13
+
14
+ def create
15
+ r = klass.new
16
+ r.runner_context = ::EacCli::Runner::Context.new(r, *context_args)
17
+ r
18
+ end
19
+
20
+ def run
21
+ on_asserted_speaker do
22
+ r = create
23
+ begin
24
+ r.run_run
25
+ rescue ::EacCli::Parser::Error => e
26
+ run_parser_error(r, e)
27
+ end
28
+ r
29
+ end
30
+ end
31
+
32
+ def run_parser_error(runner_instance, error)
33
+ $stderr.write("#{runner_instance.program_name}: #{error}\n")
34
+ ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
35
+ end
36
+
37
+ private
38
+
39
+ def on_asserted_speaker
40
+ if ::EacRubyUtils::Speaker.context.optional_current
41
+ yield
42
+ else
43
+ ::EacRubyUtils::Speaker.context.on(::EacCli::Speaker.new) do
44
+ yield
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -3,22 +3,13 @@
3
3
  module EacCli
4
4
  module Runner
5
5
  module InstanceMethods
6
- PARSER_ERROR_EXIT_CODE = 1
7
-
8
6
  def run_run
9
7
  parsed
10
8
  run_callbacks(:run) { run }
11
- rescue ::EacCli::Parser::Error => e
12
- run_parser_error(e)
13
9
  rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
14
10
  # Do nothing
15
11
  end
16
12
 
17
- def run_parser_error(error)
18
- $stderr.write("#{program_name}: #{error}\n")
19
- ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
20
- end
21
-
22
13
  def runner_context
23
14
  return @runner_context if @runner_context
24
15
 
@@ -7,18 +7,19 @@ module EacCli
7
7
  module Help
8
8
  class Builder
9
9
  class Alternative
10
- PROGRAM_MACRO = '__PROGRAM__'
10
+ enable_method_class
11
+
11
12
  SUBCOMMANDS_MACRO = '__SUBCOMMANDS__'
12
13
 
13
- common_constructor :alternative
14
+ common_constructor :builder, :alternative
14
15
 
15
- def to_s
16
+ def result
16
17
  (
17
- [PROGRAM_MACRO] +
18
+ program_name +
18
19
  alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
19
20
  options +
20
21
  positionals
21
- ).join(::EacCli::RunnerWith::Help::Builder::SEP)
22
+ ).join(builder.word_separator)
22
23
  end
23
24
 
24
25
  def options
@@ -49,6 +50,12 @@ module EacCli
49
50
  r
50
51
  end
51
52
  end
53
+
54
+ def program_name
55
+ r = builder.runner.program_name
56
+ r = [r] unless r.is_a?(::Enumerable)
57
+ r
58
+ end
52
59
  end
53
60
  end
54
61
  end
@@ -6,8 +6,8 @@ module EacCli
6
6
  module RunnerWith
7
7
  module Help
8
8
  class Builder
9
- require_sub __FILE__
10
- common_constructor :definition
9
+ require_sub __FILE__, require_dependency: true
10
+ common_constructor :runner
11
11
 
12
12
  SEP = ' '
13
13
  IDENT = SEP * 2
@@ -28,11 +28,21 @@ module EacCli
28
28
 
29
29
  def option_usage_full(option)
30
30
  if option.long.present?
31
- [option.short, option_long(option)].reject(&:blank?).join(SEP)
31
+ [option.short, option_long(option)].reject(&:blank?).join(word_separator)
32
32
  else
33
33
  option_short(option)
34
34
  end
35
35
  end
36
+
37
+ def word_separator
38
+ SEP
39
+ end
40
+ end
41
+
42
+ delegate :word_separator, to: :class
43
+
44
+ def definition
45
+ runner.class.runner_definition
36
46
  end
37
47
 
38
48
  def option_definition(option)
@@ -45,8 +55,7 @@ module EacCli
45
55
  b = include_header ? "#{header.humanize}:\n" : ''
46
56
  b += send("self_#{header}") + "\n"
47
57
  definition.alternatives.each do |alternative|
48
- b += IDENT + ::EacCli::RunnerWith::Help::Builder::Alternative.new(alternative).to_s +
49
- "\n"
58
+ b += IDENT + self.alternative(alternative) + "\n"
50
59
  end
51
60
  b
52
61
  end
@@ -60,7 +69,7 @@ module EacCli
60
69
  def usage_section
61
70
  "Usage:\n" +
62
71
  definition.alternatives.map do |alternative|
63
- IDENT + ::EacCli::RunnerWith::Help::Builder::Alternative.new(alternative).to_s + "\n"
72
+ IDENT + self.alternative(alternative) + "\n"
64
73
  end.join
65
74
  end
66
75
 
@@ -6,7 +6,7 @@ require 'eac_ruby_utils/core_ext'
6
6
  module EacCli
7
7
  module RunnerWith
8
8
  module Help
9
- require_sub __FILE__
9
+ require_sub __FILE__, require_dependency: true
10
10
  common_concern do
11
11
  include ::EacCli::Runner
12
12
 
@@ -28,7 +28,7 @@ module EacCli
28
28
  end
29
29
 
30
30
  def help_text
31
- r = ::EacCli::RunnerWith::Help::Builder.new(self.class.runner_definition).to_s
31
+ r = ::EacCli::RunnerWith::Help::Builder.new(self).to_s
32
32
  r += help_extra_text if respond_to?(:help_extra_text)
33
33
  r
34
34
  end
@@ -12,6 +12,14 @@ module EacCli
12
12
  def runner?(object)
13
13
  ::EacCli::Runner.runner?(object)
14
14
  end
15
+
16
+ # @return [Hash<String, EacCli::Runner>]
17
+ def subcommands_from_module(a_module)
18
+ a_module.constants
19
+ .map { |name| [name.to_s.underscore.gsub('_', '-'), a_module.const_get(name)] }
20
+ .select { |c| runner?(c[1]) }
21
+ .to_h.with_indifferent_access
22
+ end
15
23
  end
16
24
 
17
25
  common_concern do
@@ -26,11 +34,9 @@ module EacCli
26
34
  @available_subcommands ||= available_subcommands_auto.merge(available_subcommands_extra)
27
35
  end
28
36
 
37
+ # @return [Hash<String, EacCli::Runner>]
29
38
  def available_subcommands_auto
30
- self.class.constants
31
- .map { |name| [name.to_s.underscore.gsub('_', '-'), self.class.const_get(name)] }
32
- .select { |c| ::EacCli::RunnerWith::Subcommands.runner?(c[1]) }
33
- .to_h.with_indifferent_access
39
+ ::EacCli::RunnerWith::Subcommands.subcommands_from_module(self.class)
34
40
  end
35
41
 
36
42
  def available_subcommands_extra
@@ -104,7 +110,7 @@ module EacCli
104
110
  end
105
111
 
106
112
  def subcommand_program
107
- subcommand_name
113
+ [program_name, subcommand_name]
108
114
  end
109
115
 
110
116
  def subcommand_runner
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.27.3'
4
+ VERSION = '0.27.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.3
4
+ version: 0.27.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.83'
47
+ version: '0.95'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.83'
54
+ version: '0.95'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: eac_ruby_gem_support
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +86,6 @@ files:
86
86
  - lib/eac_cli/definition/base_option.rb
87
87
  - lib/eac_cli/definition/base_option/initialize_args_parser.rb
88
88
  - lib/eac_cli/definition/boolean_option.rb
89
- - lib/eac_cli/definition/help_formatter.rb
90
89
  - lib/eac_cli/definition/positional_argument.rb
91
90
  - lib/eac_cli/enum.rb
92
91
  - lib/eac_cli/old_configs.rb
@@ -112,6 +111,7 @@ files:
112
111
  - lib/eac_cli/rspec/setup.rb
113
112
  - lib/eac_cli/runner.rb
114
113
  - lib/eac_cli/runner/after_class_methods.rb
114
+ - lib/eac_cli/runner/class_runner.rb
115
115
  - lib/eac_cli/runner/context.rb
116
116
  - lib/eac_cli/runner/exit.rb
117
117
  - lib/eac_cli/runner/instance_methods.rb
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner_with/help/builder/alternative'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module EacCli
7
- class Definition
8
- class HelpFormatter
9
- SEP = ' '
10
- IDENT = SEP * 2
11
- OPTION_DESC_SEP = IDENT * 2
12
-
13
- class << self
14
- def option_long(option)
15
- b = option.long
16
- b += '=VALUE' if option.argument?
17
- b
18
- end
19
-
20
- def option_short(option)
21
- b = option.short
22
- b += 'VALUE' if option.argument?
23
- b
24
- end
25
- end
26
-
27
- common_constructor :definition
28
-
29
- def positional_argument(positional)
30
- if positional.subcommand?
31
- ::EacCli::RunnerWith::Help::Builder::Alternative::SUBCOMMANDS_MACRO
32
- else
33
- r = "<#{positional.name}>"
34
- r += '...' if positional.repeat?
35
- r = "[#{r}]" if positional.optional?
36
- r
37
- end
38
- end
39
-
40
- def section(header, include_header = true)
41
- b = include_header ? "#{header.humanize}:\n" : ''
42
- b += send("self_#{header}") + "\n"
43
- # TO-DO: implement alternatives
44
- b
45
- end
46
-
47
- def self_options
48
- definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
49
- end
50
-
51
- def self_usage
52
- IDENT + self_usage_arguments.join(SEP)
53
- end
54
-
55
- def self_usage_arguments
56
- [::EacCli::RunnerWith::Help::Builder::Alternative::PROGRAM_MACRO] +
57
- definition.options_argument.if_present([]) { |_v| ['[options]'] } +
58
- self_usage_arguments_options +
59
- self_usage_arguments_positional
60
- end
61
-
62
- def self_usage_arguments_options
63
- definition.options.select(&:show_on_usage?).map do |option|
64
- self.class.option_long(option)
65
- end
66
- end
67
-
68
- def self_usage_arguments_positional
69
- definition.positional.map { |p| positional_argument(p) }
70
- end
71
-
72
- def to_banner
73
- "#{definition.description}\n\n#{section('usage')}"
74
- end
75
- end
76
- end
77
- end