ehbrs-tools 0.9.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/gems.rb +37 -0
- data/lib/ehbrs/google.rb +9 -0
- data/lib/ehbrs/google/translate.rb +11 -0
- data/lib/ehbrs/google/translate/session.rb +61 -0
- data/lib/ehbrs/runner.rb +9 -13
- data/lib/ehbrs/runner/finances.rb +19 -0
- data/lib/ehbrs/runner/finances/bb_browser.rb +40 -0
- data/lib/ehbrs/runner/fs/used_space.rb +4 -4
- data/lib/ehbrs/runner/google.rb +19 -0
- data/lib/ehbrs/runner/google/translate.rb +92 -0
- data/lib/ehbrs/runner/self.rb +19 -0
- data/lib/ehbrs/runner/self/test.rb +30 -0
- data/lib/ehbrs/runner/videos/series.rb +21 -0
- data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/videos/series.rb +11 -0
- data/lib/ehbrs/videos/series/rename.rb +13 -0
- data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
- data/lib/ehbrs/videos/series/rename/file.rb +114 -0
- data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
- data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
- data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
- data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
- data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
- data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
- data/vendor/aranha-selenium/Gemfile +5 -0
- data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
- data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
- data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
- data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
- data/vendor/eac_cli/eac_cli.gemspec +3 -3
- data/vendor/eac_cli/lib/eac_cli/definition.rb +72 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/{runner → definition}/base_option.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/{runner → definition}/positional_argument.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +51 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +56 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +105 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +21 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +49 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +25 -5
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +18 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +70 -0
- data/vendor/eac_docker/Gemfile +5 -0
- data/vendor/eac_docker/eac_docker.gemspec +18 -0
- data/vendor/eac_docker/lib/eac_docker.rb +7 -0
- data/vendor/eac_docker/lib/eac_docker/container.rb +50 -0
- data/vendor/eac_docker/lib/eac_docker/executables.rb +18 -0
- data/vendor/eac_docker/lib/eac_docker/images.rb +9 -0
- data/vendor/eac_docker/lib/eac_docker/images/base.rb +14 -0
- data/vendor/eac_docker/lib/eac_docker/images/named.rb +30 -0
- data/vendor/eac_docker/lib/eac_docker/rspec.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +5 -0
- data/vendor/eac_docker/spec/lib/eac_docker/executables_spec.rb +9 -0
- data/vendor/eac_docker/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_docker/spec/spec_helper.rb +103 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +3 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable.rb +15 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +32 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/base_accessor.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/boolean_accessor.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/class_methods.rb +20 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/common_accessor.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/instance_methods.rb +21 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/immutable.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +72 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +47 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +8 -59
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_not_found_error.rb +7 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/base.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/generic.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/variable_providers/hash.rb +29 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby_spec.rb +22 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
- data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
- metadata +103 -10
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/struct'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class Parser
|
8
|
+
class Collector
|
9
|
+
class << self
|
10
|
+
def to_data(definition)
|
11
|
+
collector = new(definition)
|
12
|
+
yield(collector)
|
13
|
+
collector.to_data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
common_constructor :definition do
|
18
|
+
default_values
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [OpenStruct]
|
22
|
+
def to_data
|
23
|
+
::EacRubyUtils::Struct.new(data.transform_keys(&:identifier))
|
24
|
+
end
|
25
|
+
|
26
|
+
def collect(option, value)
|
27
|
+
if data[option].is_a?(::Array)
|
28
|
+
data[option] << value
|
29
|
+
else
|
30
|
+
data[option] = value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def data
|
37
|
+
@data ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_values
|
41
|
+
definition.options.each { |option| data[option] = option_default_value(option) }
|
42
|
+
definition.positional.each do |positional|
|
43
|
+
data[positional] = positional_default_value(positional)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def option_default_value(option)
|
48
|
+
option.argument? ? nil : false
|
49
|
+
end
|
50
|
+
|
51
|
+
def positional_default_value(positional)
|
52
|
+
positional.repeat? ? [] : nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Parser
|
7
|
+
class Error < ::StandardError
|
8
|
+
def initialize(definition, argv, message)
|
9
|
+
@definition = definition
|
10
|
+
@argv = argv
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class Parser
|
8
|
+
class OptionsCollection
|
9
|
+
SEP = ' '
|
10
|
+
IDENT = SEP * 2
|
11
|
+
OPTION_DESC_SEP = IDENT * 2
|
12
|
+
|
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)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
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)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def positional_argument(positional)
|
48
|
+
if positional.subcommand?
|
49
|
+
::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
|
50
|
+
else
|
51
|
+
r = "<#{positional.name}>"
|
52
|
+
r += '...' if positional.repeat?
|
53
|
+
r = "[#{r}]" if positional.optional?
|
54
|
+
r
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
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
|
+
def section(header, include_header = true)
|
75
|
+
b = include_header ? "#{header.humanize}:\n" : ''
|
76
|
+
b += send("self_#{header}") + "\n"
|
77
|
+
# TO-DO: implement alternatives
|
78
|
+
b
|
79
|
+
end
|
80
|
+
|
81
|
+
def self_options
|
82
|
+
definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def self_usage
|
86
|
+
IDENT + self_usage_arguments.join(SEP)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self_usage_arguments
|
90
|
+
[::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
|
91
|
+
definition.options_argument.if_present([]) { |_v| ['[options]'] } +
|
92
|
+
self_usage_arguments_options +
|
93
|
+
self_usage_arguments_positional
|
94
|
+
end
|
95
|
+
|
96
|
+
def self_usage_arguments_options
|
97
|
+
definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def self_usage_arguments_positional
|
101
|
+
definition.positional.map { |p| positional_argument(p) }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Parser
|
7
|
+
class ParseResult
|
8
|
+
common_constructor :definition, :argv
|
9
|
+
|
10
|
+
def result
|
11
|
+
::EacCli::Parser::Collector.to_data(definition) do |collector|
|
12
|
+
::EacCli::Parser::PositionalCollection.new(
|
13
|
+
definition,
|
14
|
+
::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
|
15
|
+
collector
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_cli/parser/error'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
class Parser
|
8
|
+
class PositionalCollection
|
9
|
+
common_constructor(:definition, :argv, :collector) { collect }
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def collected
|
14
|
+
@collected ||= ::Set.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def collect
|
18
|
+
argv.each { |argv_value| colect_argv_value(argv_value) }
|
19
|
+
return unless pending_required_positional?
|
20
|
+
|
21
|
+
raise ::EacCli::Parser::Error.new(
|
22
|
+
definition, argv, 'No value for required positional ' \
|
23
|
+
"\"#{current_positional.identifier}\""
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def colect_argv_value(argv_value)
|
28
|
+
collector.collect(current_positional, argv_value)
|
29
|
+
collected << current_positional
|
30
|
+
positional_enumerator.next unless current_positional.repeat?
|
31
|
+
end
|
32
|
+
|
33
|
+
def pending_required_positional?
|
34
|
+
!(current_positional.blank? || current_positional.optional? ||
|
35
|
+
collected.include?(current_positional))
|
36
|
+
end
|
37
|
+
|
38
|
+
def positional_enumerator
|
39
|
+
@positional_enumerator ||= definition.positional.each
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_positional
|
43
|
+
positional_enumerator.peek
|
44
|
+
rescue ::StopIteration
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,29 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'eac_cli/
|
4
|
-
require 'eac_cli/
|
3
|
+
require 'eac_cli/definition'
|
4
|
+
require 'eac_cli/docopt/runner_extension'
|
5
|
+
require 'eac_cli/parser'
|
5
6
|
require 'eac_ruby_utils/core_ext'
|
6
7
|
|
7
8
|
module EacCli
|
8
9
|
module Runner
|
10
|
+
require_sub __FILE__
|
9
11
|
extend ::ActiveSupport::Concern
|
10
12
|
|
11
13
|
included do
|
12
14
|
extend ClassMethods
|
13
15
|
include InstanceMethods
|
16
|
+
::EacCli::Docopt::RunnerExtension.check(self)
|
14
17
|
end
|
15
18
|
|
16
19
|
module ClassMethods
|
20
|
+
def create(*context_args)
|
21
|
+
r = new
|
22
|
+
r.context = ::EacCli::Runner::Context.new(*context_args)
|
23
|
+
r
|
24
|
+
end
|
25
|
+
|
17
26
|
def runner_definition(&block)
|
18
|
-
@runner_definition ||= ::EacCli::
|
27
|
+
@runner_definition ||= ::EacCli::Definition.new
|
19
28
|
@runner_definition.instance_eval(&block) if block
|
20
29
|
@runner_definition
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
33
|
module InstanceMethods
|
25
|
-
def
|
26
|
-
|
34
|
+
def context
|
35
|
+
return @context if @context
|
36
|
+
|
37
|
+
raise 'Context was required, but was not set yet'
|
38
|
+
end
|
39
|
+
|
40
|
+
def context=(new_context)
|
41
|
+
@context = new_context
|
42
|
+
@parsed = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def parsed
|
46
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(context.argv)
|
27
47
|
end
|
28
48
|
end
|
29
49
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
module Runner
|
7
|
+
class Context
|
8
|
+
attr_reader :argv, :parent, :program_name
|
9
|
+
|
10
|
+
def initialize(*context_args)
|
11
|
+
options = context_args.extract_options!
|
12
|
+
@argv = (context_args[0] || options.delete(:argv)).freeze
|
13
|
+
@parent = context_args[1] || options.delete(:parent)
|
14
|
+
@program_name = options.delete(:program_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
require 'eac_cli/runner'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::Runner do
|
7
|
+
let(:stub_runner) do
|
8
|
+
r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
|
9
|
+
def run; end
|
10
|
+
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
|
+
end
|
19
|
+
|
20
|
+
let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
|
21
|
+
|
22
|
+
before { instance.run }
|
23
|
+
|
24
|
+
it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
|
25
|
+
it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
|
26
|
+
|
27
|
+
context 'without docopt runner' do
|
28
|
+
let(:runner_class) do
|
29
|
+
the_module = described_class
|
30
|
+
::Class.new do
|
31
|
+
include the_module
|
32
|
+
|
33
|
+
runner_definition do
|
34
|
+
arg_opt '-o', '--opt1', 'A arg option.'
|
35
|
+
bool_opt '-o', '--opt2', 'A boolean option'
|
36
|
+
pos_arg :pos1
|
37
|
+
pos_arg :pos2, repeat: true, optional: true
|
38
|
+
end
|
39
|
+
|
40
|
+
def run; end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
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
|
52
|
+
|
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
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
require 'eac_docker/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'eac_docker'
|
9
|
+
s.version = EacDocker::VERSION
|
10
|
+
s.authors = ['Put here the authors']
|
11
|
+
s.summary = 'Put here de description.'
|
12
|
+
|
13
|
+
s.files = Dir['{lib}/**/*']
|
14
|
+
|
15
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.36'
|
16
|
+
|
17
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacDocker
|
6
|
+
class Container
|
7
|
+
enable_immutable
|
8
|
+
immutable_accessor :interactive, :temporary, :tty, type: :boolean
|
9
|
+
immutable_accessor :env, type: :hash
|
10
|
+
immutable_accessor :command_arg, :volume, type: :array
|
11
|
+
common_constructor :image
|
12
|
+
|
13
|
+
def immutable_constructor_args
|
14
|
+
[image]
|
15
|
+
end
|
16
|
+
|
17
|
+
alias immutable_volume volume
|
18
|
+
|
19
|
+
def volume(left_part, right_part = null)
|
20
|
+
immutable_volume(right_part.if_present(left_part) { |v| "#{left_part}:#{v}" })
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_command
|
24
|
+
::EacDocker::Executables.docker.command('run', *run_command_args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_command_args
|
28
|
+
run_command_boolean_args + run_command_envs_args + run_command_volumes_args + [image.id] +
|
29
|
+
command_args
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def run_command_boolean_args
|
35
|
+
r = []
|
36
|
+
r << '--interactive' if interactive?
|
37
|
+
r << '--tty' if tty?
|
38
|
+
r << '--rm' if temporary?
|
39
|
+
r
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_command_volumes_args
|
43
|
+
volumes.flat_map { |volume| ['--volume', volume] }
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_command_envs_args
|
47
|
+
envs.flat_map { |name, value| ['--env', "#{name}=#{value}"] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|