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
@@ -4,67 +4,87 @@ 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'
24
+ end
25
+
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) do
32
+ { opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
33
+ pos2: %w[ccc ddd] }
16
34
  end
17
- r
35
+
36
+ it { expect(parsed_actual).to eq(parsed_expected) }
37
+ it { expect(instance.parsed.opt1).to eq('aaa') }
38
+ it { expect(instance.parsed.opt2?).to eq(true) }
39
+ it { expect(instance.parsed.pos1).to eq('bbb') }
40
+ it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
41
+ end
42
+
43
+ context 'when only required args are supplied' do
44
+ let(:argv) { %w[bbb] }
45
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
46
+
47
+ it { expect(parsed_actual).to eq(parsed_expected) }
48
+ it { expect(instance.parsed.opt1).to be_nil }
49
+ it { expect(instance.parsed.opt2?).to eq(false) }
50
+ it { expect(instance.parsed.pos1).to eq('bbb') }
51
+ it { expect(instance.parsed.pos2).to eq([]) }
18
52
  end
19
53
 
20
- let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
54
+ context 'when required args are not supplied' do
55
+ let(:argv) { %w[] }
21
56
 
22
- before { instance.run }
57
+ it do
58
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
59
+ end
60
+ end
61
+
62
+ context 'when alternative args are supplied' do
63
+ let(:argv) { %w[--opt3] }
64
+ let(:parsed_expected) { { opt1: nil, opt2: false, opt3: true, pos1: nil, pos2: [] } }
23
65
 
24
- it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
25
- it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
66
+ it { expect(parsed_actual).to eq(parsed_expected) }
67
+ it { expect(instance.parsed.opt3?).to eq(true) }
68
+ end
26
69
 
27
- context 'without docopt runner' do
70
+ context 'when extra args are not supplied' do
28
71
  let(:runner_class) do
29
72
  the_module = described_class
30
73
  ::Class.new do
31
74
  include the_module
32
75
 
33
76
  runner_definition do
34
- arg_opt '-o', '--opt1', 'A arg option.'
35
- bool_opt '-o', '--opt2', 'A boolean option'
36
77
  pos_arg :pos1
37
- pos_arg :pos2, repeat: true, optional: true
38
78
  end
39
79
 
40
80
  def run; end
41
81
  end
42
82
  end
43
83
 
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
84
+ let(:argv) { %w[aaa bbb] }
52
85
 
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
86
+ it do
87
+ expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
68
88
  end
69
89
  end
70
90
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/help'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Help do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub runner.'
14
+ pos_arg :a_argument
15
+ end
16
+
17
+ def run
18
+ puts 'Runner run'
19
+ end
20
+ end
21
+ end
22
+
23
+ let(:runner_argv) { ['--help'] }
24
+ let(:instance) { runner.create(argv: runner_argv) }
25
+ let(:expected_output) do
26
+ <<~OUTPUT
27
+ A stub runner.
28
+
29
+ Usage:
30
+ __PROGRAM__ [options] <a_argument>
31
+ __PROGRAM__ --help
32
+
33
+ Options:
34
+ -h --help Show help.
35
+
36
+ OUTPUT
37
+ end
38
+
39
+ it 'show help text' do
40
+ expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
41
+ end
42
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner_with/output_file'
4
+ require 'eac_ruby_utils/fs/temp'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::OutputFile do
7
+ let(:runner) do
8
+ the_module = described_class
9
+ Class.new do
10
+ include the_module
11
+
12
+ runner_definition do
13
+ desc 'A stub root runner.'
14
+ pos_arg :input_text
15
+ end
16
+
17
+ def run
18
+ run_output
19
+ end
20
+
21
+ def output_content
22
+ parsed.input_text
23
+ end
24
+ end
25
+ end
26
+
27
+ let(:stub_text) { 'STUB_TEXT' }
28
+ let(:instance) { runner.create(argv: runner_argv) }
29
+
30
+ context 'without --output-file option' do
31
+ let(:runner_argv) { [stub_text] }
32
+
33
+ it do
34
+ expect { instance.run }.to output(stub_text).to_stdout_from_any_process
35
+ end
36
+ end
37
+
38
+ context 'with --output-file option' do
39
+ let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
40
+ let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
41
+
42
+ before do
43
+ instance.run
44
+ end
45
+
46
+ after do
47
+ output_file.remove
48
+ end
49
+
50
+ it { expect(output_file).to exist }
51
+ it { expect(output_file.read).to eq(stub_text) }
52
+ end
53
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_cli/runner_with/subcommands'
5
+
6
+ RSpec.describe ::EacCli::RunnerWith::Subcommands do
7
+ let(:parent_runner) do
8
+ the_module = described_class
9
+ the_child = child_runner
10
+ Class.new do
11
+ include the_module
12
+ const_set('ChildCmd', the_child)
13
+
14
+ runner_definition do
15
+ desc 'A stub root runner.'
16
+ arg_opt '-r', '--root-var', 'A root variable.'
17
+ subcommands
18
+ end
19
+
20
+ delegate :root_var, to: :parsed
21
+ end
22
+ end
23
+
24
+ let(:child_runner) do
25
+ ::Class.new do
26
+ include ::EacCli::Runner
27
+
28
+ runner_definition do
29
+ bool_opt '-c', '--child-opt', 'A boolean option.'
30
+ pos_arg :child_var
31
+ end
32
+
33
+ def run; end
34
+ end
35
+ end
36
+
37
+ let(:instance) { parent_runner.create(argv: parent_argv) }
38
+
39
+ context 'when subcommand is supplied' do
40
+ let(:parent_argv) { %w[--root-var 123 child-cmd --child-opt 456] }
41
+
42
+ it { expect(instance.parsed.root_var).to eq('123') }
43
+ it { expect(instance.parsed.subcommand).to eq('child-cmd') }
44
+ it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
45
+ it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
46
+ it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
47
+ end
48
+
49
+ context 'when subcommand is not supplied' do
50
+ let(:instance) { parent_runner.create(%w[456]) }
51
+
52
+ it do
53
+ expect { instance.run }.to raise_error(::EacCli::Parser::Error)
54
+ end
55
+ end
56
+ end
@@ -8,6 +8,7 @@ module EacDocker
8
8
  immutable_accessor :interactive, :temporary, :tty, type: :boolean
9
9
  immutable_accessor :env, type: :hash
10
10
  immutable_accessor :command_arg, :volume, type: :array
11
+ attr_reader :id
11
12
  common_constructor :image
12
13
 
13
14
  def immutable_constructor_args
@@ -16,6 +17,23 @@ module EacDocker
16
17
 
17
18
  alias immutable_volume volume
18
19
 
20
+ def hostname
21
+ ::EacDocker::Executables.docker.command(
22
+ 'inspect', '--format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
23
+ id
24
+ ).execute!.strip
25
+ end
26
+
27
+ def on_detached
28
+ command = ::EacDocker::Executables.docker.command(*(%w[run --detach] + run_command_args))
29
+ self.id = command.execute!.strip
30
+ begin
31
+ yield(self)
32
+ ensure
33
+ stop
34
+ end
35
+ end
36
+
19
37
  def volume(left_part, right_part = null)
20
38
  immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
21
39
  end
@@ -29,8 +47,14 @@ module EacDocker
29
47
  command_args
30
48
  end
31
49
 
50
+ def stop
51
+ ::EacDocker::Executables.docker.command('stop', id).execute!
52
+ end
53
+
32
54
  private
33
55
 
56
+ attr_writer :id
57
+
34
58
  def run_command_boolean_args
35
59
  r = []
36
60
  r << '--interactive' if interactive?
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+ require 'eac_docker/images/base'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EacDocker
8
+ module Images
9
+ class Coded < ::EacDocker::Images::Base
10
+ enable_simple_cache
11
+ enable_immutable
12
+ immutable_accessor :tag
13
+ common_constructor :path do
14
+ self.path = path.to_pathname
15
+ end
16
+
17
+ def immutable_constructor_args
18
+ [path]
19
+ end
20
+
21
+ def provide
22
+ id
23
+ self
24
+ end
25
+
26
+ private
27
+
28
+ def id_uncached
29
+ ::EacDocker::Executables.docker.command(*build_args).execute!.strip
30
+ end
31
+
32
+ def build_args
33
+ args = %w[build --quiet]
34
+ args += ['--tag', tag] if tag.present?
35
+ args + [path.to_path]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/base'
4
+ require 'eac_docker/images/coded'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/fs/temp'
7
+
8
+ module EacDocker
9
+ module Images
10
+ class Templatized < ::EacDocker::Images::Base
11
+ enable_immutable
12
+ immutable_accessor :tag
13
+
14
+ def provide
15
+ ::EacRubyUtils::Fs::Temp.on_directory do |provide_dir|
16
+ template.apply(self, provide_dir)
17
+ coded_image(provide_dir).tag(tag).provide
18
+ end
19
+ end
20
+
21
+ def coded_image(provide_dir)
22
+ ::EacDocker::Images::Coded.new(provide_dir)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacDocker
6
+ class Registry
7
+ common_constructor :name
8
+
9
+ def to_s
10
+ name
11
+ end
12
+
13
+ def sub(suffix)
14
+ self.class.new("#{name}#{suffix}")
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacDocker
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/coded'
4
+
5
+ RSpec.describe(::EacDocker::Images::Coded, docker: true) do
6
+ let(:fixtures_dir) { ::Pathname.new('coded_spec_files').expand_path(__dir__) }
7
+ let(:instance) { described_class.new(fixtures_dir / 'image1') }
8
+
9
+ describe '#provide' do
10
+ it { expect { instance.provide }.not_to raise_error }
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/images/templatized'
4
+
5
+ RSpec.describe(::EacDocker::Images::Templatized, docker: true) do
6
+ let(:fixtures_dir) { ::Pathname.new('templatized_spec_files').expand_path(__dir__) }
7
+ let(:instance) { StubDockerImage.new }
8
+
9
+ before do
10
+ ::EacRubyUtils::Templates::Searcher.default.included_paths << fixtures_dir
11
+ stub_const('StubDockerImage', Class.new(described_class))
12
+ end
13
+
14
+ describe '#provide' do
15
+ it { expect { instance.provide }.not_to raise_error }
16
+ end
17
+ end