eac_cli 0.36.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: fd9008aa3fd4b63d3bf1d901377a2efc3a257ccf1eba103cf74cf3f480ef9b95
4
- data.tar.gz: ea3e787fe4c7ae277a06ab501ed74098ecad0f6beb27367400010f8696717db6
3
+ metadata.gz: c8e016c3cb10caefe2fcc4f81d73dbdf76cff97a0e11ecb49f4b8378be238b7a
4
+ data.tar.gz: 676cf803931311818d97ea9a5421e360e16a36495e93a2cf90a938afdb526562
5
5
  SHA512:
6
- metadata.gz: da6e58e10afa32f283293d775814e0b4e0cd35374807f5fec4b581efc73995d8483460d79c2758aead99ac00d64069714c1c6b3c815b3f177da7991a779e1568
7
- data.tar.gz: 27ac60328b39f15651cce3263dc3c195b69e2e9ad2a87340f0ec863fc33ee04d8aba9895c93e60360e1d011da2448e55029ba76b4d859377f4b7b4716a1dfe50
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
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/acts_as_abstract'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module OutputItem
9
+ class BaseFormatter
10
+ acts_as_abstract :to_output
11
+ common_constructor :item_hash
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_cli/runner_with/output_item/base_formatter'
6
+
7
+ module EacCli
8
+ module RunnerWith
9
+ module OutputItem
10
+ class CsvFormatter < ::EacCli::RunnerWith::OutputItem::BaseFormatter
11
+ COLUMNS = %w[key value].freeze
12
+
13
+ # @return [String]
14
+ def to_output
15
+ ::CSV.generate do |csv|
16
+ csv << COLUMNS
17
+ item_hash.each { |k, v| csv << [k, v] }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/runner_with/output_item/base_formatter'
5
+ require 'yaml'
6
+
7
+ module EacCli
8
+ module RunnerWith
9
+ module OutputItem
10
+ class YamlFormatter < ::EacCli::RunnerWith::OutputItem::BaseFormatter
11
+ # @return [String]
12
+ def to_output
13
+ ::YAML.dump(item_hash.deep_stringify_keys)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/output'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/acts_as_abstract'
6
+
7
+ module EacCli
8
+ module RunnerWith
9
+ module OutputItem
10
+ require_sub __FILE__
11
+
12
+ FORMATS = {
13
+ 'csv' => ::EacCli::RunnerWith::OutputItem::CsvFormatter,
14
+ 'yaml' => ::EacCli::RunnerWith::OutputItem::YamlFormatter
15
+ }.freeze
16
+
17
+ common_concern do
18
+ acts_as_abstract :item_hash
19
+ include ::EacCli::RunnerWith::Output
20
+
21
+ runner_definition do
22
+ arg_opt '-f', '--format', 'Format to output item.', default: 'yaml'
23
+ end
24
+ end
25
+
26
+ # @return [String]
27
+ def output_content
28
+ formatter.to_output
29
+ end
30
+
31
+ # @return [EacCli::RunnerWith::OutputList::BaseFormatter]
32
+ def formatter
33
+ formatter_class.new(item_hash)
34
+ end
35
+
36
+ # @return [Class]
37
+ def formatter_class
38
+ FORMATS.fetch(parsed.format)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -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.36.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.36.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-02 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
@@ -51,6 +51,9 @@ dependencies:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0.119'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.119.2
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,20 +61,23 @@ dependencies:
58
61
  - - "~>"
59
62
  - !ruby/object:Gem::Version
60
63
  version: '0.119'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.119.2
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: eac_ruby_gem_support
63
69
  requirement: !ruby/object:Gem::Requirement
64
70
  requirements:
65
71
  - - "~>"
66
72
  - !ruby/object:Gem::Version
67
- version: 0.5.1
73
+ version: 0.8.1
68
74
  type: :development
69
75
  prerelease: false
70
76
  version_requirements: !ruby/object:Gem::Requirement
71
77
  requirements:
72
78
  - - "~>"
73
79
  - !ruby/object:Gem::Version
74
- version: 0.5.1
80
+ version: 0.8.1
75
81
  description:
76
82
  email:
77
83
  executables: []
@@ -103,6 +109,7 @@ files:
103
109
  - lib/eac_cli/old_configs/store_passwords_entry_reader.rb
104
110
  - lib/eac_cli/parser.rb
105
111
  - lib/eac_cli/parser/alternative.rb
112
+ - lib/eac_cli/parser/alternative/any_options.rb
106
113
  - lib/eac_cli/parser/alternative/argv.rb
107
114
  - lib/eac_cli/parser/alternative/double_dash.rb
108
115
  - lib/eac_cli/parser/alternative/long_options.rb
@@ -138,6 +145,10 @@ files:
138
145
  - lib/eac_cli/runner_with/help/layout.rb
139
146
  - lib/eac_cli/runner_with/input.rb
140
147
  - lib/eac_cli/runner_with/output.rb
148
+ - lib/eac_cli/runner_with/output_item.rb
149
+ - lib/eac_cli/runner_with/output_item/base_formatter.rb
150
+ - lib/eac_cli/runner_with/output_item/csv_formatter.rb
151
+ - lib/eac_cli/runner_with/output_item/yaml_formatter.rb
141
152
  - lib/eac_cli/runner_with/output_list.rb
142
153
  - lib/eac_cli/runner_with/output_list/base_formatter.rb
143
154
  - lib/eac_cli/runner_with/output_list/csv_formatter.rb
@@ -163,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
174
  requirements:
164
175
  - - ">="
165
176
  - !ruby/object:Gem::Version
166
- version: '0'
177
+ version: 2.7.0
167
178
  required_rubygems_version: !ruby/object:Gem::Requirement
168
179
  requirements:
169
180
  - - ">="