ehbrs-tools 0.14.1 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner.rb +4 -7
  3. data/lib/ehbrs/runner/finances.rb +4 -7
  4. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  5. data/lib/ehbrs/runner/fs.rb +4 -7
  6. data/lib/ehbrs/runner/fs/used_space.rb +4 -5
  7. data/lib/ehbrs/runner/google.rb +4 -7
  8. data/lib/ehbrs/runner/google/translate.rb +7 -12
  9. data/lib/ehbrs/runner/self.rb +4 -7
  10. data/lib/ehbrs/runner/self/test.rb +5 -10
  11. data/lib/ehbrs/runner/vg.rb +4 -7
  12. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  13. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  14. data/lib/ehbrs/runner/videos.rb +3 -5
  15. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  16. data/lib/ehbrs/runner/videos/probe.rb +6 -9
  17. data/lib/ehbrs/runner/videos/series.rb +5 -8
  18. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  19. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  20. data/lib/ehbrs/runner/web_utils.rb +24 -0
  21. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  22. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  23. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  26. data/lib/ehbrs/videos/file.rb +4 -8
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/track.rb +20 -10
  29. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
  30. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
  31. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
  32. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
  33. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  34. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  35. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  36. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  37. data/vendor/aranha-parsers/Gemfile +5 -0
  38. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  39. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  40. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  41. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  42. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  43. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  44. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  45. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  46. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  47. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  48. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  49. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  50. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  51. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  52. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  53. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  54. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  55. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  56. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  57. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  58. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  59. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  60. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  61. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  62. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  63. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  64. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  65. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  66. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  67. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  68. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  69. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  70. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  71. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  72. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  73. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  74. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  75. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  76. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  77. data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
  78. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
  79. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  80. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  81. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  82. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  83. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  84. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  85. data/vendor/eac_cli/lib/eac_cli/runner.rb +17 -5
  86. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  87. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  88. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +16 -1
  89. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  90. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  91. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  92. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  93. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
  94. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  95. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +59 -39
  96. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  97. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  98. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +56 -0
  99. data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
  100. data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
  101. data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
  102. data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
  103. data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
  104. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
  105. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
  106. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
  107. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
  117. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  118. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  119. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
  120. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  121. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  122. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  123. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  124. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  125. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  126. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  127. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  128. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  129. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  130. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  131. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  132. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  133. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  134. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  135. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  136. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +11 -1
  137. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  138. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  139. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  140. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  141. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  142. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  143. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  144. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  145. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  146. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  147. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  148. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  149. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  150. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  151. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  152. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  153. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  154. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  155. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  156. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  157. metadata +91 -7
  158. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  159. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  160. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  161. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -31,6 +31,10 @@ module EacCli
31
31
  end
32
32
  end
33
33
 
34
+ def supplied?(option)
35
+ data[option].present?
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def data
@@ -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.parsed
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).parse(runner_context.argv)
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
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacCli
4
+ module Runner
5
+ class Exit < ::StandardError
6
+ attr_reader :status
7
+
8
+ def initialize(status = true)
9
+ @status = status
10
+ end
11
+ end
12
+ end
13
+ end
@@ -10,9 +10,24 @@ module EacCli
10
10
  include ::EacCli::Runner
11
11
 
12
12
  runner_definition.alt do
13
- options_arg false
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
+ ::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
16
31
  end
17
32
  end
18
33
  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
- out output_content
25
+ $stdout.write(output_content)
22
26
  end
23
27
  end
24
28
  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_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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacCli
4
- VERSION = '0.8.0'
4
+ VERSION = '0.12.3'
5
5
  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