eac_cli 0.14.0 → 0.16.2

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: 8ca942fefac703528e400de1a095cad1dd85d648895eabf7cfdf51ac430b34fe
4
- data.tar.gz: 73f8e8c595e7669756b134d35576a1a3f873b67dfda1def674ea02d4a60173a7
3
+ metadata.gz: 6b336c067e8d70a7f067881875fe4b2c040fa9548d068f5634466d98aeb5c6ee
4
+ data.tar.gz: ee2db632c41c4cd425ccec883a2a308400c3d004b6f76ab8d2834a0c7b0d203a
5
5
  SHA512:
6
- metadata.gz: 95cbcedfb77ca5d9fd3a3ffe2f818d9a8866d6774cc25bf3964f0a0fa1c81a3014afb6f3a26cb32393fd84fe76e56e159a5be22f0780e5d916b1d66f90a08961
7
- data.tar.gz: 4a9cf2040a0cdae39543379f3da011931d11bbc22c15aca1a0c88838a592215d80c6fd413b034f66c991487d7f6a5b32eecc9b9d29530c787aba09c3f48c4daa
6
+ metadata.gz: 45fc37951d2d381e9a9157ab07fa086e7272c0411018eb7ee561cab676a66522a898edbb8fb9abbf34cd55135c0f33aeaa641a8503bb4360521af580c02f2560
7
+ data.tar.gz: ffe16017e057939246dfc62d14b1736a1265cc8e1da100f7695047247befad721a079b8c03ebbb579cd382919e3292eb1d42bb293a4a3c8e65c9eb97c330c5fd
@@ -2,3 +2,5 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_cli/patches'
5
+
6
+ ::EacCli::RunnerWithSet.default.add_namespace(::EacCli::RunnerWith)
@@ -28,7 +28,11 @@ module EacCli
28
28
  end
29
29
 
30
30
  def identifier
31
- long.to_s.variableize.to_sym
31
+ [long, short].each do |v|
32
+ v.to_s.if_present { |vv| return vv.variableize.to_sym }
33
+ end
34
+
35
+ raise 'No short or long option to build identifier'
32
36
  end
33
37
 
34
38
  def repeat?
@@ -36,7 +36,9 @@ module EacCli
36
36
  end
37
37
 
38
38
  def option_definition(option)
39
- self.class.option_usage_full(option) + OPTION_DESC_SEP + option.description
39
+ self.class.option_usage_full(option) + option.description.if_present('') do |v|
40
+ OPTION_DESC_SEP + v
41
+ end
40
42
  end
41
43
 
42
44
  def section(header, include_header = true)
@@ -14,7 +14,9 @@ module EacCli
14
14
  end
15
15
 
16
16
  def find_short_option(char)
17
- alternative.options.find { |option| short_without_prefix(option.short) == char }
17
+ alternative.options.find do |option|
18
+ short_without_prefix(option.short).if_present(false) { |v| v == char }
19
+ end
18
20
  end
19
21
 
20
22
  def short_option_collect_argv_value
@@ -37,7 +39,7 @@ module EacCli
37
39
  end
38
40
 
39
41
  def short_without_prefix(short)
40
- short.gsub(/\A#{::Regexp.quote(SHORT_OPTION_PREFIX)}/, '')
42
+ short.to_s.gsub(/\A#{::Regexp.quote(SHORT_OPTION_PREFIX)}/, '')
41
43
  end
42
44
  end
43
45
  end
@@ -3,6 +3,7 @@
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_cli/runner'
5
5
  require 'eac_cli/runner_with'
6
+ require 'eac_cli/runner_with_set'
6
7
 
7
8
  class Object
8
9
  def runner_with(*runners, &block)
@@ -10,7 +11,7 @@ class Object
10
11
  enable_simple_cache
11
12
  enable_console_speaker
12
13
  runners.each do |runner|
13
- include runner_with_to_module(runner)
14
+ include ::EacCli::RunnerWithSet.default.item_to_module(runner)
14
15
  end
15
16
  runner_definition(&block) if block
16
17
  end
@@ -27,8 +27,9 @@ module EacCli
27
27
 
28
28
  def parent_call(method_name, *args)
29
29
  return parent.context(method_name, *args) if parent.respond_to?(:context)
30
+ return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)
30
31
 
31
- parent.runner_context.call(method_name, *args)
32
+ raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
32
33
  end
33
34
  end
34
35
  end
@@ -3,15 +3,22 @@
3
3
  module EacCli
4
4
  module Runner
5
5
  module InstanceMethods
6
+ PARSER_ERROR_EXIT_CODE = 1
7
+
6
8
  def run_run
7
9
  parsed
8
10
  run_callbacks(:run) { run }
9
11
  rescue ::EacCli::Parser::Error => e
10
- $stderr.write("#{e}\n")
12
+ run_parser_error(e)
11
13
  rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
12
14
  # Do nothing
13
15
  end
14
16
 
17
+ def run_parser_error(error)
18
+ $stderr.write("#{error}\n")
19
+ ::Kernel.exit(PARSER_ERROR_EXIT_CODE)
20
+ end
21
+
15
22
  def runner_context
16
23
  return @runner_context if @runner_context
17
24
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ class RunnerWithSet
5
+ class << self
6
+ def default
7
+ @default ||= new
8
+ end
9
+ end
10
+
11
+ def add_namespace(namespace)
12
+ namespace = sanitize_namespace(namespace)
13
+ raise "\"#{namespace}\" already was included" if namespace_set.include?(namespace)
14
+
15
+ namespace_set << namespace
16
+ self
17
+ end
18
+
19
+ def item_to_module(item)
20
+ item.is_a?(::Module) ? item : key_to_module(item)
21
+ end
22
+
23
+ def namespaces
24
+ namespace_set.dup
25
+ end
26
+
27
+ private
28
+
29
+ def namespace_set
30
+ @namespace_set ||= ::Array.new
31
+ end
32
+
33
+ def key_to_module(key)
34
+ namespace_set.lazy
35
+ .map { |namespace| key_to_module_in_namespace(namespace, key) }
36
+ .find(&:present?) ||
37
+ raise("Not module found with key \"#{key}\" (Namespaces: #{namespace_set})")
38
+ end
39
+
40
+ def key_to_module_in_namespace(namespace, key)
41
+ namespace.const_get(key.to_s.camelize)
42
+ rescue ::NameError
43
+ nil
44
+ end
45
+
46
+ def sanitize_namespace(source)
47
+ source.is_a?(::Module) ? source : source.to_s.constantize
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.14.0'
4
+ VERSION = '0.16.2'
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.14.0
4
+ version: 0.16.2
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: 2021-02-14 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -87,8 +87,8 @@ files:
87
87
  - lib/eac_cli/runner/instance_methods.rb
88
88
  - lib/eac_cli/runner_with.rb
89
89
  - lib/eac_cli/runner_with/help.rb
90
- - lib/eac_cli/runner_with/output_file.rb
91
90
  - lib/eac_cli/runner_with/subcommands.rb
91
+ - lib/eac_cli/runner_with_set.rb
92
92
  - lib/eac_cli/version.rb
93
93
  homepage:
94
94
  licenses: []
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.8
111
+ rubygems_version: 3.0.9
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Utilities to build CLI applications with Ruby.
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_cli/runner'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/abstract_methods'
6
-
7
- module EacCli
8
- module RunnerWith
9
- module OutputFile
10
- common_concern do
11
- include ::EacCli::Runner
12
- include ::EacRubyUtils::AbstractMethods
13
-
14
- abstract_methods :output_content
15
-
16
- runner_definition do
17
- arg_opt '-o', '--output-file', 'Output to file.'
18
- end
19
- end
20
-
21
- def run_output
22
- if parsed.output_file.present?
23
- ::File.write(parsed.output_file, output_content)
24
- else
25
- $stdout.write(output_content)
26
- end
27
- end
28
- end
29
- end
30
- end