ehbrs-tools 0.13.1 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +1 -1
- data/lib/ehbrs/runner.rb +4 -7
- data/lib/ehbrs/runner/finances.rb +4 -7
- data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
- data/lib/ehbrs/runner/fs.rb +4 -7
- data/lib/ehbrs/runner/fs/used_space.rb +4 -5
- data/lib/ehbrs/runner/google.rb +4 -7
- data/lib/ehbrs/runner/google/translate.rb +7 -12
- data/lib/ehbrs/runner/self.rb +4 -7
- data/lib/ehbrs/runner/self/test.rb +5 -10
- data/lib/ehbrs/runner/vg.rb +4 -7
- data/lib/ehbrs/runner/vg/ips.rb +9 -14
- data/lib/ehbrs/runner/vg/wii.rb +10 -13
- data/lib/ehbrs/runner/videos.rb +7 -14
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +32 -0
- data/lib/ehbrs/runner/videos/series.rb +5 -8
- data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
- data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
- data/lib/ehbrs/runner/web_utils.rb +24 -0
- data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
- data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
- data/lib/ehbrs/videos/file.rb +2 -1
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/vendor/aranha-parsers/Gemfile +5 -0
- data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
- data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +70 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
- data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
- data/vendor/eac_cli/lib/eac_cli/definition.rb +35 -3
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
- data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +4 -9
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +27 -64
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +47 -19
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +51 -10
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +20 -3
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +48 -40
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
- data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
- data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
- data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
- data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
- metadata +85 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_cli/parser/error'
|
3
4
|
require 'eac_ruby_utils/core_ext'
|
4
5
|
|
5
6
|
module EacCli
|
@@ -8,6 +9,20 @@ module EacCli
|
|
8
9
|
common_constructor :definition, :argv
|
9
10
|
|
10
11
|
def result
|
12
|
+
result_or_error = parse(definition)
|
13
|
+
return result_or_error unless result_or_error.is_a?(::Exception)
|
14
|
+
|
15
|
+
definition.alternatives.each do |alternative|
|
16
|
+
alt_result_or_error = parse(alternative)
|
17
|
+
return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
|
18
|
+
end
|
19
|
+
|
20
|
+
raise result_or_error
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse(definition)
|
11
26
|
::EacCli::Parser::Collector.to_data(definition) do |collector|
|
12
27
|
::EacCli::Parser::PositionalCollection.new(
|
13
28
|
definition,
|
@@ -15,6 +30,8 @@ module EacCli
|
|
15
30
|
collector
|
16
31
|
)
|
17
32
|
end
|
33
|
+
rescue ::EacCli::Parser::Error => e
|
34
|
+
e
|
18
35
|
end
|
19
36
|
end
|
20
37
|
end
|
@@ -10,39 +10,67 @@ module EacCli
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
def argv_enum
|
14
|
+
@argv_enum ||= argv.each
|
15
|
+
end
|
16
|
+
|
17
|
+
def argv_pending?
|
18
|
+
argv_enum.ongoing?
|
19
|
+
end
|
20
|
+
|
21
|
+
def argv_pending_check
|
22
|
+
return unless argv_pending?
|
23
|
+
return unless positional_enum.stopped?
|
24
|
+
|
25
|
+
raise ::EacCli::Parser::Error.new(
|
26
|
+
definition, argv, "No positional left for argv \"#{argv_enum.current}\""
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
13
30
|
def collected
|
14
31
|
@collected ||= ::Set.new
|
15
32
|
end
|
16
33
|
|
17
34
|
def collect
|
18
|
-
|
19
|
-
|
35
|
+
loop do
|
36
|
+
break unless enums('pending?').any?
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
38
|
+
enums('pending_check')
|
39
|
+
collect_argv_value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def collect_argv_value
|
44
|
+
collector.collect(*enums('enum', &:peek))
|
45
|
+
collected << positional_enum.peek
|
46
|
+
positional_enum.next unless positional_enum.peek.repeat?
|
47
|
+
argv_enum.next
|
25
48
|
end
|
26
49
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
50
|
+
def enums(method_suffix, &block)
|
51
|
+
%w[positional argv].map do |method_prefix|
|
52
|
+
v = send("#{method_prefix}_#{method_suffix}")
|
53
|
+
block ? block.call(v) : v
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
|
-
def
|
34
|
-
|
35
|
-
collected.include?(current_positional))
|
57
|
+
def positional_enum
|
58
|
+
@positional_enum ||= definition.positional.each
|
36
59
|
end
|
37
60
|
|
38
|
-
def
|
39
|
-
|
61
|
+
def positional_pending?
|
62
|
+
!(positional_enum.stopped? || positional_enum.current.optional? ||
|
63
|
+
collected.include?(positional_enum.current))
|
40
64
|
end
|
41
65
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
66
|
+
def positional_pending_check
|
67
|
+
return unless positional_pending?
|
68
|
+
return unless argv_enum.stopped?
|
69
|
+
|
70
|
+
raise ::EacCli::Parser::Error.new(
|
71
|
+
definition, argv, 'No value for required positional ' \
|
72
|
+
"\"#{positional_enum.current.identifier}\""
|
73
|
+
)
|
46
74
|
end
|
47
75
|
end
|
48
76
|
end
|
@@ -0,0 +1,25 @@
|
|
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, &block)
|
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
|
+
runner_definition(&block) if block
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def runner_with_to_module(runner)
|
21
|
+
return runner if runner.is_a?(::Module)
|
22
|
+
|
23
|
+
"EacCli::RunnerWith::#{runner.to_s.camelize}".constantize
|
24
|
+
end
|
25
|
+
end
|
@@ -10,40 +10,81 @@ 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
|
+
def runner?(object)
|
22
|
+
object.is_a?(::Class) && object.included_modules.include?(::EacCli::Runner)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def alias_class_method(klass, from, to)
|
28
|
+
sklass = klass.singleton_class
|
29
|
+
return unless sklass.method_defined?(from)
|
30
|
+
|
31
|
+
sklass.alias_method to, from
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_method_name(name, suffix)
|
35
|
+
ss = suffix.if_present('') { |s| "#{s}_" }
|
36
|
+
"#{ss}#{name}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
the_module = self
|
13
41
|
included do
|
14
|
-
|
42
|
+
the_module.alias_runner_class_methods(self, '', 'original')
|
43
|
+
|
44
|
+
extend AfterClassMethods
|
15
45
|
include InstanceMethods
|
16
46
|
::EacCli::Docopt::RunnerExtension.check(self)
|
17
47
|
end
|
18
48
|
|
19
|
-
module
|
20
|
-
def create(*
|
49
|
+
module AfterClassMethods
|
50
|
+
def create(*runner_context_args)
|
21
51
|
r = new
|
22
|
-
r.
|
52
|
+
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
53
|
+
r
|
54
|
+
end
|
55
|
+
|
56
|
+
def run(*runner_context_args)
|
57
|
+
r = create(*runner_context_args)
|
58
|
+
r.parsed
|
59
|
+
r.run
|
23
60
|
r
|
24
61
|
end
|
25
62
|
|
26
63
|
def runner_definition(&block)
|
27
|
-
@runner_definition ||=
|
64
|
+
@runner_definition ||= super_runner_definition
|
28
65
|
@runner_definition.instance_eval(&block) if block
|
29
66
|
@runner_definition
|
30
67
|
end
|
68
|
+
|
69
|
+
def super_runner_definition
|
70
|
+
superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
|
71
|
+
end
|
31
72
|
end
|
32
73
|
|
33
74
|
module InstanceMethods
|
34
|
-
def
|
35
|
-
return @
|
75
|
+
def runner_context
|
76
|
+
return @runner_context if @runner_context
|
36
77
|
|
37
78
|
raise 'Context was required, but was not set yet'
|
38
79
|
end
|
39
80
|
|
40
|
-
def
|
41
|
-
@
|
81
|
+
def runner_context=(new_runner_context)
|
82
|
+
@runner_context = new_runner_context
|
42
83
|
@parsed = nil
|
43
84
|
end
|
44
85
|
|
45
86
|
def parsed
|
46
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(
|
87
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
|
47
88
|
end
|
48
89
|
end
|
49
90
|
end
|
@@ -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
|
@@ -0,0 +1,96 @@
|
|
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 Subcommands
|
9
|
+
common_concern do
|
10
|
+
include ::EacCli::Runner
|
11
|
+
end
|
12
|
+
|
13
|
+
EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
|
14
|
+
|
15
|
+
def available_subcommands
|
16
|
+
@available_subcommands ||= available_subcommands_auto.merge(available_subcommands_extra)
|
17
|
+
end
|
18
|
+
|
19
|
+
def available_subcommands_auto
|
20
|
+
self.class.constants
|
21
|
+
.map { |name| [name.to_s.underscore.gsub('_', '-'), self.class.const_get(name)] }
|
22
|
+
.select { |c| ::EacCli::Runner.runner?(c[1]) }
|
23
|
+
.to_h.with_indifferent_access
|
24
|
+
end
|
25
|
+
|
26
|
+
def available_subcommands_extra
|
27
|
+
if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
|
28
|
+
send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
|
29
|
+
else
|
30
|
+
{}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(method_name, *arguments, &block)
|
35
|
+
return run_with_subcommand(*arguments, &block) if
|
36
|
+
run_with_subcommand_alias_run?(method_name)
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def respond_to_missing?(method_name, include_private = false)
|
42
|
+
run_with_subcommand_alias_run?(method_name) || super
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_with_subcommand
|
46
|
+
if subcommand_name
|
47
|
+
subcommand_runner.run
|
48
|
+
else
|
49
|
+
run_without_subcommand
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run_with_subcommand_alias_run?(method_name)
|
54
|
+
subcommands? && method_name.to_sym == :run
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_without_subcommand
|
58
|
+
"Method #{__method__} should be overrided in #{self.class.name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def subcommands?
|
62
|
+
self.class.runner_definition.subcommands?
|
63
|
+
end
|
64
|
+
|
65
|
+
def subcommand_args
|
66
|
+
parsed.fetch(::EacCli::Definition::SUBCOMMAND_ARGS_ARG)
|
67
|
+
end
|
68
|
+
|
69
|
+
def subcommand_class
|
70
|
+
available_subcommands[subcommand_name].if_present { |v| return v }
|
71
|
+
|
72
|
+
raise(::EacCli::Parser::Error.new(
|
73
|
+
self.class.runner_definition, runner_context.argv,
|
74
|
+
"Subcommand \"#{subcommand_name}\" not found " \
|
75
|
+
"(Available: #{available_subcommands.keys}"
|
76
|
+
))
|
77
|
+
end
|
78
|
+
|
79
|
+
def subcommand_name
|
80
|
+
parsed.fetch(::EacCli::Definition::SUBCOMMAND_NAME_ARG)
|
81
|
+
end
|
82
|
+
|
83
|
+
def subcommand_program
|
84
|
+
subcommand_name
|
85
|
+
end
|
86
|
+
|
87
|
+
def subcommand_runner
|
88
|
+
@subcommand_runner ||= subcommand_class.create(
|
89
|
+
argv: subcommand_args,
|
90
|
+
program_name: subcommand_program,
|
91
|
+
parent: self
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|