eac_cli 0.40.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ece27189a8fbfde6ada6b7b3b1bbe78a57dd47cd2df0eba8cd1551fe94b5cee
4
- data.tar.gz: 77046ab0fcdc365df212cfe028e953eec75d82f2ed0f4b7f148d62635d7a783f
3
+ metadata.gz: e47dbd4933f71d029f4fd1f19d84db730ecd3040c866c89725c6d02b81571fb3
4
+ data.tar.gz: 1b5093e85452bb32a228b94d4a71bc35fc0fd9c2f036d23d2c9f52e76b05047a
5
5
  SHA512:
6
- metadata.gz: 825723db43e762a7445d7ba56e7c61fc9125d5355209608112009137937f43679cd460b9c45fcbcbd808a34db7f3986b257618ba6e702aa33ff01946f6251e8a
7
- data.tar.gz: 843805718a773a90e3dc1030127bc4db0c073f4f304bd0c6b2140177697c74becebccfa755412f048528f30af9e362775b1cda7e87f73132c5d348b81b9ac182
6
+ metadata.gz: 5eb9b2c2faa3b1e6beb70f09e16caaedf0061fbbd565c72d18228061896e0996d18f0375d3f569ca1ef3dc0ec5d333ea9157f44192c10a8981fa6e2ffaf8e086
7
+ data.tar.gz: b0120fe12a7dd9599a00f8288e7be2a6adde51796c4012f0a12b3df5f294c4bccd9bfb9e81becb8d562882b821e291906c9bbe010a076ee7d56fee57cf2ccb92
@@ -15,6 +15,10 @@ module EacCli
15
15
 
16
16
  def disable_config_input_request
17
17
  rspec_config.before do
18
+ # Fixes EacCli::Config::Entry does not implement #input_value error
19
+ ::EacCli::Config::Entry.define_method(:input_value) do
20
+ super
21
+ end
18
22
  allow_any_instance_of(::EacCli::Config::Entry).to receive(:input_value) do |obj|
19
23
  raise "Console input requested for entry (Path: #{obj.path})"
20
24
  end
@@ -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(input(message, list: INPUT_LIST))
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
- r = confirm_input(message)
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
  {}
@@ -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
- def build(list)
11
- return List.new(hash_to_values(list)) if list.is_a?(::Hash)
12
- return List.new(array_to_values(list)) if list.is_a?(::Array)
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| ::OpenStruct.new(key: key, label: key, value: value) } # rubocop:disable Style/OpenStructUse
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| ::OpenStruct.new(key: value, label: value, value: value) } # rubocop:disable Style/OpenStructUse
28
+ list.map { |value| VALUE_STRUCT.new(value, value, value) }
25
29
  end
26
30
  end
27
31
 
28
- attr_reader :values
32
+ DEFAULT_IGNORE_CASE = true
33
+
34
+ enable_listable
35
+ lists.add_symbol :option, :ignore_case
29
36
 
30
- def initialize(values)
31
- @values = values.map do |v|
32
- ::OpenStruct.new(key: to_key(v.key), label: to_label(v.label), value: v.value) # rubocop:disable Style/OpenStructUse
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).downcase
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
@@ -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 = options.to_options_consumer.consume_all(: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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.40.0'
4
+ VERSION = '0.41.0'
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.40.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: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '0.14'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.14.1
42
+ version: 0.14.2
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,21 +49,21 @@ dependencies:
49
49
  version: '0.14'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.14.1
52
+ version: 0.14.2
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: eac_ruby_utils
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '0.120'
59
+ version: '0.121'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '0.120'
66
+ version: '0.121'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: tty-table
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -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: []