ehbrs-tools 0.13.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +1 -1
  3. data/lib/ehbrs/runner.rb +10 -17
  4. data/lib/ehbrs/runner/finances.rb +4 -7
  5. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  6. data/lib/ehbrs/runner/fs.rb +4 -7
  7. data/lib/ehbrs/runner/fs/used_space.rb +8 -9
  8. data/lib/ehbrs/runner/google.rb +4 -7
  9. data/lib/ehbrs/runner/google/translate.rb +7 -12
  10. data/lib/ehbrs/runner/self.rb +4 -7
  11. data/lib/ehbrs/runner/self/test.rb +5 -10
  12. data/lib/ehbrs/runner/vg.rb +4 -7
  13. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  14. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  15. data/lib/ehbrs/runner/videos.rb +7 -14
  16. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  17. data/lib/ehbrs/runner/videos/probe.rb +32 -0
  18. data/lib/ehbrs/runner/videos/series.rb +5 -8
  19. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  20. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  21. data/lib/ehbrs/runner/web_utils.rb +24 -0
  22. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  23. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  24. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  25. data/lib/ehbrs/tools/version.rb +1 -1
  26. data/lib/ehbrs/videos/file.rb +2 -1
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
  29. data/vendor/eac_cli/eac_cli.gemspec +3 -3
  30. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
  31. data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
  32. data/vendor/eac_cli/lib/eac_cli/definition.rb +94 -0
  33. data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
  34. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
  35. data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
  36. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
  37. data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
  38. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +46 -0
  39. data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
  40. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
  41. data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
  42. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
  43. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
  44. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
  45. data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
  46. data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
  47. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
  48. data/vendor/eac_cli/lib/eac_cli/runner.rb +68 -7
  49. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
  50. data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
  51. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
  52. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
  53. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  54. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  55. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
  56. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +78 -0
  57. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +8 -40
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +2 -2
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  81. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +8 -8
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +57 -0
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
  101. data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
  102. data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
  103. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
  104. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
  105. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
  106. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
  107. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
  108. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
  109. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
  110. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
  111. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
  112. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  113. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  114. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  115. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  116. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  117. data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
  118. data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
  119. data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
  120. metadata +77 -10
  121. data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
  122. data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
  123. data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
  124. data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
  125. data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/parser/error'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacCli
7
+ class Parser
8
+ class ParseResult
9
+ common_constructor :definition, :argv
10
+
11
+ def result
12
+ result_or_error = parse(definition)
13
+ return result_or_error unless result_or_error.is_a?(::Exception)
14
+
15
+ definition.alternatives.each do |alternative|
16
+ alt_result_or_error = parse(alternative)
17
+ return alt_result_or_error unless alt_result_or_error.is_a?(::Exception)
18
+ end
19
+
20
+ raise result_or_error
21
+ end
22
+
23
+ private
24
+
25
+ def parse(definition)
26
+ ::EacCli::Parser::Collector.to_data(definition) do |collector|
27
+ ::EacCli::Parser::PositionalCollection.new(
28
+ definition,
29
+ ::EacCli::Parser::OptionsCollection.new(definition, argv, collector).arguments,
30
+ collector
31
+ )
32
+ end
33
+ rescue ::EacCli::Parser::Error => e
34
+ e
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,77 @@
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 argv_enum
14
+ @argv_enum ||= argv.each
15
+ end
16
+
17
+ def argv_pending?
18
+ argv_enum.ongoing?
19
+ end
20
+
21
+ def argv_pending_check
22
+ return unless argv_pending?
23
+ return unless positional_enum.stopped?
24
+
25
+ raise ::EacCli::Parser::Error.new(
26
+ definition, argv, "No positional left for argv \"#{argv_enum.current}\""
27
+ )
28
+ end
29
+
30
+ def collected
31
+ @collected ||= ::Set.new
32
+ end
33
+
34
+ def collect
35
+ loop do
36
+ break unless enums('pending?').any?
37
+
38
+ enums('pending_check')
39
+ collect_argv_value
40
+ end
41
+ end
42
+
43
+ def collect_argv_value
44
+ collector.collect(*enums('enum', &:peek))
45
+ collected << positional_enum.peek
46
+ positional_enum.next unless positional_enum.peek.repeat?
47
+ argv_enum.next
48
+ end
49
+
50
+ def enums(method_suffix, &block)
51
+ %w[positional argv].map do |method_prefix|
52
+ v = send("#{method_prefix}_#{method_suffix}")
53
+ block ? block.call(v) : v
54
+ end
55
+ end
56
+
57
+ def positional_enum
58
+ @positional_enum ||= definition.positional.each
59
+ end
60
+
61
+ def positional_pending?
62
+ !(positional_enum.stopped? || positional_enum.current.optional? ||
63
+ collected.include?(positional_enum.current))
64
+ end
65
+
66
+ def positional_pending_check
67
+ return unless positional_pending?
68
+ return unless argv_enum.stopped?
69
+
70
+ raise ::EacCli::Parser::Error.new(
71
+ definition, argv, 'No value for required positional ' \
72
+ "\"#{positional_enum.current.identifier}\""
73
+ )
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].sort.each do |path|
4
+ require path
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_cli/runner'
5
+ require 'eac_cli/runner_with'
6
+
7
+ class Object
8
+ def runner_with(*runners, &block)
9
+ include ::EacCli::Runner
10
+ enable_simple_cache
11
+ enable_console_speaker
12
+ runners.each do |runner|
13
+ include runner_with_to_module(runner)
14
+ end
15
+ runner_definition(&block) if block
16
+ end
17
+
18
+ private
19
+
20
+ def runner_with_to_module(runner)
21
+ return runner if runner.is_a?(::Module)
22
+
23
+ "EacCli::RunnerWith::#{runner.to_s.camelize}".constantize
24
+ end
25
+ end
@@ -1,29 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/runner/definition'
4
- require 'eac_cli/runner/docopt_doc'
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
 
13
+ class << self
14
+ def alias_runner_class_methods(klass, from_suffix, to_suffix)
15
+ %i[create run].each do |method|
16
+ alias_class_method(klass, build_method_name(method, from_suffix),
17
+ build_method_name(method, to_suffix))
18
+ end
19
+ end
20
+
21
+ def runner?(object)
22
+ object.is_a?(::Class) && object.included_modules.include?(::EacCli::Runner)
23
+ end
24
+
25
+ private
26
+
27
+ def alias_class_method(klass, from, to)
28
+ sklass = klass.singleton_class
29
+ return unless sklass.method_defined?(from)
30
+
31
+ sklass.alias_method to, from
32
+ end
33
+
34
+ def build_method_name(name, suffix)
35
+ ss = suffix.if_present('') { |s| "#{s}_" }
36
+ "#{ss}#{name}"
37
+ end
38
+ end
39
+
40
+ the_module = self
11
41
  included do
12
- extend ClassMethods
42
+ the_module.alias_runner_class_methods(self, '', 'original')
43
+
44
+ extend AfterClassMethods
13
45
  include InstanceMethods
46
+ ::EacCli::Docopt::RunnerExtension.check(self)
14
47
  end
15
48
 
16
- module ClassMethods
49
+ module AfterClassMethods
50
+ def create(*runner_context_args)
51
+ r = new
52
+ r.runner_context = ::EacCli::Runner::Context.new(r, *runner_context_args)
53
+ r
54
+ end
55
+
56
+ def run(*runner_context_args)
57
+ r = create(*runner_context_args)
58
+ r.parsed
59
+ r.run
60
+ r
61
+ end
62
+
17
63
  def runner_definition(&block)
18
- @runner_definition ||= ::EacCli::Runner::Definition.new
64
+ @runner_definition ||= super_runner_definition
19
65
  @runner_definition.instance_eval(&block) if block
20
66
  @runner_definition
21
67
  end
68
+
69
+ def super_runner_definition
70
+ superclass.try(:runner_definition).if_present(&:dup) || ::EacCli::Definition.new
71
+ end
22
72
  end
23
73
 
24
74
  module InstanceMethods
25
- def doc
26
- ::EacCli::Runner::DocoptDoc.new(self.class.runner_definition).to_s
75
+ def runner_context
76
+ return @runner_context if @runner_context
77
+
78
+ raise 'Context was required, but was not set yet'
79
+ end
80
+
81
+ def runner_context=(new_runner_context)
82
+ @runner_context = new_runner_context
83
+ @parsed = nil
84
+ end
85
+
86
+ def parsed
87
+ @parsed ||= ::EacCli::Parser.new(self.class.runner_definition).parse(runner_context.argv)
27
88
  end
28
89
  end
29
90
  end
@@ -0,0 +1,35 @@
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, :runner
9
+
10
+ def initialize(runner, *context_args)
11
+ options = context_args.extract_options!
12
+ @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
13
+ @parent = context_args[1] || options.delete(:parent)
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)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacCli
6
+ module RunnerWith
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,19 @@
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 Help
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition.alt do
13
+ options_arg false
14
+ bool_opt '-h', '--help', 'Show help.', usage: true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
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 OutputFile
9
+ common_concern do
10
+ include ::EacCli::Runner
11
+
12
+ runner_definition do
13
+ arg_opt '-o', '--output-file', 'Output to file.'
14
+ end
15
+ end
16
+
17
+ def run_output
18
+ if parsed.output_file.present?
19
+ ::File.write(parsed.output_file, output_content)
20
+ else
21
+ out output_content
22
+ end
23
+ end
24
+ end
25
+ end
26
+ 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.3.0'
4
+ VERSION = '0.10.0'
5
5
  end