eac_cli 0.5.0 → 0.8.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: 22db6b0edb02623b574dc9545e67dc42ac19d35ec6da4010b0c463c886aacfe3
4
- data.tar.gz: 8164b097784d2d63d805de366c830a0313bdd244a4656326ace4c01faa17ac52
3
+ metadata.gz: 2b936a1bc75006a7969bd549ed89750bf7b09ccebf5d77e35a7b2443ad7175b5
4
+ data.tar.gz: 812fb927a263d8d6aa74600631db16eb07e626217ec1e81614bdf5f1031d7ef7
5
5
  SHA512:
6
- metadata.gz: d013970f6550f09e9ff0411326ee6b014b4685c33b7f96ff1c3db2321521114b33746e87bac97fa4f96c779b4efff8f1d420c88b93319998a08c7c10d288342f
7
- data.tar.gz: 1d3c695a9c107e69a54062e5e2fa4cd6ebaa9b9e935a6902e185078eb2ff0fbdffb7c6d83e252d892702ec2b6a8c305a55269f1e05d67af0daeadabe9e8fa2bb
6
+ metadata.gz: 4b2331aa69dd79cf797ab64305f3b088ee012cfe53e71ef0d0f00ec1f84ed2f5bc849e70a9745e17e43d591fc7e02ae9b061870b4d2b27cb93c51385c12780f8
7
+ data.tar.gz: a62b07e41f454aa85015be5b39a3e427ab41b2afffdacfbf998ce1a261a49bf82c0711e95f7bb42b449fb3b41178dee666124a76eeaeee993c9fe6fdc7a6baf5
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/patches'
@@ -1,22 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/concern'
4
- require 'eac_cli/runner'
5
- require 'eac_ruby_utils/console/speaker'
6
- require 'eac_ruby_utils/simple_cache'
3
+ require 'eac_cli/runner_with/help'
4
+ require 'eac_ruby_utils/core_ext'
7
5
 
8
6
  module EacCli
9
7
  module DefaultRunner
10
- extend ::ActiveSupport::Concern
11
-
12
- included do
13
- include ::EacCli::Runner
14
- include ::EacRubyUtils::Console::Speaker
15
- include ::EacRubyUtils::SimpleCache
16
- runner_definition.alt do
17
- options_arg false
18
- bool_opt '-h', '--help', 'Show help.', usage: true
19
- end
8
+ common_concern do
9
+ include ::EacCli::RunnerWith::Help
10
+ enable_console_speaker
11
+ enable_simple_cache
20
12
  end
21
13
  end
22
14
  end
@@ -9,7 +9,6 @@ module EacCli
9
9
  extend ::ActiveSupport::Concern
10
10
 
11
11
  included do
12
- singleton_class.prepend ClassMethods
13
12
  prepend InstanceMethods
14
13
  end
15
14
 
@@ -17,15 +16,10 @@ module EacCli
17
16
  def check(klass)
18
17
  return unless klass < ::EacRubyUtils::Console::DocoptRunner
19
18
 
20
- klass.include(self)
21
- end
22
- end
19
+ ::EacCli::Runner.alias_runner_class_methods(klass, '', 'eac_cli')
20
+ ::EacCli::Runner.alias_runner_class_methods(klass, 'original', '')
23
21
 
24
- module ClassMethods
25
- def create(*context_args)
26
- r = new(*context_args)
27
- r.context = ::EacCli::Runner::Context.new(*context_args)
28
- r
22
+ klass.include(self)
29
23
  end
30
24
  end
31
25
 
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].sort.each do |path|
4
+ require path
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/runner'
5
+ require 'eac_cli/runner_with'
6
+
7
+ class Object
8
+ def runner_with(*runners)
9
+ include ::EacCli::Runner
10
+ enable_simple_cache
11
+ enable_console_speaker
12
+ runners.each do |runner|
13
+ include runner_with_to_module(runner)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def runner_with_to_module(runner)
20
+ return runner if runner.is_a?(::Module)
21
+
22
+ "EacCli::RunnerWith::#{runner.to_s.camelize}".constantize
23
+ end
24
+ end
@@ -10,40 +10,77 @@ module EacCli
10
10
  require_sub __FILE__
11
11
  extend ::ActiveSupport::Concern
12
12
 
13
+ class << self
14
+ def alias_runner_class_methods(klass, from_suffix, to_suffix)
15
+ %i[create run].each do |method|
16
+ alias_class_method(klass, build_method_name(method, from_suffix),
17
+ build_method_name(method, to_suffix))
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def alias_class_method(klass, from, to)
24
+ sklass = klass.singleton_class
25
+ return unless sklass.method_defined?(from)
26
+
27
+ sklass.alias_method to, from
28
+ end
29
+
30
+ def build_method_name(name, suffix)
31
+ ss = suffix.if_present('') { |s| "#{s}_" }
32
+ "#{ss}#{name}"
33
+ end
34
+ end
35
+
36
+ the_module = self
13
37
  included do
14
- extend ClassMethods
38
+ the_module.alias_runner_class_methods(self, '', 'original')
39
+
40
+ extend AfterClassMethods
15
41
  include InstanceMethods
16
42
  ::EacCli::Docopt::RunnerExtension.check(self)
17
43
  end
18
44
 
19
- module ClassMethods
20
- def create(*context_args)
45
+ module AfterClassMethods
46
+ def create(*runner_context_args)
21
47
  r = new
22
- r.context = ::EacCli::Runner::Context.new(*context_args)
48
+ r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
49
+ r
50
+ end
51
+
52
+ def run(*runner_context_args)
53
+ r = create(*runner_context_args)
54
+ r.parsed
55
+ r.run
23
56
  r
24
57
  end
25
58
 
26
59
  def runner_definition(&block)
27
- @runner_definition ||= ::EacCli::Definition.new
60
+ @runner_definition ||= super_runner_definition
28
61
  @runner_definition.instance_eval(&block) if block
29
62
  @runner_definition
30
63
  end
64
+
65
+ def super_runner_definition
66
+ superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
67
+ end
31
68
  end
32
69
 
33
70
  module InstanceMethods
34
- def context
35
- return @context if @context
71
+ def runner_context
72
+ return @runner_context if @runner_context
36
73
 
37
74
  raise 'Context was required, but was not set yet'
38
75
  end
39
76
 
40
- def context=(new_context)
41
- @context = new_context
77
+ def runner_context=(new_runner_context)
78
+ @runner_context = new_runner_context
42
79
  @parsed = nil
43
80
  end
44
81
 
45
82
  def parsed
46
- @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(context.argv)
83
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
47
84
  end
48
85
  end
49
86
  end
@@ -9,7 +9,7 @@ module EacCli
9
9
 
10
10
  def initialize(*context_args)
11
11
  options = context_args.extract_options!
12
- @argv = (context_args[0] || options.delete(:argv)).freeze
12
+ @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
13
13
  @parent = context_args[1] || options.delete(:parent)
14
14
  @program_name = options.delete(:program_name)
15
15
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module Help
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition.alt do
13
+ options_arg false
14
+ bool_opt '-h', '--help', 'Show help.', usage: true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ module RunnerWith
8
+ module OutputFile
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--output-file', 'Output to file.'
14
+ end
15
+ end
16
+
17
+ def run_output
18
+ if parsed.output_file.present?
19
+ ::File.write(parsed.output_file, output_content)
20
+ else
21
+ out output_content
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.5.0'
4
+ VERSION = '0.8.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.5.0
4
+ version: 0.8.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: 2020-09-13 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -52,6 +52,7 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - Gemfile
54
54
  - lib/eac_cli.rb
55
+ - lib/eac_cli/core_ext.rb
55
56
  - lib/eac_cli/default_runner.rb
56
57
  - lib/eac_cli/definition.rb
57
58
  - lib/eac_cli/definition/argument_option.rb
@@ -66,8 +67,14 @@ files:
66
67
  - lib/eac_cli/parser/options_collection.rb
67
68
  - lib/eac_cli/parser/parse_result.rb
68
69
  - lib/eac_cli/parser/positional_collection.rb
70
+ - lib/eac_cli/patches.rb
71
+ - lib/eac_cli/patches/object.rb
72
+ - lib/eac_cli/patches/object/runner_with.rb
69
73
  - lib/eac_cli/runner.rb
70
74
  - lib/eac_cli/runner/context.rb
75
+ - lib/eac_cli/runner_with.rb
76
+ - lib/eac_cli/runner_with/help.rb
77
+ - lib/eac_cli/runner_with/output_file.rb
71
78
  - lib/eac_cli/version.rb
72
79
  homepage:
73
80
  licenses: []