eac_cli 0.37.0 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86b393d29e9db3edc24f1bd34bb4f7ade5935892d8c753b400f7737504d8af21
4
- data.tar.gz: 5f609ff444293079bf8f1d21f292aa72d42012814fbbb6c50acc26b56a8d4613
3
+ metadata.gz: c8e016c3cb10caefe2fcc4f81d73dbdf76cff97a0e11ecb49f4b8378be238b7a
4
+ data.tar.gz: 676cf803931311818d97ea9a5421e360e16a36495e93a2cf90a938afdb526562
5
5
  SHA512:
6
- metadata.gz: b2fe55eff4ac6b552cd3d6505eae01415e17dd970977f849b320dd8ceddead841537fdaf27675a7751265dd6f6a1e4810e4fd5450ddefd3d6a8a14d989ea9944
7
- data.tar.gz: a2ae31d75a0a7c1aa75597072acce427ee1c3c9a345795ff85111c72f493767f3362826d4bd941ce0e0f3ff947a3e0e64b8198f61db934904452f06f11b0dbd0
6
+ metadata.gz: 9902444b9eb020f42bf0b33c2c7afe5c8dae6651ad7ae2f6a0b57a563424715eed55058ca48f4b50d572a1284a62d0c4e0246ecbb0b15f907c10b12254a6f7b3
7
+ data.tar.gz: d62d638adea120b7dd203cafff53646a40ef011659bb952216e130d49988d06ceb151f85caf5832301092448c95ef46ffe82223ba550f6a9c6bb2b298bf21e3e
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- local_gemfile = ::File.join(::File.dirname(__FILE__), 'Gemfile.local')
8
- eval_gemfile local_gemfile if ::File.exist?(local_gemfile)
7
+ local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
8
+ eval_gemfile local_gemfile if File.exist?(local_gemfile)
@@ -6,10 +6,6 @@ module EacCli
6
6
  class Config < ::SimpleDelegator
7
7
  require_sub __FILE__
8
8
 
9
- def initialize(sub_node)
10
- super(sub_node)
11
- end
12
-
13
9
  def entry(path, options = {})
14
10
  ::EacCli::Config::Entry.new(self, path, options)
15
11
  end
@@ -3,4 +3,4 @@
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_cli/patches'
5
5
 
6
- ::EacCli::RunnerWithSet.default.add_from_gems_registry
6
+ EacCli::RunnerWithSet.default.add_from_gems_registry
@@ -7,9 +7,30 @@ require 'eac_cli/definition/positional_argument'
7
7
  module EacCli
8
8
  class Definition
9
9
  class Alternative
10
+ ANY_OPTION_DESCRIPTION = 'ANY_OPTION'
11
+ ANY_OPTION_LONG = '__'
12
+ ANY_OPTION_SHORT = '_'
10
13
  SUBCOMMAND_NAME_ARG = :subcommand
11
14
  SUBCOMMAND_ARGS_ARG = :subcommand_args
12
15
 
16
+ # @return [Boolean]
17
+ def any_opt
18
+ @any_opt = true
19
+ end
20
+
21
+ # @return [Boolean]
22
+ def any_option?
23
+ @any_opt ? true : false
24
+ end
25
+
26
+ # @return [EacCli::Definition::BooleanOption]
27
+ def any_options_option
28
+ @any_options_option ||= ::EacCli::Definition::BooleanOption.new(
29
+ ANY_OPTION_SHORT, ANY_OPTION_LONG, ANY_OPTION_DESCRIPTION,
30
+ optional: true, repeat: true, usage: false
31
+ )
32
+ end
33
+
13
34
  def arg_opt(*args)
14
35
  options_set << ::EacCli::Definition::ArgumentOption.from_args(args)
15
36
  end
@@ -48,7 +69,7 @@ module EacCli
48
69
  return 'there are subcommands' if subcommands?
49
70
  return 'last argument repeats' if last.repeat?
50
71
  return 'new argument is required and last is optional' if
51
- last.optional? && new_pos_arg.if_present(&:required?)
72
+ last.optional? && new_pos_arg.if_present(&:required?)
52
73
 
53
74
  nil
54
75
  end
@@ -67,8 +88,8 @@ module EacCli
67
88
 
68
89
  def check_positional_blocked(new_pos_arg)
69
90
  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})"
91
+ raise ::EacCli::Definition::Error, "Positional arguments are blocked: #{v} " \
92
+ "(New argument: #{new_pos_arg})"
72
93
  end
73
94
  end
74
95
 
@@ -66,7 +66,7 @@ module EacCli
66
66
  alternatives.any?(&:subcommands?)
67
67
  end
68
68
 
69
- def options_first(enable = true)
69
+ def options_first(enable = true) # rubocop:disable Style/OptionalBooleanParameter
70
70
  @options_first = enable
71
71
  end
72
72
 
@@ -17,7 +17,7 @@ module EacCli
17
17
  def banner
18
18
  infom 'Do you wanna to store passwords?'
19
19
  infom 'Warning: the passwords will be store in clear text in ' \
20
- "\"#{console_configs.configs.storage_path}\""
20
+ "\"#{console_configs.configs.storage_path}\""
21
21
  infom 'Enter "yes" or "no"'
22
22
  end
23
23
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ class Parser
7
+ class Alternative
8
+ module AnyOptions
9
+ delegate :any_option?, to: :alternative
10
+
11
+ # @return [EacCli::Definition::BooleanOption] if #any_option? is true.
12
+ # @raise [EacCli::Parser::Error] if #any_option? is false.
13
+ def any_option_collect_option
14
+ any_option? ? alternative.any_options_option : raise_argv_current_invalid_option
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -24,7 +24,7 @@ module EacCli
24
24
  else
25
25
  option_argument_collect(option, value)
26
26
  end
27
- end || raise_argv_current_invalid_option
27
+ end || any_option_collect_option
28
28
  end
29
29
 
30
30
  def parse_option_current_argv
@@ -33,9 +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
- raise_argv_current_invalid_option unless option
37
-
38
- option_collect_option(option)
36
+ option ? option_collect_option(option) : any_option_collect_option
39
37
  end
40
38
 
41
39
  def short_without_prefix(short)
@@ -62,15 +62,6 @@ module EacCli
62
62
  argv_enum.next
63
63
  end
64
64
 
65
- def collect_option_argv_value
66
- alternative.options.each do |option|
67
- end
68
-
69
- raise ::EacCli::Parser::Error.new(
70
- alternative, argv, "Invalid option: #{argv_enum.current}"
71
- )
72
- end
73
-
74
65
  def raise_error(message)
75
66
  raise ::EacCli::Parser::Error.new(alternative, argv, message)
76
67
  end
@@ -12,7 +12,7 @@ module EacCli
12
12
 
13
13
  def parsed_uncached
14
14
  raise 'Definition has no alternatives' if alternatives.empty?
15
- raise first_error unless alternatives.select(&:success?).any?
15
+ raise first_error unless alternatives.any?(&:success?)
16
16
 
17
17
  alternatives_parsed(true).merge(alternatives_parsed(false))
18
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].sort.each do |path|
3
+ Dir["#{File.dirname(__FILE__)}/#{File.basename(__FILE__, '.*')}/*.rb"].sort.each do |path|
4
4
  require path
5
5
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub(__FILE__)
4
+ EacRubyUtils.require_sub(__FILE__)
@@ -29,7 +29,7 @@ module EacCli
29
29
 
30
30
  def run_parser_error(runner_instance, error)
31
31
  $stderr.write("#{runner_instance.program_name}: #{error}\n")
32
- ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
32
+ ::Kernel.exit(PARSER_ERROR_EXIT_CODE) # rubocop:disable Rails/Exit
33
33
  end
34
34
  end
35
35
  end
@@ -18,9 +18,9 @@ module EacCli
18
18
  responders_instances.any?(&:callable?)
19
19
  end
20
20
 
21
- def call(*args, &block)
21
+ def call(...)
22
22
  caller = responder_to_call
23
- return caller.call(*args, &block) if caller
23
+ return caller.call(...) if caller
24
24
 
25
25
  raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
26
26
  end
@@ -5,7 +5,8 @@ module EacCli
5
5
  class Exit < ::StandardError
6
6
  attr_reader :status
7
7
 
8
- def initialize(status = true)
8
+ def initialize(status = true) # rubocop:disable Style/OptionalBooleanParameter
9
+ super
9
10
  @status = status
10
11
  end
11
12
  end
@@ -6,7 +6,7 @@ module EacCli
6
6
  def run_run
7
7
  parsed
8
8
  run_callbacks(:run) { run }
9
- rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
9
+ rescue ::EacCli::Runner::Exit
10
10
  # Do nothing
11
11
  end
12
12
 
@@ -35,7 +35,7 @@ module EacCli
35
35
  end
36
36
 
37
37
  def positionals
38
- alternative.positional.map { |p| positional(p) }.reject(&:blank?)
38
+ alternative.positional.map { |p| positional(p) }.compact_blank
39
39
  end
40
40
 
41
41
  def positional(positional)
@@ -26,7 +26,7 @@ module EacCli
26
26
 
27
27
  def option_usage_full(option)
28
28
  if option.long.present?
29
- [option.short, option_long(option)].reject(&:blank?).join(word_separator)
29
+ [option.short, option_long(option)].compact_blank.join(word_separator)
30
30
  else
31
31
  option_short(option)
32
32
  end
@@ -53,7 +53,7 @@ module EacCli
53
53
  def option_definition(option)
54
54
  [self.class.option_usage_full(option), option.description,
55
55
  option.default_value? ? "[Default: \"#{option.default_value}\"]" : nil]
56
- .reject(&:blank?).join(OPTION_DESCRIPTION_SEPARATOR)
56
+ .compact_blank.join(OPTION_DESCRIPTION_SEPARATOR)
57
57
  end
58
58
 
59
59
  # @return [String]
@@ -12,6 +12,7 @@ module EacCli
12
12
 
13
13
  runner_definition.alt do
14
14
  bool_opt '-h', '--help', 'Show help.', usage: true, required: true
15
+ any_opt
15
16
  pos_arg :any_arg_with_help, repeat: true, optional: true, visible: false
16
17
  end
17
18
 
@@ -105,7 +105,7 @@ module EacCli
105
105
  raise(::EacCli::Parser::Error.new(
106
106
  self.class.runner_definition, runner_context.argv,
107
107
  "Subcommand \"#{subcommand_name}\" not found " \
108
- "(Available: #{available_subcommands_to_s})"
108
+ "(Available: #{available_subcommands_to_s})"
109
109
  ))
110
110
  end
111
111
 
@@ -33,7 +33,7 @@ module EacCli
33
33
  private
34
34
 
35
35
  def namespace_set
36
- @namespace_set ||= ::Array.new
36
+ @namespace_set ||= []
37
37
  end
38
38
 
39
39
  def key_to_module(key)
@@ -17,11 +17,11 @@ module EacCli
17
17
  private
18
18
 
19
19
  def hash_to_values(list)
20
- list.map { |key, value| ::OpenStruct.new(key: key, label: key, value: value) }
20
+ list.map { |key, value| ::OpenStruct.new(key: key, label: key, value: value) } # rubocop:disable Style/OpenStructUse
21
21
  end
22
22
 
23
23
  def array_to_values(list)
24
- list.map { |value| ::OpenStruct.new(key: value, label: value, value: value) }
24
+ list.map { |value| ::OpenStruct.new(key: value, label: value, value: value) } # rubocop:disable Style/OpenStructUse
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ module EacCli
29
29
 
30
30
  def initialize(values)
31
31
  @values = values.map do |v|
32
- ::OpenStruct.new(key: to_key(v.key), label: to_label(v.label), value: v.value)
32
+ ::OpenStruct.new(key: to_key(v.key), label: to_label(v.label), value: v.value) # rubocop:disable Style/OpenStructUse
33
33
  end
34
34
  end
35
35
 
@@ -51,7 +51,7 @@ module EacCli
51
51
 
52
52
  def build_value(value)
53
53
  key = to_key(value)
54
- values.each do |v| # rubocop:disable Style/HashEachMethods
54
+ values.each do |v|
55
55
  return v.value if v.key == key
56
56
  end
57
57
  raise "Value not found: \"#{value}\" (#{values})"
@@ -11,15 +11,15 @@ module EacCli
11
11
  end
12
12
 
13
13
  def err_out
14
- option(OPTION_ERR_OUT, ::EacCli::Speaker::STDERR)
14
+ option(OPTION_ERR_OUT, $stderr)
15
15
  end
16
16
 
17
17
  def out_out
18
- option(OPTION_OUT_OUT, ::EacCli::Speaker::STDOUT)
18
+ option(OPTION_OUT_OUT, $stdout)
19
19
  end
20
20
 
21
21
  def in_in
22
- option(OPTION_IN_IN, ::EacCli::Speaker::STDIN)
22
+ option(OPTION_IN_IN, $stdin)
23
23
  end
24
24
 
25
25
  def err_line_prefix
@@ -83,7 +83,8 @@ module EacCli
83
83
  def list_value(list, input)
84
84
  values = list_values(list)
85
85
  return input, true unless values
86
- return input, false unless values.include?(input)
86
+
87
+ [input, false] unless values.include?(input)
87
88
  end
88
89
 
89
90
  def list_values(list)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.37.0'
4
+ VERSION = '0.38.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.37.0
4
+ version: 0.38.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-07-22 00:00:00.000000000 Z
11
+ date: 2023-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: '0.119'
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.119.1
56
+ version: 0.119.2
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,21 +63,21 @@ dependencies:
63
63
  version: '0.119'
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 0.119.1
66
+ version: 0.119.2
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: eac_ruby_gem_support
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: 0.5.1
73
+ version: 0.8.1
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 0.5.1
80
+ version: 0.8.1
81
81
  description:
82
82
  email:
83
83
  executables: []
@@ -109,6 +109,7 @@ files:
109
109
  - lib/eac_cli/old_configs/store_passwords_entry_reader.rb
110
110
  - lib/eac_cli/parser.rb
111
111
  - lib/eac_cli/parser/alternative.rb
112
+ - lib/eac_cli/parser/alternative/any_options.rb
112
113
  - lib/eac_cli/parser/alternative/argv.rb
113
114
  - lib/eac_cli/parser/alternative/double_dash.rb
114
115
  - lib/eac_cli/parser/alternative/long_options.rb
@@ -173,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
174
  requirements:
174
175
  - - ">="
175
176
  - !ruby/object:Gem::Version
176
- version: '0'
177
+ version: 2.7.0
177
178
  required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  requirements:
179
180
  - - ">="