eac_cli 0.32.0 → 0.34.0
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/base_option.rb +3 -1
- data/lib/eac_cli/definition/default_value.rb +17 -0
- data/lib/eac_cli/runner/context.rb +9 -6
- data/lib/eac_cli/runner/instance_methods.rb +3 -3
- data/lib/eac_cli/runner_with/help/builder.rb +8 -26
- data/lib/eac_cli/runner_with/help/layout.rb +40 -0
- data/lib/eac_cli/runner_with/help.rb +12 -0
- data/lib/eac_cli/runner_with/input.rb +1 -1
- data/lib/eac_cli/runner_with/output.rb +1 -1
- data/lib/eac_cli/runner_with/subcommands.rb +1 -4
- data/lib/eac_cli/version.rb +1 -1
- metadata +6 -5
- data/lib/eac_cli/runner_with/help/list_section.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5669575a2fe583905e0b4f1406102ce97429ecedbfd97e69d737c5198410242c
|
4
|
+
data.tar.gz: 0e777a88e237fa1e2d61d9a95d14c0435f0ec3664902fcc896d89bf9edb509f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861a9c0e766b38db24fc8e2dc27b74fa4cd91b2978e0ad01d452acdcaa5fcd3c3fc9012e65b71270c65e8bf69333048f84ce115b1d031d57196586944109aec9
|
7
|
+
data.tar.gz: d9d516f186575069712a9d33673ef26021dc2ed2644b347ee05549861cbceca023b2541658cf5730e8446b8abebddb9261e0f616b8255c7a959a8c5fabdf6559
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_cli/definition/default_value'
|
3
4
|
require 'eac_ruby_utils/core_ext'
|
4
5
|
|
5
6
|
module EacCli
|
6
7
|
class Definition
|
7
8
|
class BaseOption
|
8
9
|
require_sub __FILE__
|
10
|
+
include ::EacCli::Definition::DefaultValue
|
9
11
|
|
10
12
|
class << self
|
11
13
|
def from_args(args)
|
@@ -17,7 +19,7 @@ module EacCli
|
|
17
19
|
DEFAULT_REQUIRED = false
|
18
20
|
|
19
21
|
enable_listable
|
20
|
-
enable_abstract_methods :build_value
|
22
|
+
enable_abstract_methods :build_value
|
21
23
|
lists.add_symbol :option, :default, :optional, :usage, :repeat, :required
|
22
24
|
common_constructor :short, :long, :description, :options, default: [{}] do
|
23
25
|
raise 'Nor short neither long selector was set' if short.blank? && long.blank?
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Definition
|
7
|
+
module DefaultValue
|
8
|
+
def default_value
|
9
|
+
default_value? ? options[OPTION_DEFAULT] : default_default_value
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_value?
|
13
|
+
options.key?(OPTION_DEFAULT)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -18,19 +18,22 @@ module EacCli
|
|
18
18
|
# Call a method in the runner or in one of it ancestors.
|
19
19
|
def call(method_name, *args)
|
20
20
|
return runner.send(method_name, *args) if runner.respond_to?(method_name)
|
21
|
-
return parent_call(method_name, *args) if
|
21
|
+
return parent_call(method_name, *args) if parent_respond_to?(method_name)
|
22
22
|
|
23
23
|
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
# @param method_name [Symbol]
|
27
|
+
# @return [Boolean]
|
28
|
+
def parent_respond_to?(method_name)
|
29
|
+
parent.if_present(false) do |v|
|
30
|
+
next true if v.respond_to?(method_name)
|
29
31
|
|
30
|
-
|
32
|
+
v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
|
33
|
+
end
|
34
|
+
end
|
31
35
|
|
32
36
|
def parent_call(method_name, *args)
|
33
|
-
return parent.context(method_name, *args) if parent.respond_to?(:context)
|
34
37
|
return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)
|
35
38
|
|
36
39
|
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
@@ -30,13 +30,13 @@ module EacCli
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def respond_to_missing?(method, include_all = false)
|
33
|
-
runner_context.
|
33
|
+
runner_context.parent_respond_to?(method) || super
|
34
34
|
end
|
35
35
|
|
36
36
|
def method_missing(method, *args, &block)
|
37
|
-
return super unless runner_context.
|
37
|
+
return super unless runner_context.parent_respond_to?(method)
|
38
38
|
|
39
|
-
runner_context.
|
39
|
+
runner_context.parent_call(method, *args, &block)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/runner_with/help/
|
3
|
+
require 'eac_cli/runner_with/help/layout'
|
4
4
|
require 'eac_ruby_utils/core_ext'
|
5
5
|
|
6
6
|
module EacCli
|
7
7
|
module RunnerWith
|
8
8
|
module Help
|
9
9
|
class Builder
|
10
|
+
include ::EacCli::RunnerWith::Help::Layout
|
10
11
|
require_sub __FILE__, require_dependency: true
|
11
12
|
common_constructor :runner
|
12
13
|
|
13
|
-
OPTION_DESC_SEP = ::EacCli::RunnerWith::Help::ListSection::IDENTATION * 2
|
14
|
-
SECTION_SEPARATOR = "\n"
|
15
|
-
|
16
14
|
class << self
|
17
15
|
def option_long(option)
|
18
16
|
b = option.long
|
@@ -35,7 +33,7 @@ module EacCli
|
|
35
33
|
end
|
36
34
|
|
37
35
|
def word_separator
|
38
|
-
|
36
|
+
WORD_SEPARATOR
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
@@ -45,36 +43,22 @@ module EacCli
|
|
45
43
|
runner.class.runner_definition
|
46
44
|
end
|
47
45
|
|
48
|
-
# @return [String, nil]
|
49
|
-
def extra_section
|
50
|
-
ess = extra_sections
|
51
|
-
return nil if ess.none?
|
52
|
-
|
53
|
-
ess.join(SECTION_SEPARATOR)
|
54
|
-
end
|
55
|
-
|
56
46
|
# @return [Enumerable<String>]
|
57
47
|
def extra_sections
|
58
48
|
runner.if_respond(:help_extra_text, []) do |v|
|
59
|
-
|
60
|
-
v.map do |title, lines|
|
61
|
-
::EacCli::RunnerWith::Help::ListSection.new(title, lines)
|
62
|
-
end
|
63
|
-
else
|
64
|
-
[v.to_s]
|
65
|
-
end
|
49
|
+
[v.to_s]
|
66
50
|
end
|
67
51
|
end
|
68
52
|
|
69
53
|
def option_definition(option)
|
70
54
|
[self.class.option_usage_full(option), option.description,
|
71
55
|
option.default_value? ? "[Default: \"#{option.default_value}\"]" : nil]
|
72
|
-
.reject(&:blank?).join(
|
56
|
+
.reject(&:blank?).join(OPTION_DESCRIPTION_SEPARATOR)
|
73
57
|
end
|
74
58
|
|
75
59
|
# @return [String]
|
76
60
|
def options_section
|
77
|
-
|
61
|
+
list_section(
|
78
62
|
'Options',
|
79
63
|
definition.alternatives.flat_map(&:options).map { |option| option_definition(option) }
|
80
64
|
)
|
@@ -82,16 +66,14 @@ module EacCli
|
|
82
66
|
|
83
67
|
# @return [String]
|
84
68
|
def usage_section
|
85
|
-
|
69
|
+
list_section(
|
86
70
|
'Usage',
|
87
71
|
definition.alternatives.map { |alternative| self.alternative(alternative) }
|
88
72
|
)
|
89
73
|
end
|
90
74
|
|
91
75
|
def to_s
|
92
|
-
|
93
|
-
.map { |s| "#{s}#{SECTION_SEPARATOR}" }.join
|
94
|
-
extra_section.if_present(r) { |v| r + v }
|
76
|
+
join_sections(definition.description, usage_section, options_section, *extra_sections)
|
95
77
|
end
|
96
78
|
end
|
97
79
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
module RunnerWith
|
7
|
+
module Help
|
8
|
+
module Layout
|
9
|
+
common_concern do
|
10
|
+
include InstanceClassMethods
|
11
|
+
extend InstanceClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceClassMethods
|
15
|
+
WORD_SEPARATOR = ' '
|
16
|
+
IDENTATION = WORD_SEPARATOR * 2
|
17
|
+
OPTION_DESCRIPTION_SEPARATOR = IDENTATION * 2
|
18
|
+
LINE_BREAK = "\n"
|
19
|
+
SECTION_SEPARATOR = LINE_BREAK * 2
|
20
|
+
|
21
|
+
# @param title String
|
22
|
+
# @param items [Enumerable<String>]
|
23
|
+
# @return [String]
|
24
|
+
def list_section(title, items)
|
25
|
+
(["#{title}:"] + items.map { |line| "#{IDENTATION}#{line}" })
|
26
|
+
.map { |line| "#{line}\n" }.join
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param sections [Enumerable<String>]
|
30
|
+
# @return [String]
|
31
|
+
def join_sections(*sections)
|
32
|
+
sections.map { |s| s.to_s.strip }.join(SECTION_SEPARATOR) + LINE_BREAK
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
extend InstanceClassMethods
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -20,6 +20,18 @@ module EacCli
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
# @param items [Enumerable<String>]
|
24
|
+
# @return [String]
|
25
|
+
def help_list_section(title, items)
|
26
|
+
::EacCli::RunnerWith::Help::Layout.list_section(title, items)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param items [Enumerable<String>]
|
30
|
+
# @return [String]
|
31
|
+
def help_join_sections(*sections)
|
32
|
+
::EacCli::RunnerWith::Help::Layout.join_sections(*sections)
|
33
|
+
end
|
34
|
+
|
23
35
|
def help_run
|
24
36
|
return unless show_help?
|
25
37
|
|
@@ -53,10 +53,7 @@ module EacCli
|
|
53
53
|
|
54
54
|
# @return [Hash<String, Enumerable<String>]
|
55
55
|
def help_extra_text
|
56
|
-
|
57
|
-
'Subcommands' =>
|
58
|
-
available_subcommands.keys.sort
|
59
|
-
}
|
56
|
+
help_list_section('Subcommands', available_subcommands.keys.sort)
|
60
57
|
end
|
61
58
|
|
62
59
|
def method_missing(method_name, *arguments, &block)
|
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.
|
4
|
+
version: 0.34.0
|
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: 2023-05-
|
11
|
+
date: 2023-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
53
|
+
version: '0.116'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0.
|
60
|
+
version: '0.116'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: eac_ruby_gem_support
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/eac_cli/definition/base_option.rb
|
93
93
|
- lib/eac_cli/definition/base_option/initialize_args_parser.rb
|
94
94
|
- lib/eac_cli/definition/boolean_option.rb
|
95
|
+
- lib/eac_cli/definition/default_value.rb
|
95
96
|
- lib/eac_cli/definition/positional_argument.rb
|
96
97
|
- lib/eac_cli/enum.rb
|
97
98
|
- lib/eac_cli/old_configs.rb
|
@@ -126,7 +127,7 @@ files:
|
|
126
127
|
- lib/eac_cli/runner_with/help.rb
|
127
128
|
- lib/eac_cli/runner_with/help/builder.rb
|
128
129
|
- lib/eac_cli/runner_with/help/builder/alternative.rb
|
129
|
-
- lib/eac_cli/runner_with/help/
|
130
|
+
- lib/eac_cli/runner_with/help/layout.rb
|
130
131
|
- lib/eac_cli/runner_with/input.rb
|
131
132
|
- lib/eac_cli/runner_with/output.rb
|
132
133
|
- lib/eac_cli/runner_with/subcommands.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/core_ext'
|
4
|
-
|
5
|
-
module EacCli
|
6
|
-
module RunnerWith
|
7
|
-
module Help
|
8
|
-
class ListSection
|
9
|
-
WORD_SEPARATOR = ' '
|
10
|
-
IDENTATION = WORD_SEPARATOR * 2
|
11
|
-
|
12
|
-
common_constructor :title, :items
|
13
|
-
|
14
|
-
# @return [String]
|
15
|
-
def to_s
|
16
|
-
(["#{title}:"] + items.map { |line| "#{IDENTATION}#{line}" })
|
17
|
-
.map { |line| "#{line}\n" }.join
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|