ehbrs-tools 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) 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/fix_profile.rb +1 -0
  35. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  36. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  37. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  38. data/vendor/aranha-parsers/Gemfile +5 -0
  39. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  40. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  41. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  42. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  43. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  44. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  45. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  46. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  47. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  48. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  49. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  50. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  51. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  52. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  53. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  54. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  55. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  56. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  57. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  58. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  59. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  60. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  61. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  62. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  63. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  64. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  65. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  66. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  67. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  68. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  69. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  70. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  71. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  72. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  73. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  74. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  75. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  76. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  77. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  78. data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
  79. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
  80. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  81. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  82. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  83. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  84. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  85. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  86. data/vendor/eac_cli/lib/eac_cli/runner.rb +7 -3
  87. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  88. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -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 +57 -40
  96. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  97. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  107. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  117. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  118. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
  119. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  120. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  121. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  122. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  123. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  124. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  125. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  126. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  127. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  128. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  129. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  130. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  131. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  132. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  133. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  134. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  135. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  136. metadata +78 -7
  137. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  138. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  139. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  140. 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)
@@ -45,7 +49,7 @@ module EacCli
45
49
  module AfterClassMethods
46
50
  def create(*runner_context_args)
47
51
  r = new
48
- r.runner_context = ::EacCli::Runner::Context.new(*runner_context_args)
52
+ r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
49
53
  r
50
54
  end
51
55
 
@@ -80,7 +84,7 @@ module EacCli
80
84
  end
81
85
 
82
86
  def parsed
83
- @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
87
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
84
88
  end
85
89
  end
86
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
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,7 +10,7 @@ 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
16
  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
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.2'
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
@@ -4,67 +4,84 @@ require 'eac_ruby_utils/console/docopt_runner'
4
4
  require 'eac_cli/runner'
5
5
 
6
6
  RSpec.describe ::EacCli::Runner do
7
- let(:stub_runner) do
8
- r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
7
+ let(:runner_class) do
8
+ the_module = described_class
9
+ ::Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--opt1', 'A arg option.'
14
+ bool_opt '-o', '--opt2', 'A boolean option'
15
+ pos_arg :pos1
16
+ pos_arg :pos2, repeat: true, optional: true
17
+ alt do
18
+ bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
19
+ end
20
+ end
21
+
9
22
  def run; end
10
23
  end
11
- r.include described_class
12
- r.runner_definition do
13
- desc 'A stub runner.'
14
- arg_opt '-o', '--opt1', 'A argument option'
15
- pos_arg 'pos1'
16
- end
17
- r
18
24
  end
19
25
 
20
- let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
26
+ let(:instance) { runner_class.create(argv) }
27
+ let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
28
+
29
+ context 'when all args are supplied' do
30
+ let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
31
+ let(:parsed_expected) { { opt1: 'aaa', opt2: true, pos1: 'bbb', pos2: %w[ccc ddd] } }
32
+
33
+ it { expect(parsed_actual).to eq(parsed_expected) }
34
+ it { expect(instance.parsed.opt1).to eq('aaa') }
35
+ it { expect(instance.parsed.opt2?).to eq(true) }
36
+ it { expect(instance.parsed.pos1).to eq('bbb') }
37
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
38
+ end
39
+
40
+ context 'when only required args are supplied' do
41
+ let(:argv) { %w[bbb] }
42
+ let(:parsed_expected) { { opt1: nil, opt2: false, pos1: 'bbb', pos2: [] } }
21
43
 
22
- before { instance.run }
44
+ it { expect(parsed_actual).to eq(parsed_expected) }
45
+ it { expect(instance.parsed.opt1).to be_nil }
46
+ it { expect(instance.parsed.opt2?).to eq(false) }
47
+ it { expect(instance.parsed.pos1).to eq('bbb') }
48
+ it { expect(instance.parsed.pos2).to eq([]) }
49
+ end
23
50
 
24
- it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
25
- it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
51
+ context 'when required args are not supplied' do
52
+ let(:argv) { %w[] }
26
53
 
27
- context 'without docopt runner' do
54
+ it do
55
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
56
+ end
57
+ end
58
+
59
+ context 'when alternative args are supplied' do
60
+ let(:argv) { %w[--opt3] }
61
+ let(:parsed_expected) { { opt3: true } }
62
+
63
+ it { expect(parsed_actual).to eq(parsed_expected) }
64
+ it { expect(instance.parsed.opt3?).to eq(true) }
65
+ end
66
+
67
+ context 'when extra args are not supplied' do
28
68
  let(:runner_class) do
29
69
  the_module = described_class
30
70
  ::Class.new do
31
71
  include the_module
32
72
 
33
73
  runner_definition do
34
- arg_opt '-o', '--opt1', 'A arg option.'
35
- bool_opt '-o', '--opt2', 'A boolean option'
36
74
  pos_arg :pos1
37
- pos_arg :pos2, repeat: true, optional: true
38
75
  end
39
76
 
40
77
  def run; end
41
78
  end
42
79
  end
43
80
 
44
- context 'when all args are supplied' do
45
- let(:instance) { runner_class.create(%w[--opt1 aaa --opt2 bbb ccc ddd]) }
46
-
47
- it { expect(instance.parsed.opt1).to eq('aaa') }
48
- it { expect(instance.parsed.opt2?).to eq(true) }
49
- it { expect(instance.parsed.pos1).to eq('bbb') }
50
- it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
51
- end
81
+ let(:argv) { %w[aaa bbb] }
52
82
 
53
- context 'when only required args are supplied' do
54
- let(:instance) { runner_class.create(%w[bbb]) }
55
-
56
- it { expect(instance.parsed.opt1).to be_nil }
57
- it { expect(instance.parsed.opt2?).to eq(false) }
58
- it { expect(instance.parsed.pos1).to eq('bbb') }
59
- it { expect(instance.parsed.pos2).to eq([]) }
60
- end
61
-
62
- context 'when required args are not supplied' do
63
- let(:instance) { runner_class.create(%w[]) }
64
-
65
- it do
66
- expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
67
- end
83
+ it do
84
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
68
85
  end
69
86
  end
70
87
  end