eac_cli 0.33.0 → 0.35.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/alternative.rb +11 -7
- data/lib/eac_cli/definition/base_option/initialize_args_parser.rb +2 -1
- data/lib/eac_cli/definition/base_option.rb +1 -1
- data/lib/eac_cli/definition/boolean_option.rb +2 -1
- data/lib/eac_cli/definition/error.rb +8 -0
- data/lib/eac_cli/runner/after_class_methods.rb +6 -1
- data/lib/eac_cli/runner/context.rb +29 -7
- data/lib/eac_cli/runner/context_responders/base.rb +24 -0
- data/lib/eac_cli/runner/context_responders/parent.rb +27 -0
- data/lib/eac_cli/runner/context_responders/runner.rb +20 -0
- data/lib/eac_cli/runner/context_responders/runner_missing_method.rb +32 -0
- data/lib/eac_cli/runner/context_responders/set.rb +44 -0
- data/lib/eac_cli/runner/context_responders.rb +11 -0
- data/lib/eac_cli/runner/for_context.rb +40 -0
- data/lib/eac_cli/runner/instance_methods.rb +5 -3
- data/lib/eac_cli/runner.rb +1 -0
- data/lib/eac_cli/version.rb +1 -1
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c64bf26b4c30499f44f1b0398c485b3f62e2111e1b289fe1d8b0770c58e3ed8e
|
4
|
+
data.tar.gz: '088a6b2cb5046192f702e30c5dee090a2916fb1d28ec595fb2fab0caeaaa84be'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b91146dc901cc943250c941eddaec66951ddbf62a0232544f34b99e483d9e4e33615e30f611c9cba7001c9a245c79b7d6a898d5c1606015ea6a217cd9eef27c
|
7
|
+
data.tar.gz: 80c2f9606cad73728c47a996fa8e5a698e75c52785eff5736dc07cd5a7cf740e826737782b2884a0d8d07626dc8a2a44d37f85c614a927efa2f6a3748bf8d3fd
|
@@ -42,14 +42,15 @@ module EacCli
|
|
42
42
|
pos_set.to_a
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def positional_arguments_blocked_reason(new_pos_arg)
|
46
46
|
last = pos_set.last
|
47
|
-
return
|
48
|
-
return
|
49
|
-
return
|
50
|
-
return
|
47
|
+
return nil unless last
|
48
|
+
return 'there are subcommands' if subcommands?
|
49
|
+
return 'last argument repeats' if last.repeat?
|
50
|
+
return 'new argument is required and last is optional' if
|
51
|
+
last.optional? && new_pos_arg.if_present(&:required?)
|
51
52
|
|
52
|
-
|
53
|
+
nil
|
53
54
|
end
|
54
55
|
|
55
56
|
def subcommands
|
@@ -65,7 +66,10 @@ module EacCli
|
|
65
66
|
private
|
66
67
|
|
67
68
|
def check_positional_blocked(new_pos_arg)
|
68
|
-
|
69
|
+
positional_arguments_blocked_reason(new_pos_arg).if_present do |v|
|
70
|
+
raise ::EacCli::Definition::Error, "Positional arguments are blocked: #{v}" \
|
71
|
+
" (New argument: #{new_pos_arg})"
|
72
|
+
end
|
69
73
|
end
|
70
74
|
|
71
75
|
def pos_set
|
@@ -26,7 +26,8 @@ module EacCli
|
|
26
26
|
common_constructor :value
|
27
27
|
|
28
28
|
def type
|
29
|
-
TYPES.find { |type| send("#{type}?") } ||
|
29
|
+
TYPES.find { |type| send("#{type}?") } ||
|
30
|
+
raise(::EacCli::Definition::Error, "Unknown type for \"#{value}\"")
|
30
31
|
end
|
31
32
|
|
32
33
|
def short?
|
@@ -16,7 +16,8 @@ module EacCli
|
|
16
16
|
def default_value
|
17
17
|
return super unless default_value?
|
18
18
|
|
19
|
-
raise
|
19
|
+
raise(::EacCli::Definition::Error,
|
20
|
+
"Unallowed default value for boolean options (Option: #{self})")
|
20
21
|
end
|
21
22
|
|
22
23
|
def default_default_value
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_cli/definition'
|
4
|
+
require 'eac_cli/definition/error'
|
4
5
|
require 'eac_cli/runner/class_runner'
|
5
6
|
|
6
7
|
module EacCli
|
@@ -21,7 +22,11 @@ module EacCli
|
|
21
22
|
|
22
23
|
def runner_definition(&block)
|
23
24
|
@runner_definition ||= super_runner_definition
|
24
|
-
|
25
|
+
begin
|
26
|
+
@runner_definition.instance_eval(&block) if block
|
27
|
+
rescue ::EacCli::Definition::Error => _e
|
28
|
+
raise ::EacCli::Definition::Error, "Definition error for #{self}"
|
29
|
+
end
|
25
30
|
@runner_definition
|
26
31
|
end
|
27
32
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/parent'
|
5
|
+
require 'eac_cli/runner/context_responders/runner'
|
6
|
+
require 'eac_cli/runner/context_responders/runner_missing_method'
|
7
|
+
require 'eac_cli/runner/context_responders/set'
|
4
8
|
|
5
9
|
module EacCli
|
6
10
|
module Runner
|
@@ -17,24 +21,42 @@ module EacCli
|
|
17
21
|
|
18
22
|
# Call a method in the runner or in one of it ancestors.
|
19
23
|
def call(method_name, *args)
|
20
|
-
|
21
|
-
|
24
|
+
context_call_responder(method_name).call(*args)
|
25
|
+
end
|
22
26
|
|
23
|
-
|
27
|
+
# @return [EacCli::Runner::ContextResponders]
|
28
|
+
def context_call_responder(method_name)
|
29
|
+
::EacCli::Runner::ContextResponders::Set.new(self, method_name, %i[runner parent])
|
24
30
|
end
|
25
31
|
|
26
|
-
|
27
|
-
|
32
|
+
# @param method_name [Symbol]
|
33
|
+
# @return [EacCli::Runner::ContextResponders::Parent]
|
34
|
+
def runner_missing_method_responder(method_name)
|
35
|
+
::EacCli::Runner::ContextResponders::RunnerMissingMethod
|
36
|
+
.new(self, method_name)
|
28
37
|
end
|
29
38
|
|
30
|
-
|
39
|
+
# @param method_name [Symbol]
|
40
|
+
# @return [Boolean]
|
41
|
+
def parent_respond_to?(method_name)
|
42
|
+
parent.if_present(false) do |v|
|
43
|
+
next true if v.respond_to?(method_name)
|
44
|
+
|
45
|
+
v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
|
46
|
+
end
|
47
|
+
end
|
31
48
|
|
32
49
|
def parent_call(method_name, *args)
|
33
|
-
return parent.context(method_name, *args) if parent.respond_to?(:context)
|
34
50
|
return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)
|
35
51
|
|
36
52
|
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
37
53
|
end
|
54
|
+
|
55
|
+
# @param method_name [Symbol]
|
56
|
+
# @return [EacCli::Runner::ContextResponders::Parent]
|
57
|
+
def parent_responder(method_name)
|
58
|
+
::EacCli::Runner::ContextResponders::Parent.new(self, method_name)
|
59
|
+
end
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
module Runner
|
7
|
+
module ContextResponders
|
8
|
+
class Base
|
9
|
+
acts_as_abstract :call, :callable?
|
10
|
+
common_constructor :context, :method_name do
|
11
|
+
self.method_name = method_name.to_sym
|
12
|
+
end
|
13
|
+
delegate :parent, :runner, to: :context
|
14
|
+
|
15
|
+
def if_callable
|
16
|
+
return false unless callable?
|
17
|
+
|
18
|
+
yield(self)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Parent < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
parent.if_present(false) do |v|
|
12
|
+
next true if v.respond_to?(method_name)
|
13
|
+
|
14
|
+
v.if_respond(:runner_context, false) { |w| w.parent_respond_to?(method_name) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(*args, &block)
|
19
|
+
return parent.runner_context.call(method_name, *args, &block) if
|
20
|
+
parent.respond_to?(:runner_context)
|
21
|
+
|
22
|
+
raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Runner < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
runner.respond_to?(method_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(*args, &block)
|
15
|
+
runner.send(method_name, *args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class RunnerMissingMethod < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
def callable?
|
11
|
+
responder_runner.present?
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(*args, &block)
|
15
|
+
responder_runner.send(method_name, *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def responder_runner
|
21
|
+
parent.if_present(nil) do |v|
|
22
|
+
next v if v.respond_to?(method_name) && v.for_context?(method_name)
|
23
|
+
|
24
|
+
v.if_respond(:runner_context, nil) do |w|
|
25
|
+
w.runner_missing_method_responder(method_name).send(__method__)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/runner/context_responders/base'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ContextResponders
|
9
|
+
class Set < ::EacCli::Runner::ContextResponders::Base
|
10
|
+
attr_reader :responders_names
|
11
|
+
|
12
|
+
def initialize(context, method_name, responders_names)
|
13
|
+
super(context, method_name)
|
14
|
+
@responders_names = responders_names
|
15
|
+
end
|
16
|
+
|
17
|
+
def callable?
|
18
|
+
responders_instances.any?(&:callable?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(*args, &block)
|
22
|
+
caller = responder_to_call
|
23
|
+
return caller.call(*args, &block) if caller
|
24
|
+
|
25
|
+
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def responder_class(class_name)
|
31
|
+
::EacCli::Runner::ContextResponders.const_get(class_name.to_s.camelize)
|
32
|
+
end
|
33
|
+
|
34
|
+
def responders_instances
|
35
|
+
responders_names.lazy.map { |name| responder_class(name).new(context, method_name) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def responder_to_call
|
39
|
+
responders_instances.lazy.select(&:callable?).first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/module_ancestors_variable/set'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Runner
|
8
|
+
module ForContext
|
9
|
+
common_concern
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# @param methods_names [Enumerable<Symbol>]
|
13
|
+
# @return [void]
|
14
|
+
def for_context(*methods_names)
|
15
|
+
for_context_methods.merge(methods_names.map(&:to_sym))
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param method_name [Symbol]
|
19
|
+
# @return [Boolean]
|
20
|
+
def for_context?(method_name)
|
21
|
+
for_context_methods.include?(method_name.to_sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# @return [EacRubyUtils::ModuleAncestorsVariable::Set<Symbol>]
|
27
|
+
def for_context_methods
|
28
|
+
@for_context_methods ||=
|
29
|
+
::EacRubyUtils::ModuleAncestorsVariable::Set.new(self, __method__)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param method_name [Symbol]
|
34
|
+
# @return [Boolean]
|
35
|
+
def for_context?(method_name)
|
36
|
+
self.class.for_context?(method_name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -30,13 +30,15 @@ module EacCli
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def respond_to_missing?(method, include_all = false)
|
33
|
-
runner_context.
|
33
|
+
runner_context.runner_missing_method_responder(method).callable? || super
|
34
34
|
end
|
35
35
|
|
36
36
|
def method_missing(method, *args, &block)
|
37
|
-
|
37
|
+
runner_context.runner_missing_method_responder(method).if_callable do |v|
|
38
|
+
return v.call(*args, &block)
|
39
|
+
end
|
38
40
|
|
39
|
-
|
41
|
+
super
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
data/lib/eac_cli/runner.rb
CHANGED
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.35.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-20 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.117'
|
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.117'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: eac_ruby_gem_support
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/eac_cli/definition/base_option/initialize_args_parser.rb
|
94
94
|
- lib/eac_cli/definition/boolean_option.rb
|
95
95
|
- lib/eac_cli/definition/default_value.rb
|
96
|
+
- lib/eac_cli/definition/error.rb
|
96
97
|
- lib/eac_cli/definition/positional_argument.rb
|
97
98
|
- lib/eac_cli/enum.rb
|
98
99
|
- lib/eac_cli/old_configs.rb
|
@@ -120,7 +121,14 @@ files:
|
|
120
121
|
- lib/eac_cli/runner/after_class_methods.rb
|
121
122
|
- lib/eac_cli/runner/class_runner.rb
|
122
123
|
- lib/eac_cli/runner/context.rb
|
124
|
+
- lib/eac_cli/runner/context_responders.rb
|
125
|
+
- lib/eac_cli/runner/context_responders/base.rb
|
126
|
+
- lib/eac_cli/runner/context_responders/parent.rb
|
127
|
+
- lib/eac_cli/runner/context_responders/runner.rb
|
128
|
+
- lib/eac_cli/runner/context_responders/runner_missing_method.rb
|
129
|
+
- lib/eac_cli/runner/context_responders/set.rb
|
123
130
|
- lib/eac_cli/runner/exit.rb
|
131
|
+
- lib/eac_cli/runner/for_context.rb
|
124
132
|
- lib/eac_cli/runner/instance_methods.rb
|
125
133
|
- lib/eac_cli/runner_with.rb
|
126
134
|
- lib/eac_cli/runner_with/confirmation.rb
|