eac_cli 0.40.1 → 0.41.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/runner_with/confirmation/input_result.rb +7 -1
- data/lib/eac_cli/runner_with/confirmation.rb +11 -3
- data/lib/eac_cli/speaker/list.rb +33 -10
- data/lib/eac_cli/speaker/options.rb +7 -1
- data/lib/eac_cli/speaker/request_from_list.rb +43 -0
- data/lib/eac_cli/speaker.rb +4 -13
- data/lib/eac_cli/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e47dbd4933f71d029f4fd1f19d84db730ecd3040c866c89725c6d02b81571fb3
|
4
|
+
data.tar.gz: 1b5093e85452bb32a228b94d4a71bc35fc0fd9c2f036d23d2c9f52e76b05047a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb9b2c2faa3b1e6beb70f09e16caaedf0061fbbd565c72d18228061896e0996d18f0375d3f569ca1ef3dc0ec5d333ea9157f44192c10a8981fa6e2ffaf8e086
|
7
|
+
data.tar.gz: b0120fe12a7dd9599a00f8288e7be2a6adde51796c4012f0a12b3df5f294c4bccd9bfb9e81becb8d562882b821e291906c9bbe010a076ee7d56fee57cf2ccb92
|
@@ -23,7 +23,13 @@ module EacCli
|
|
23
23
|
# @param message [String]
|
24
24
|
# @return [EacCli::RunnerWith::Confirmation::InputResult]
|
25
25
|
def by_message(message)
|
26
|
-
new(
|
26
|
+
new(input_value_by_speaker(message))
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param message [String]
|
30
|
+
# @return [String]
|
31
|
+
def input_value_by_speaker(message)
|
32
|
+
input(message, list: INPUT_LIST, ignore_case: false)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
@@ -18,14 +18,14 @@ module EacCli
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
# @param message [String, nil]
|
22
|
+
# @return [Boolean]
|
21
23
|
def confirm?(message = nil)
|
22
24
|
return for_all_answers.fetch(message) if for_all_answers.key?(message)
|
23
25
|
return false if parsed.no?
|
24
26
|
return true if parsed.yes?
|
25
27
|
|
26
|
-
|
27
|
-
for_all_answers[message] = r.for_all?
|
28
|
-
r.confirm?
|
28
|
+
confirm_input_and_register(message)
|
29
29
|
rescue ::EacCli::Speaker::InputRequested => e
|
30
30
|
fatal_error e.message
|
31
31
|
end
|
@@ -48,6 +48,14 @@ module EacCli
|
|
48
48
|
)
|
49
49
|
end
|
50
50
|
|
51
|
+
# @param message [String, nil]
|
52
|
+
# @return [Boolean]
|
53
|
+
def confirm_input_and_register(message)
|
54
|
+
r = confirm_input(message)
|
55
|
+
for_all_answers[message] = r.confirm? if r.for_all?
|
56
|
+
r.confirm?
|
57
|
+
end
|
58
|
+
|
51
59
|
# @return [Hash<String, Boolean>]
|
52
60
|
def for_all_answers_uncached
|
53
61
|
{}
|
data/lib/eac_cli/speaker/list.rb
CHANGED
@@ -6,10 +6,14 @@ require 'ostruct'
|
|
6
6
|
module EacCli
|
7
7
|
class Speaker
|
8
8
|
class List
|
9
|
+
VALUE_STRUCT = ::Struct.new(:key, :label, :value)
|
10
|
+
|
9
11
|
class << self
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
# @param list [Array, Hash]
|
13
|
+
# @param options [Hash]
|
14
|
+
def build(list, options = {})
|
15
|
+
return List.new(hash_to_values(list), options) if list.is_a?(::Hash)
|
16
|
+
return List.new(array_to_values(list), options) if list.is_a?(::Array)
|
13
17
|
|
14
18
|
raise "Invalid list: #{list} (#{list.class})"
|
15
19
|
end
|
@@ -17,22 +21,38 @@ module EacCli
|
|
17
21
|
private
|
18
22
|
|
19
23
|
def hash_to_values(list)
|
20
|
-
list.map { |key, value|
|
24
|
+
list.map { |key, value| VALUE_STRUCT.new(key, key, value) }
|
21
25
|
end
|
22
26
|
|
23
27
|
def array_to_values(list)
|
24
|
-
list.map { |value|
|
28
|
+
list.map { |value| VALUE_STRUCT.new(value, value, value) }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
|
32
|
+
DEFAULT_IGNORE_CASE = true
|
33
|
+
|
34
|
+
enable_listable
|
35
|
+
lists.add_symbol :option, :ignore_case
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
# @!attribute [r] values
|
38
|
+
# @return [Array<VALUE_STRUCT>]
|
39
|
+
# # @!attribute [r] options
|
40
|
+
# @return [Hash]
|
41
|
+
# @!method initialize(values)
|
42
|
+
# @param values [Array<VALUE_STRUCT>]
|
43
|
+
# @param options [Hash]
|
44
|
+
common_constructor :values, :options, default: [{}] do
|
45
|
+
self.options = self.class.lists.option.hash_keys_validate!(options)
|
46
|
+
self.values = values.map do |v|
|
47
|
+
VALUE_STRUCT.new(to_key(v.key), to_label(v.label), v.value)
|
33
48
|
end
|
34
49
|
end
|
35
50
|
|
51
|
+
# @return [Boolean]
|
52
|
+
def ignore_case?
|
53
|
+
options.if_key(OPTION_IGNORE_CASE, DEFAULT_IGNORE_CASE, &:to_bool)
|
54
|
+
end
|
55
|
+
|
36
56
|
def valid_labels
|
37
57
|
values.map(&:label)
|
38
58
|
end
|
@@ -41,8 +61,11 @@ module EacCli
|
|
41
61
|
values.any? { |v| v.key == to_key(value) }
|
42
62
|
end
|
43
63
|
|
64
|
+
# @param value [Object]
|
65
|
+
# @return [String]
|
44
66
|
def to_key(value)
|
45
|
-
to_label(value)
|
67
|
+
r = to_label(value)
|
68
|
+
ignore_case? ? r.downcase : r
|
46
69
|
end
|
47
70
|
|
48
71
|
def to_label(value)
|
@@ -7,7 +7,8 @@ module EacCli
|
|
7
7
|
module Options
|
8
8
|
common_concern do
|
9
9
|
enable_listable
|
10
|
-
lists.add_symbol :option, :out_out, :err_out, :in_in, :parent, :err_line_prefix
|
10
|
+
lists.add_symbol :option, :out_out, :err_out, :in_in, :parent, :err_line_prefix,
|
11
|
+
:ignore_case
|
11
12
|
end
|
12
13
|
|
13
14
|
def err_out
|
@@ -22,6 +23,11 @@ module EacCli
|
|
22
23
|
option(OPTION_IN_IN, $stdin)
|
23
24
|
end
|
24
25
|
|
26
|
+
# @return [Boolean]
|
27
|
+
def ignore_case
|
28
|
+
option(OPTION_IGNORE_CASE, nil)
|
29
|
+
end
|
30
|
+
|
25
31
|
def err_line_prefix
|
26
32
|
option(OPTION_ERR_LINE_PREFIX, '')
|
27
33
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/speaker/list'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class Speaker
|
8
|
+
class RequestFromList
|
9
|
+
acts_as_instance_method
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :speaker, :question, :list_values, :noecho,
|
12
|
+
:ignore_case
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def result
|
16
|
+
loop do
|
17
|
+
return list.build_value(input) if list.valid_value?(input)
|
18
|
+
|
19
|
+
speaker.warn "Invalid input: \"#{input}\" (Valid: #{list.valid_labels.join(', ')})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def input_uncached
|
27
|
+
speaker.send(
|
28
|
+
:request_string,
|
29
|
+
"#{question} [#{list.valid_labels.join('/')}]",
|
30
|
+
noecho
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [EacCli::Speaker::List]
|
35
|
+
def list_uncached
|
36
|
+
list_options = {}
|
37
|
+
list_options[::EacCli::Speaker::List::OPTION_IGNORE_CASE] = ignore_case unless
|
38
|
+
ignore_case.nil?
|
39
|
+
::EacCli::Speaker::List.build(list_values, list_options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/eac_cli/speaker.rb
CHANGED
@@ -52,9 +52,10 @@ module EacCli
|
|
52
52
|
# +list+ ([Hash] or [Array], default: +nil+): requires a answer from a list.
|
53
53
|
# +noecho+ ([Boolean], default: +false+): does not output answer.
|
54
54
|
def input(question, options = {})
|
55
|
-
bool, list, noecho
|
55
|
+
bool, list, noecho, ignore_case =
|
56
|
+
options.to_options_consumer.consume_all(:bool, :list, :noecho, :ignore_case)
|
56
57
|
if list
|
57
|
-
request_from_list(question, list, noecho)
|
58
|
+
request_from_list(question, list, noecho, ignore_case)
|
58
59
|
elsif bool
|
59
60
|
request_from_bool(question, noecho)
|
60
61
|
else
|
@@ -96,17 +97,7 @@ module EacCli
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def request_from_bool(question, noecho)
|
99
|
-
request_from_list(question, { yes: true, y: true, no: false, n: false }, noecho)
|
100
|
-
end
|
101
|
-
|
102
|
-
def request_from_list(question, list, noecho)
|
103
|
-
list = ::EacCli::Speaker::List.build(list)
|
104
|
-
loop do
|
105
|
-
input = request_string("#{question} [#{list.valid_labels.join('/')}]", noecho)
|
106
|
-
return list.build_value(input) if list.valid_value?(input)
|
107
|
-
|
108
|
-
warn "Invalid input: \"#{input}\" (Valid: #{list.valid_labels.join(', ')})"
|
109
|
-
end
|
100
|
+
request_from_list(question, { yes: true, y: true, no: false, n: false }, noecho, true)
|
110
101
|
end
|
111
102
|
|
112
103
|
def request_string(question, noecho)
|
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.41.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: 2024-
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/eac_cli/speaker/input_requested.rb
|
179
179
|
- lib/eac_cli/speaker/list.rb
|
180
180
|
- lib/eac_cli/speaker/options.rb
|
181
|
+
- lib/eac_cli/speaker/request_from_list.rb
|
181
182
|
- lib/eac_cli/version.rb
|
182
183
|
homepage:
|
183
184
|
licenses: []
|