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
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_address'
4
+
5
+ RSpec.describe ::Aranha::Parsers::SourceAddress do
6
+ describe '#detect_sub' do
7
+ {
8
+ { method: :post, url: 'http://postdata.net', params: { key1: :value1 } } => {
9
+ klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
10
+ url: 'http://postdata.net',
11
+ serialization: <<~SERIALIZATION
12
+ --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
13
+ method: :post
14
+ url: http://postdata.net
15
+ params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
16
+ key1: :value1
17
+ SERIALIZATION
18
+ },
19
+ { method: :get, url: 'http://getdata.net', params: { headers: %w[abc] } } => {
20
+ klass: ::Aranha::Parsers::SourceAddress::HashHttpPost,
21
+ url: 'http://getdata.net',
22
+ serialization: <<~SERIALIZATION
23
+ --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
24
+ method: :get
25
+ url: http://getdata.net
26
+ params: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
27
+ headers:
28
+ - abc
29
+ SERIALIZATION
30
+ },
31
+ 'http://postdata.net' => {
32
+ klass: ::Aranha::Parsers::SourceAddress::HttpGet,
33
+ url: 'http://postdata.net',
34
+ serialization: 'http://postdata.net'
35
+ },
36
+ 'https://getdata.com.br' => {
37
+ klass: ::Aranha::Parsers::SourceAddress::HttpGet,
38
+ url: 'https://getdata.com.br',
39
+ serialization: 'https://getdata.com.br'
40
+ },
41
+ 'file:///postdata.net' => {
42
+ klass: ::Aranha::Parsers::SourceAddress::File,
43
+ url: 'file:///postdata.net',
44
+ serialization: 'file:///postdata.net'
45
+ },
46
+ '/postdata.net' => {
47
+ klass: ::Aranha::Parsers::SourceAddress::File,
48
+ url: 'file:///postdata.net',
49
+ serialization: 'file:///postdata.net'
50
+ }
51
+ }.each do |source, expected|
52
+ context "when source is #{source}" do
53
+ let(:sub) { described_class.detect_sub(source) }
54
+ let(:deserialized) { described_class.deserialize(sub.serialize).sub }
55
+
56
+ it "sub is a #{expected.fetch(:klass)}" do
57
+ expect(sub).to be_a(expected.fetch(:klass))
58
+ end
59
+
60
+ it "sub #{expected.fetch(:klass)} return properly URL" do
61
+ expect(sub.url).to eq(expected.fetch(:url))
62
+ end
63
+
64
+ it "sub #{expected.fetch(:klass)} serialize properly" do
65
+ expect(sub.serialize).to eq(expected.fetch(:serialization))
66
+ end
67
+
68
+ it 'deserialize properly' do
69
+ expect(deserialized).to eq(sub)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_target_fixtures'
4
+
5
+ RSpec.describe ::Aranha::Parsers::SourceTargetFixtures do
6
+ let(:fixtures_dir) { ::File.join(__dir__, 'source_target_fixtures_spec_files') }
7
+ let(:instance) { described_class.new(fixtures_dir) }
8
+
9
+ describe '#source_target_files' do
10
+ it { expect(instance.source_target_files.count).to eq(3) }
11
+
12
+ (1..3).each do |index|
13
+ basename = "stub#{index}"
14
+ let(basename) { instance.source_target_files.find { |stf| stf.basename == basename } }
15
+
16
+ it { expect(send(basename)).to be_present }
17
+ it { expect(send(basename).basename).to eq(basename) }
18
+ end
19
+
20
+ it { expect(stub1.source).to eq(::File.join(fixtures_dir, 'stub1.source.txt')) }
21
+ it { expect(stub1.target).to eq(::File.join(fixtures_dir, 'stub1.target.html')) }
22
+ it { expect(stub2.source).to eq(::File.join(fixtures_dir, 'stub2.source.html')) }
23
+ it { expect(stub2.target).to eq(nil) }
24
+ it { expect(stub3.source).to eq(nil) }
25
+ it { expect(stub3.target).to eq(::File.join(fixtures_dir, 'stub3.target.yaml')) }
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/spec/examples/rubocop_check'
4
+
5
+ RSpec.describe ::RuboCop do
6
+ include_examples 'rubocop_check', ::File.expand_path('../..', __dir__)
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __dir__)
4
+ require 'tmpdir'
5
+
6
+ RSpec.configure do |config|
7
+ config.example_status_persistence_file_path = ::File.join(::Dir.tmpdir, 'aranha-parsers_rspec')
8
+ end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*', 'Gemfile']
14
14
 
15
- s.add_dependency 'eac_ruby_utils', '~> 0.45'
15
+ s.add_dependency 'eac_ruby_utils', '~> 0.55'
16
16
 
17
17
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
18
18
  end
@@ -8,57 +8,66 @@ require 'eac_ruby_utils/core_ext'
8
8
  module EacCli
9
9
  class Definition
10
10
  require_sub __FILE__
11
+
12
+ MAIN_ALTERNATIVE_KEY = :main
13
+ SUBCOMMAND_NAME_ARG = 'subcommand'
14
+ SUBCOMMAND_ARGS_ARG = 'subcommand_args'
15
+
11
16
  attr_accessor :description
12
- attr_accessor :options_argument
13
17
 
14
18
  def initialize
15
19
  self.description = '-- NO DESCRIPTION SET --'
16
- self.options_argument = true
20
+ alternatives_set[MAIN_ALTERNATIVE_KEY] = main_alternative
17
21
  end
18
22
 
19
23
  def alt(&block)
20
- r = ::EacCli::Definition.new
24
+ r = ::EacCli::Definition::Alternative.new
21
25
  r.instance_eval(&block)
22
- alternatives << r
26
+ alternatives_set[new_alternative_key] = r
23
27
  r
24
28
  end
25
29
 
26
30
  def alternatives
27
- @alternatives ||= []
28
- end
29
-
30
- def arg_opt(short, long, description, option_options = {})
31
- options << ::EacCli::Definition::ArgumentOption.new(
32
- short, long, description, option_options
33
- )
31
+ alternatives_set.values
34
32
  end
35
33
 
36
- def bool_opt(short, long, description, option_options = {})
37
- options << ::EacCli::Definition::BooleanOption.new(short, long, description, option_options)
34
+ def alternative(key)
35
+ alternatives_set.fetch(key)
38
36
  end
39
37
 
40
38
  def desc(description)
41
39
  self.description = description
42
40
  end
43
41
 
42
+ def help_formatter
43
+ @help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
44
+ end
45
+
46
+ def main_alternative
47
+ @main_alternative ||= begin
48
+ r = ::EacCli::Definition::Alternative.new
49
+ r.options_argument(true)
50
+ r
51
+ end
52
+ end
53
+
44
54
  def options_arg(options_argument)
45
55
  self.options_argument = options_argument
46
56
  end
47
57
 
48
- def options
49
- @options ||= []
58
+ def options_argument
59
+ main_alternative.options_argument?
50
60
  end
51
61
 
52
- def pos_arg(name, arg_options = {})
53
- positional << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
62
+ def options_argument=(enable)
63
+ main_alternative.options_argument(enable)
54
64
  end
55
65
 
56
- def positional
57
- @positional ||= []
58
- end
66
+ delegate :arg_opt, :bool_opt, :options, :pos_arg,
67
+ :positional, :subcommands, to: :main_alternative
59
68
 
60
- def subcommands
61
- positional << ::EacCli::Definition::PositionalArgument.new('subcommand', subcommand: true)
69
+ def subcommands?
70
+ alternatives.any?(&:subcommands?)
62
71
  end
63
72
 
64
73
  def options_first(enable = true)
@@ -68,5 +77,23 @@ module EacCli
68
77
  def options_first?
69
78
  @options_first ? true : false
70
79
  end
80
+
81
+ private
82
+
83
+ def alternatives_set
84
+ @alternatives_set ||= ::ActiveSupport::HashWithIndifferentAccess.new
85
+ end
86
+
87
+ def new_alternative_key
88
+ @last_key ||= 0
89
+ loop do
90
+ @last_key += 1
91
+ break @last_key unless alternatives_set.key?(@last_key)
92
+ end
93
+ end
94
+
95
+ def pos_set
96
+ @pos_set ||= []
97
+ end
71
98
  end
72
99
  end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/definition/argument_option'
4
+ require 'eac_cli/definition/boolean_option'
5
+ require 'eac_cli/definition/positional_argument'
6
+
7
+ module EacCli
8
+ class Definition
9
+ class Alternative
10
+ SUBCOMMAND_NAME_ARG = :subcommand
11
+ SUBCOMMAND_ARGS_ARG = :subcommand_args
12
+
13
+ def arg_opt(short, long, description, option_options = {})
14
+ options_set << ::EacCli::Definition::ArgumentOption.new(
15
+ short, long, description, option_options
16
+ )
17
+ end
18
+
19
+ def bool_opt(short, long, description, option_options = {})
20
+ options_set << ::EacCli::Definition::BooleanOption.new(short, long, description,
21
+ option_options)
22
+ end
23
+
24
+ def options
25
+ options_set.to_a
26
+ end
27
+
28
+ def options_argument?
29
+ @options_argument ? true : false
30
+ end
31
+
32
+ def options_argument(enable)
33
+ @options_argument = enable
34
+
35
+ self
36
+ end
37
+
38
+ def pos_arg(name, arg_options = {})
39
+ new_pos_arg = ::EacCli::Definition::PositionalArgument.new(name, arg_options)
40
+ check_positional_blocked(new_pos_arg)
41
+ pos_set << new_pos_arg
42
+ end
43
+
44
+ def positional
45
+ pos_set.to_a
46
+ end
47
+
48
+ def positional_arguments_blocked?(new_pos_arg)
49
+ last = pos_set.last
50
+ return false unless last
51
+ return true if subcommands?
52
+ return true if last.repeat?
53
+ return true if last.optional? && new_pos_arg.if_present(&:required?)
54
+
55
+ false
56
+ end
57
+
58
+ def subcommands
59
+ pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
60
+ pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
61
+ optional: true, repeat: true)
62
+ end
63
+
64
+ def subcommands?
65
+ pos_set.any?(&:subcommand?)
66
+ end
67
+
68
+ private
69
+
70
+ def check_positional_blocked(new_pos_arg)
71
+ raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
72
+ end
73
+
74
+ def pos_set
75
+ @pos_set ||= []
76
+ end
77
+
78
+ def options_set
79
+ @options_set ||= []
80
+ end
81
+ end
82
+ end
83
+ end
@@ -5,19 +5,35 @@ require 'eac_ruby_utils/core_ext'
5
5
  module EacCli
6
6
  class Definition
7
7
  class BaseOption
8
+ DEFAULT_REQUIRED = false
9
+
10
+ enable_listable
11
+ lists.add_symbol :option, :optional, :usage, :required
8
12
  attr_reader :short, :long, :description, :options
9
13
 
10
14
  def initialize(short, long, description, options = {})
11
15
  @short = short
12
16
  @long = long
13
17
  @description = description
14
- @options = options.with_indifferent_access
18
+ @options = options.symbolize_keys
19
+ @options.assert_valid_keys(::EacCli::Definition::BaseOption.lists.option.values)
15
20
  end
16
21
 
17
22
  def identifier
18
23
  long.to_s.variableize.to_sym
19
24
  end
20
25
 
26
+ def required?
27
+ return true if options.key?(:required) && options.fetch(:required)
28
+ return false if options.key?(:optional) && options.fetch(:optional)
29
+
30
+ DEFAULT_REQUIRED
31
+ end
32
+
33
+ def to_s
34
+ "#{self.class.name.demodulize}[#{identifier}]"
35
+ end
36
+
21
37
  def show_on_usage?
22
38
  options[:usage]
23
39
  end
@@ -1,49 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
- require 'optparse'
5
4
 
6
5
  module EacCli
7
- class Parser
8
- class OptionsCollection
6
+ class Definition
7
+ class HelpFormatter
9
8
  SEP = ' '
10
9
  IDENT = SEP * 2
11
10
  OPTION_DESC_SEP = IDENT * 2
12
11
 
13
- enable_simple_cache
14
- common_constructor(:definition, :argv, :collector) { collect }
15
- attr_reader :arguments
16
-
17
- private
18
-
19
- def collect
20
- build_banner
21
- build_options
22
- @arguments = option_parser.parse(argv)
23
- end
24
-
25
- def option_parser_uncached
26
- ::OptionParser.new
27
- end
28
-
29
- def build_banner
30
- option_parser.banner = "#{definition.description}\n\n#{section('usage')}"
31
- end
32
-
33
- def build_options
34
- definition.options.each do |option|
35
- build_option(option)
12
+ class << self
13
+ def option_long(option)
14
+ b = option.long
15
+ b += '=VALUE' if option.argument?
16
+ b
36
17
  end
37
- end
38
18
 
39
- def build_option(option)
40
- option_parser.on(
41
- *[option_short(option), option_long(option), option.description].reject(&:blank?)
42
- ) do |value|
43
- collector.collect(option, value)
19
+ def option_short(option)
20
+ b = option.short
21
+ b += 'VALUE' if option.argument?
22
+ b
44
23
  end
45
24
  end
46
25
 
26
+ common_constructor :definition
27
+
47
28
  def positional_argument(positional)
48
29
  if positional.subcommand?
49
30
  ::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
@@ -55,22 +36,6 @@ module EacCli
55
36
  end
56
37
  end
57
38
 
58
- def option_argument(option)
59
- option_long(option)
60
- end
61
-
62
- def option_long(option)
63
- b = option.long
64
- b += '=VALUE' if option.argument?
65
- b
66
- end
67
-
68
- def option_short(option)
69
- b = option.short
70
- b += 'VALUE' if option.argument?
71
- b
72
- end
73
-
74
39
  def section(header, include_header = true)
75
40
  b = include_header ? "#{header.humanize}:\n" : ''
76
41
  b += send("self_#{header}") + "\n"
@@ -94,12 +59,18 @@ module EacCli
94
59
  end
95
60
 
96
61
  def self_usage_arguments_options
97
- definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
62
+ definition.options.select(&:show_on_usage?).map do |option|
63
+ self.class.option_long(option)
64
+ end
98
65
  end
99
66
 
100
67
  def self_usage_arguments_positional
101
68
  definition.positional.map { |p| positional_argument(p) }
102
69
  end
70
+
71
+ def to_banner
72
+ "#{definition.description}\n\n#{section('usage')}"
73
+ end
103
74
  end
104
75
  end
105
76
  end