eac_cli 0.5.1 → 0.9.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 +4 -4
- data/lib/eac_cli/core_ext.rb +4 -0
- data/lib/eac_cli/default_runner.rb +6 -14
- data/lib/eac_cli/docopt/runner_extension.rb +3 -9
- data/lib/eac_cli/patches.rb +4 -0
- data/lib/eac_cli/patches/object.rb +5 -0
- data/lib/eac_cli/patches/object/runner_with.rb +24 -0
- data/lib/eac_cli/runner.rb +41 -4
- data/lib/eac_cli/runner/context.rb +20 -3
- data/lib/eac_cli/runner_with.rb +9 -0
- data/lib/eac_cli/runner_with/help.rb +19 -0
- data/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/lib/eac_cli/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d373480947d50978fb88bb6e55a1296d644fcae95eb3b39a7a4127250cf14e2
|
4
|
+
data.tar.gz: 350598588e6cb04bf5fca9cc626f8a1d662167dc5dee9fbc60bd231e2279aa0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 074cf7d6fe38050884bb0578d1dcd6a7b02bb384d0634bfec15d8d53b03945dc789bf7654aba4a491145e4c9bb8a7366e1a2a799ce00709e0af2940ca97004ba
|
7
|
+
data.tar.gz: 4da66cb205f1e58cb0c4fffb491d0d4e7aa38f7a6eeb7d7d67caa7c0f0e2177e2e98366639de29f9e588fc329c21051334d6696515e1c82711d1b2b8ec6e95b7
|
@@ -1,22 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
::EacCli::Runner.alias_runner_class_methods(klass, '', 'eac_cli')
|
20
|
+
::EacCli::Runner.alias_runner_class_methods(klass, 'original', '')
|
23
21
|
|
24
|
-
|
25
|
-
def create(*context_args)
|
26
|
-
r = new(*context_args)
|
27
|
-
r.runner_context = ::EacCli::Runner::Context.new(*context_args)
|
28
|
-
r
|
22
|
+
klass.include(self)
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
@@ -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
|
data/lib/eac_cli/runner.rb
CHANGED
@@ -10,24 +10,61 @@ 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
|
-
|
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
|
45
|
+
module AfterClassMethods
|
20
46
|
def create(*runner_context_args)
|
21
47
|
r = new
|
22
|
-
r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
|
48
|
+
r.runner_context = ::EacCli::Runner::Context.new(r, *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 ||=
|
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
|
@@ -5,13 +5,30 @@ require 'eac_ruby_utils/core_ext'
|
|
5
5
|
module EacCli
|
6
6
|
module Runner
|
7
7
|
class Context
|
8
|
-
attr_reader :argv, :parent, :program_name
|
8
|
+
attr_reader :argv, :parent, :program_name, :runner
|
9
9
|
|
10
|
-
def initialize(*context_args)
|
10
|
+
def initialize(runner, *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
|
+
@runner = runner
|
16
|
+
end
|
17
|
+
|
18
|
+
# Call a method in the runner or in one of it ancestors.
|
19
|
+
def call(method_name, *args)
|
20
|
+
return runner.send(method_name, *args) if runner.respond_to?(method_name)
|
21
|
+
return parent_call(method_name, *args) if parent.present?
|
22
|
+
|
23
|
+
raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def parent_call(method_name, *args)
|
29
|
+
return parent.context(method_name, *args) if parent.respond_to?(:context)
|
30
|
+
|
31
|
+
parent.runner_context.call(method_name, *args)
|
15
32
|
end
|
16
33
|
end
|
17
34
|
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
|
data/lib/eac_cli/version.rb
CHANGED
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.
|
4
|
+
version: 0.9.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-
|
11
|
+
date: 2020-10-14 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: []
|