ehbrs-tools 0.15.0 → 0.16.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +3 -5
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +6 -9
- 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 +5 -7
- data/lib/ehbrs/runner/web_utils/videos.rb +4 -6
- data/lib/ehbrs/runner/web_utils/videos/download.rb +8 -11
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +8 -11
- 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 +4 -8
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/track.rb +20 -10
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
- 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 +78 -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/definition.rb +49 -22
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
- data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner.rb +17 -5
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +101 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +59 -39
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +85 -0
- data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
- data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
- data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
- data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -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 +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- 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/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
- 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/module/abstract_methods.rb +10 -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/struct.rb +11 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- 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/common_concern_spec.rb +30 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- 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/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
- metadata +108 -13
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -5,13 +5,14 @@ require 'eac_cli/runner'
|
|
5
5
|
require 'eac_cli/runner_with'
|
6
6
|
|
7
7
|
class Object
|
8
|
-
def runner_with(*runners)
|
8
|
+
def runner_with(*runners, &block)
|
9
9
|
include ::EacCli::Runner
|
10
10
|
enable_simple_cache
|
11
11
|
enable_console_speaker
|
12
12
|
runners.each do |runner|
|
13
13
|
include runner_with_to_module(runner)
|
14
14
|
end
|
15
|
+
runner_definition(&block) if block
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -18,13 +18,17 @@ module EacCli
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def runner?(object)
|
22
|
+
object.is_a?(::Class) && object.included_modules.include?(::EacCli::Runner)
|
23
|
+
end
|
24
|
+
|
21
25
|
private
|
22
26
|
|
23
27
|
def alias_class_method(klass, from, to)
|
24
28
|
sklass = klass.singleton_class
|
25
29
|
return unless sklass.method_defined?(from)
|
26
30
|
|
27
|
-
sklass.alias_method to, from
|
31
|
+
sklass.send(:alias_method, to, from)
|
28
32
|
end
|
29
33
|
|
30
34
|
def build_method_name(name, suffix)
|
@@ -40,19 +44,20 @@ module EacCli
|
|
40
44
|
extend AfterClassMethods
|
41
45
|
include InstanceMethods
|
42
46
|
::EacCli::Docopt::RunnerExtension.check(self)
|
47
|
+
include ActiveSupport::Callbacks
|
48
|
+
define_callbacks :run
|
43
49
|
end
|
44
50
|
|
45
51
|
module AfterClassMethods
|
46
52
|
def create(*runner_context_args)
|
47
53
|
r = new
|
48
|
-
r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
|
54
|
+
r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
|
49
55
|
r
|
50
56
|
end
|
51
57
|
|
52
58
|
def run(*runner_context_args)
|
53
59
|
r = create(*runner_context_args)
|
54
|
-
r.
|
55
|
-
r.run
|
60
|
+
r.run_run
|
56
61
|
r
|
57
62
|
end
|
58
63
|
|
@@ -68,6 +73,13 @@ module EacCli
|
|
68
73
|
end
|
69
74
|
|
70
75
|
module InstanceMethods
|
76
|
+
def run_run
|
77
|
+
parsed
|
78
|
+
run_callbacks(:run) { run }
|
79
|
+
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
80
|
+
# Do nothing
|
81
|
+
end
|
82
|
+
|
71
83
|
def runner_context
|
72
84
|
return @runner_context if @runner_context
|
73
85
|
|
@@ -80,7 +92,7 @@ module EacCli
|
|
80
92
|
end
|
81
93
|
|
82
94
|
def parsed
|
83
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition
|
95
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
84
96
|
end
|
85
97
|
end
|
86
98
|
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
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
|
@@ -10,9 +10,26 @@ module EacCli
|
|
10
10
|
include ::EacCli::Runner
|
11
11
|
|
12
12
|
runner_definition.alt do
|
13
|
-
|
13
|
+
options_argument false
|
14
14
|
bool_opt '-h', '--help', 'Show help.', usage: true
|
15
15
|
end
|
16
|
+
|
17
|
+
set_callback :run, :before do
|
18
|
+
help_run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def help_run
|
23
|
+
return unless parsed.help?
|
24
|
+
|
25
|
+
puts help_text
|
26
|
+
raise ::EacCli::Runner::Exit
|
27
|
+
end
|
28
|
+
|
29
|
+
def help_text
|
30
|
+
r = ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
31
|
+
r += help_extra_text if respond_to?(:help_extra_text)
|
32
|
+
r
|
16
33
|
end
|
17
34
|
end
|
18
35
|
end
|
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'eac_cli/runner'
|
4
4
|
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/abstract_methods'
|
5
6
|
|
6
7
|
module EacCli
|
7
8
|
module RunnerWith
|
8
9
|
module OutputFile
|
9
10
|
common_concern do
|
10
11
|
include ::EacCli::Runner
|
12
|
+
include ::EacRubyUtils::AbstractMethods
|
13
|
+
|
14
|
+
abstract_methods :output_content
|
11
15
|
|
12
16
|
runner_definition do
|
13
17
|
arg_opt '-o', '--output-file', 'Output to file.'
|
@@ -18,7 +22,7 @@ module EacCli
|
|
18
22
|
if parsed.output_file.present?
|
19
23
|
::File.write(parsed.output_file, output_content)
|
20
24
|
else
|
21
|
-
|
25
|
+
$stdout.write(output_content)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -0,0 +1,101 @@
|
|
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 help_extra_text
|
35
|
+
(['Subcommands:'] + available_subcommands.keys.map { |s| " #{s}" })
|
36
|
+
.map { |v| "#{v}\n" }.join
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(method_name, *arguments, &block)
|
40
|
+
return run_with_subcommand(*arguments, &block) if
|
41
|
+
run_with_subcommand_alias_run?(method_name)
|
42
|
+
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def respond_to_missing?(method_name, include_private = false)
|
47
|
+
run_with_subcommand_alias_run?(method_name) || super
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_with_subcommand
|
51
|
+
if subcommand_name
|
52
|
+
subcommand_runner.run_run
|
53
|
+
else
|
54
|
+
run_without_subcommand
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_with_subcommand_alias_run?(method_name)
|
59
|
+
subcommands? && method_name.to_sym == :run
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_without_subcommand
|
63
|
+
"Method #{__method__} should be overrided in #{self.class.name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def subcommands?
|
67
|
+
self.class.runner_definition.subcommands?
|
68
|
+
end
|
69
|
+
|
70
|
+
def subcommand_args
|
71
|
+
parsed.fetch(::EacCli::Definition::SUBCOMMAND_ARGS_ARG)
|
72
|
+
end
|
73
|
+
|
74
|
+
def subcommand_class
|
75
|
+
available_subcommands[subcommand_name].if_present { |v| return v }
|
76
|
+
|
77
|
+
raise(::EacCli::Parser::Error.new(
|
78
|
+
self.class.runner_definition, runner_context.argv,
|
79
|
+
"Subcommand \"#{subcommand_name}\" not found " \
|
80
|
+
"(Available: #{available_subcommands.keys}"
|
81
|
+
))
|
82
|
+
end
|
83
|
+
|
84
|
+
def subcommand_name
|
85
|
+
parsed.fetch(::EacCli::Definition::SUBCOMMAND_NAME_ARG)
|
86
|
+
end
|
87
|
+
|
88
|
+
def subcommand_program
|
89
|
+
subcommand_name
|
90
|
+
end
|
91
|
+
|
92
|
+
def subcommand_runner
|
93
|
+
@subcommand_runner ||= subcommand_class.create(
|
94
|
+
argv: subcommand_args,
|
95
|
+
program_name: subcommand_program,
|
96
|
+
parent: self
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/definition/alternative'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Definition::Alternative do
|
6
|
+
let(:instance) { described_class.new }
|
7
|
+
|
8
|
+
it { expect { instance.arg_opt '-a', '--opt2', 'A argument option' }.not_to raise_error }
|
9
|
+
it { expect { instance.bool_opt '-b', '--opt1', 'A boolean option' }.not_to raise_error }
|
10
|
+
it { expect { instance.options_argument(true) }.not_to raise_error }
|
11
|
+
it { expect { instance.pos_arg :pos1 }.not_to raise_error }
|
12
|
+
it { expect { instance.pos_arg :pos2, optional: true, repeat: true }.not_to raise_error }
|
13
|
+
it { expect { instance.subcommands }.not_to raise_error }
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/runner_extension'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Docopt::RunnerExtension do
|
6
|
+
let(:stub_runner) do
|
7
|
+
r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
|
8
|
+
def run; end
|
9
|
+
end
|
10
|
+
r.include ::EacCli::Runner
|
11
|
+
r.runner_definition do
|
12
|
+
desc 'A stub runner.'
|
13
|
+
arg_opt '-o', '--opt1', 'A argument option'
|
14
|
+
pos_arg 'pos1'
|
15
|
+
end
|
16
|
+
r
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
|
20
|
+
|
21
|
+
before { instance.run }
|
22
|
+
|
23
|
+
it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
|
24
|
+
it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
|
25
|
+
it { expect(instance.doc).to eq(<<~EXPECTED) }
|
26
|
+
A stub runner.
|
27
|
+
|
28
|
+
Usage:
|
29
|
+
__PROGRAM__ [options] <pos1>
|
30
|
+
|
31
|
+
Options:
|
32
|
+
-o --opt1=<value> A argument option
|
33
|
+
|
34
|
+
EXPECTED
|
35
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/runner_extension'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Parser::Alternative do
|
6
|
+
let(:instance) { described_class.new(alternative, argv) }
|
7
|
+
let(:actual_parsed) { instance.parsed.to_h.symbolize_keys }
|
8
|
+
|
9
|
+
context 'without subcommands' do
|
10
|
+
let(:alternative) do
|
11
|
+
r = ::EacCli::Definition::Alternative.new
|
12
|
+
r.bool_opt '-b', '--opt1', 'A boolean option'
|
13
|
+
r.arg_opt '-a', '--opt2', 'A argument option'
|
14
|
+
r.bool_opt '-c', '--opt3', 'A required boolean option', required: true
|
15
|
+
r.pos_arg :pos1
|
16
|
+
r.pos_arg :pos2, optional: true, repeat: true
|
17
|
+
r
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with all values' do
|
21
|
+
let(:argv) { %w[--opt1 --opt2 OPT2 --opt3 POS1 POS2_1 POS2_2] }
|
22
|
+
let(:parsed_expected) do
|
23
|
+
{
|
24
|
+
opt1: true, opt2: 'OPT2', opt3: true, pos1: 'POS1', pos2: %w[POS2_1 POS2_2]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it { expect(instance.error).to be_blank }
|
29
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with only required values' do
|
33
|
+
let(:argv) { %w[--opt3 POS1] }
|
34
|
+
let(:parsed_expected) { { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: [] } }
|
35
|
+
|
36
|
+
it { expect(instance.error).to be_blank }
|
37
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with double dash' do
|
41
|
+
let(:argv) { %w[--opt3 POS1 -- --opt1 --] }
|
42
|
+
let(:parsed_expected) do
|
43
|
+
{ opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: %w[--opt1 --] }
|
44
|
+
end
|
45
|
+
|
46
|
+
it { expect(instance.error).to be_blank }
|
47
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'without required positional' do
|
51
|
+
let(:argv) { %w[--opt1 --opt3] }
|
52
|
+
let(:parsed_expected) { { opt1: true, opt2: nil, opt3: true, pos1: nil, pos2: [] } }
|
53
|
+
|
54
|
+
it { expect(instance.error).to be_present }
|
55
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'without required option' do
|
59
|
+
let(:argv) { %w[--opt1 POS1] }
|
60
|
+
let(:parsed_expected) { { opt1: true, opt2: nil, opt3: false, pos1: 'POS1', pos2: [] } }
|
61
|
+
|
62
|
+
it { expect(instance.error).to be_present }
|
63
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'without any required option or positional' do
|
67
|
+
let(:argv) { %w[] }
|
68
|
+
let(:parsed_expected) { { opt1: false, opt2: nil, opt3: false, pos1: nil, pos2: [] } }
|
69
|
+
|
70
|
+
it { expect(instance.error).to be_present }
|
71
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with excedent positional' do
|
75
|
+
let(:alternative) do
|
76
|
+
r = ::EacCli::Definition::Alternative.new
|
77
|
+
r.pos_arg :pos1
|
78
|
+
r
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:argv) { %w[POS1 POS2] }
|
82
|
+
let(:parsed_expected) { { pos1: 'POS1' } }
|
83
|
+
|
84
|
+
it { expect(instance.error).to be_present }
|
85
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with subcommands' do
|
90
|
+
let(:alternative) do
|
91
|
+
r = ::EacCli::Definition::Alternative.new
|
92
|
+
r.bool_opt '-b', '--opt1', 'A boolean option'
|
93
|
+
r.arg_opt '-a', '--opt2', 'A argument option'
|
94
|
+
r.subcommands
|
95
|
+
r
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with all values' do
|
99
|
+
let(:argv) { %w[--opt1 --opt2 OPT2 CMD CMD_ARG_1 --CMD_ARG_2] }
|
100
|
+
let(:parsed_expected) do
|
101
|
+
{
|
102
|
+
opt1: true, opt2: 'OPT2',
|
103
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
|
104
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => %w[CMD_ARG_1 --CMD_ARG_2]
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
it { expect(instance.error).to be_blank }
|
109
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with only required values' do
|
113
|
+
let(:argv) { %w[CMD] }
|
114
|
+
let(:parsed_expected) do
|
115
|
+
{
|
116
|
+
opt1: false, opt2: nil,
|
117
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
|
118
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
it { expect(instance.error).to be_blank }
|
123
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'without required values' do
|
127
|
+
let(:argv) { %w[--opt1] }
|
128
|
+
let(:parsed_expected) do
|
129
|
+
{
|
130
|
+
opt1: true, opt2: nil,
|
131
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => nil,
|
132
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
it { expect(instance.error).to be_present }
|
137
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|