eac_cli 0.27.2 → 0.27.5
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 +4 -4
- data/lib/eac_cli/definition.rb +0 -4
- data/lib/eac_cli/old_configs/entry_reader.rb +1 -1
- data/lib/eac_cli/old_configs/read_entry_options.rb +1 -1
- data/lib/eac_cli/parser/alternative/short_options.rb +1 -1
- data/lib/eac_cli/parser.rb +2 -2
- data/lib/eac_cli/runner/after_class_methods.rb +9 -22
- data/lib/eac_cli/runner/class_runner.rb +50 -0
- data/lib/eac_cli/runner/instance_methods.rb +0 -9
- data/lib/eac_cli/runner_with/help/builder/alternative.rb +12 -5
- data/lib/eac_cli/runner_with/help/builder.rb +16 -7
- data/lib/eac_cli/runner_with/help.rb +2 -2
- data/lib/eac_cli/runner_with/subcommands.rb +5 -5
- data/lib/eac_cli/runner_with_set.rb +2 -2
- data/lib/eac_cli/version.rb +1 -1
- metadata +7 -7
- data/lib/eac_cli/definition/help_formatter.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 938ea5f13a60ee96410614ad3a2467e1ee172f0edbbf8a853169f0c563f61fc6
|
4
|
+
data.tar.gz: ac6f3fde9506adc953a59e96b8c152037233c7609e8194e65a70534dd2f2e358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc0d1c69a1f274767b42dcd34456c004edf0896623c7791bc87e1d23fdfd92df65b5ce960e84c1341897b196ba4337de16d1c6e517966d0e6340e86059c2ff9c
|
7
|
+
data.tar.gz: f9dd8eb35bb94e9cdf58d78021ef07f7fea1a9437c57300085bc8a835505100bfaa582fdf7d1f76b97a5cf959d3266bd980a33a38e6f6511f6a0cd5b77be7fee
|
data/lib/eac_cli/definition.rb
CHANGED
@@ -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
|
-
|
36
|
+
raise_argv_current_invalid_option unless option
|
37
37
|
|
38
38
|
option_collect_option(option)
|
39
39
|
end
|
data/lib/eac_cli/parser.rb
CHANGED
@@ -19,12 +19,12 @@ module EacCli
|
|
19
19
|
|
20
20
|
def alternatives_parsed(error)
|
21
21
|
alternatives.select { |a| error == a.error? }.map(&:parsed).reverse
|
22
|
-
|
22
|
+
.inject(::EacRubyUtils::Struct.new) { |a, e| a.merge(e) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def alternatives_uncached
|
26
26
|
definition.alternatives
|
27
|
-
|
27
|
+
.map { |alternative| ::EacCli::Parser::Alternative.new(alternative, argv) }
|
28
28
|
end
|
29
29
|
|
30
30
|
def first_error_uncached
|
@@ -1,23 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/
|
4
|
-
require '
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
16
|
+
def result
|
16
17
|
(
|
17
|
-
|
18
|
+
program_name +
|
18
19
|
alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
|
19
20
|
options +
|
20
21
|
positionals
|
21
|
-
).join(
|
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 :
|
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(
|
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 +
|
49
|
-
"\n"
|
58
|
+
b += IDENT + self.alternative(alternative) + "\n"
|
50
59
|
end
|
51
60
|
b
|
52
61
|
end
|
@@ -54,13 +63,13 @@ module EacCli
|
|
54
63
|
def options_section
|
55
64
|
"Options:\n" +
|
56
65
|
definition.alternatives.flat_map(&:options)
|
57
|
-
|
66
|
+
.map { |option| IDENT + option_definition(option) + "\n" }.join
|
58
67
|
end
|
59
68
|
|
60
69
|
def usage_section
|
61
70
|
"Usage:\n" +
|
62
71
|
definition.alternatives.map do |alternative|
|
63
|
-
IDENT +
|
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
|
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
|
@@ -17,7 +17,7 @@ module EacCli
|
|
17
17
|
common_concern do
|
18
18
|
include ::EacCli::Runner
|
19
19
|
runner_definition.singleton_class
|
20
|
-
|
20
|
+
.include(::EacCli::RunnerWith::Subcommands::DefinitionConcern)
|
21
21
|
end
|
22
22
|
|
23
23
|
EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
|
@@ -28,9 +28,9 @@ module EacCli
|
|
28
28
|
|
29
29
|
def available_subcommands_auto
|
30
30
|
self.class.constants
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
34
34
|
end
|
35
35
|
|
36
36
|
def available_subcommands_extra
|
@@ -104,7 +104,7 @@ module EacCli
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def subcommand_program
|
107
|
-
subcommand_name
|
107
|
+
[program_name, subcommand_name]
|
108
108
|
end
|
109
109
|
|
110
110
|
def subcommand_runner
|
@@ -32,8 +32,8 @@ module EacCli
|
|
32
32
|
|
33
33
|
def key_to_module(key)
|
34
34
|
namespace_set.lazy
|
35
|
-
|
36
|
-
|
35
|
+
.map { |namespace| key_to_module_in_namespace(namespace, key) }
|
36
|
+
.find(&:present?) ||
|
37
37
|
raise("Not module found with key \"#{key}\" (Namespaces: #{namespace_set})")
|
38
38
|
end
|
39
39
|
|
data/lib/eac_cli/version.rb
CHANGED
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.
|
4
|
+
version: 0.27.5
|
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-
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
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.
|
54
|
+
version: '0.95'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: eac_ruby_gem_support
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.5.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.5.1
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -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
|