ehbrs-tools 0.13.1 → 0.16.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/executables.rb +1 -1
- data/lib/ehbrs/runner.rb +4 -7
- data/lib/ehbrs/runner/finances.rb +4 -7
- data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
- data/lib/ehbrs/runner/fs.rb +4 -7
- data/lib/ehbrs/runner/fs/used_space.rb +4 -5
- data/lib/ehbrs/runner/google.rb +4 -7
- data/lib/ehbrs/runner/google/translate.rb +7 -12
- data/lib/ehbrs/runner/self.rb +4 -7
- data/lib/ehbrs/runner/self/test.rb +5 -10
- data/lib/ehbrs/runner/vg.rb +4 -7
- data/lib/ehbrs/runner/vg/ips.rb +9 -14
- data/lib/ehbrs/runner/vg/wii.rb +10 -13
- data/lib/ehbrs/runner/videos.rb +7 -14
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +32 -0
- data/lib/ehbrs/runner/videos/series.rb +5 -8
- data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
- data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
- data/lib/ehbrs/runner/web_utils.rb +24 -0
- data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
- data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
- data/lib/ehbrs/videos/file.rb +2 -1
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/vendor/aranha-parsers/Gemfile +5 -0
- data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
- data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +70 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
- data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
- data/vendor/eac_cli/lib/eac_cli/definition.rb +35 -3
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
- data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +4 -9
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +27 -64
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +47 -19
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +51 -10
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +20 -3
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +48 -40
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
- data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
- data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
- data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
- data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
- metadata +85 -2
@@ -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 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -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.
|
15
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.50'
|
16
16
|
|
17
17
|
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
|
18
18
|
end
|
@@ -1,22 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'eac_ruby_utils/console/speaker'
|
6
|
-
require 'eac_ruby_utils/simple_cache'
|
3
|
+
require 'eac_cli/runner_with/help'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
7
5
|
|
8
6
|
module EacCli
|
9
7
|
module DefaultRunner
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
include ::EacRubyUtils::Console::Speaker
|
15
|
-
include ::EacRubyUtils::SimpleCache
|
16
|
-
runner_definition.alt do
|
17
|
-
options_arg false
|
18
|
-
bool_opt '-h', '--help', 'Show help.', usage: true
|
19
|
-
end
|
8
|
+
common_concern do
|
9
|
+
include ::EacCli::RunnerWith::Help
|
10
|
+
enable_console_speaker
|
11
|
+
enable_simple_cache
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
@@ -8,6 +8,10 @@ require 'eac_ruby_utils/core_ext'
|
|
8
8
|
module EacCli
|
9
9
|
class Definition
|
10
10
|
require_sub __FILE__
|
11
|
+
|
12
|
+
SUBCOMMAND_NAME_ARG = 'subcommand'
|
13
|
+
SUBCOMMAND_ARGS_ARG = 'subcommand_args'
|
14
|
+
|
11
15
|
attr_accessor :description
|
12
16
|
attr_accessor :options_argument
|
13
17
|
|
@@ -41,6 +45,10 @@ module EacCli
|
|
41
45
|
self.description = description
|
42
46
|
end
|
43
47
|
|
48
|
+
def help_formatter
|
49
|
+
@help_formatter ||= ::EacCli::Definition::HelpFormatter.new(self)
|
50
|
+
end
|
51
|
+
|
44
52
|
def options_arg(options_argument)
|
45
53
|
self.options_argument = options_argument
|
46
54
|
end
|
@@ -50,15 +58,33 @@ module EacCli
|
|
50
58
|
end
|
51
59
|
|
52
60
|
def pos_arg(name, arg_options = {})
|
53
|
-
|
61
|
+
new_pos_arg = ::EacCli::Definition::PositionalArgument.new(name, arg_options)
|
62
|
+
raise 'Positional arguments are blocked' if positional_arguments_blocked?(new_pos_arg)
|
63
|
+
|
64
|
+
pos_set << new_pos_arg
|
54
65
|
end
|
55
66
|
|
56
67
|
def positional
|
57
|
-
|
68
|
+
pos_set.to_a
|
69
|
+
end
|
70
|
+
|
71
|
+
def positional_arguments_blocked?(new_pos_arg)
|
72
|
+
last = pos_set.last
|
73
|
+
return false unless last
|
74
|
+
return true if last.repeat?
|
75
|
+
return true if last.optional? && new_pos_arg.required?
|
76
|
+
|
77
|
+
false
|
58
78
|
end
|
59
79
|
|
60
80
|
def subcommands
|
61
|
-
|
81
|
+
pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
|
82
|
+
pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
|
83
|
+
optional: true, repeat: true)
|
84
|
+
end
|
85
|
+
|
86
|
+
def subcommands?
|
87
|
+
pos_set.any?(&:subcommand?)
|
62
88
|
end
|
63
89
|
|
64
90
|
def options_first(enable = true)
|
@@ -68,5 +94,11 @@ module EacCli
|
|
68
94
|
def options_first?
|
69
95
|
@options_first ? true : false
|
70
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def pos_set
|
101
|
+
@pos_set ||= []
|
102
|
+
end
|
71
103
|
end
|
72
104
|
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.
|
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
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Definition
|
7
|
+
class HelpFormatter
|
8
|
+
SEP = ' '
|
9
|
+
IDENT = SEP * 2
|
10
|
+
OPTION_DESC_SEP = IDENT * 2
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def option_long(option)
|
14
|
+
b = option.long
|
15
|
+
b += '=VALUE' if option.argument?
|
16
|
+
b
|
17
|
+
end
|
18
|
+
|
19
|
+
def option_short(option)
|
20
|
+
b = option.short
|
21
|
+
b += 'VALUE' if option.argument?
|
22
|
+
b
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
common_constructor :definition
|
27
|
+
|
28
|
+
def positional_argument(positional)
|
29
|
+
if positional.subcommand?
|
30
|
+
::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
|
31
|
+
else
|
32
|
+
r = "<#{positional.name}>"
|
33
|
+
r += '...' if positional.repeat?
|
34
|
+
r = "[#{r}]" if positional.optional?
|
35
|
+
r
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def section(header, include_header = true)
|
40
|
+
b = include_header ? "#{header.humanize}:\n" : ''
|
41
|
+
b += send("self_#{header}") + "\n"
|
42
|
+
# TO-DO: implement alternatives
|
43
|
+
b
|
44
|
+
end
|
45
|
+
|
46
|
+
def self_options
|
47
|
+
definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def self_usage
|
51
|
+
IDENT + self_usage_arguments.join(SEP)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self_usage_arguments
|
55
|
+
[::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
|
56
|
+
definition.options_argument.if_present([]) { |_v| ['[options]'] } +
|
57
|
+
self_usage_arguments_options +
|
58
|
+
self_usage_arguments_positional
|
59
|
+
end
|
60
|
+
|
61
|
+
def self_usage_arguments_options
|
62
|
+
definition.options.select(&:show_on_usage?).map do |option|
|
63
|
+
self.class.option_long(option)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self_usage_arguments_positional
|
68
|
+
definition.positional.map { |p| positional_argument(p) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_banner
|
72
|
+
"#{definition.description}\n\n#{section('usage')}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -5,22 +5,39 @@ require 'eac_ruby_utils/core_ext'
|
|
5
5
|
module EacCli
|
6
6
|
class Definition
|
7
7
|
class PositionalArgument
|
8
|
-
|
8
|
+
DEFAULT_REQUIRED = true
|
9
|
+
|
10
|
+
enable_listable
|
11
|
+
lists.add_symbol :option, :optional, :repeat, :required, :subcommand
|
12
|
+
common_constructor :name, :options, default: [{}] do
|
13
|
+
options.assert_valid_keys(self.class.lists.option.values)
|
14
|
+
end
|
9
15
|
|
10
16
|
def identifier
|
11
17
|
name.to_s.variableize.to_sym
|
12
18
|
end
|
13
19
|
|
14
20
|
def optional?
|
15
|
-
|
21
|
+
!required?
|
16
22
|
end
|
17
23
|
|
18
24
|
def repeat?
|
19
|
-
options[
|
25
|
+
options[OPTION_REPEAT]
|
26
|
+
end
|
27
|
+
|
28
|
+
def required?
|
29
|
+
return true if options.key?(OPTION_REQUIRED) && options.fetch(OPTION_REQUIRED)
|
30
|
+
return false if options.key?(OPTION_OPTIONAL) && options.fetch(OPTION_OPTIONAL)
|
31
|
+
|
32
|
+
DEFAULT_REQUIRED
|
20
33
|
end
|
21
34
|
|
22
35
|
def subcommand?
|
23
|
-
options[
|
36
|
+
options[OPTION_SUBCOMMAND]
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"#{self.class.name.demodulize}[#{identifier}]"
|
24
41
|
end
|
25
42
|
end
|
26
43
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_cli/docopt/doc_builder'
|
4
|
+
require 'eac_cli/runner'
|
4
5
|
require 'eac_ruby_utils/console/docopt_runner'
|
5
6
|
|
6
7
|
module EacCli
|
@@ -9,7 +10,6 @@ module EacCli
|
|
9
10
|
extend ::ActiveSupport::Concern
|
10
11
|
|
11
12
|
included do
|
12
|
-
singleton_class.prepend ClassMethods
|
13
13
|
prepend InstanceMethods
|
14
14
|
end
|
15
15
|
|
@@ -17,15 +17,10 @@ module EacCli
|
|
17
17
|
def check(klass)
|
18
18
|
return unless klass < ::EacRubyUtils::Console::DocoptRunner
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
20
|
+
::EacCli::Runner.alias_runner_class_methods(klass, '', 'eac_cli')
|
21
|
+
::EacCli::Runner.alias_runner_class_methods(klass, 'original', '')
|
23
22
|
|
24
|
-
|
25
|
-
def create(*context_args)
|
26
|
-
r = new(*context_args)
|
27
|
-
r.context = ::EacCli::Runner::Context.new(*context_args)
|
28
|
-
r
|
23
|
+
klass.include(self)
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
@@ -6,28 +6,46 @@ require 'optparse'
|
|
6
6
|
module EacCli
|
7
7
|
class Parser
|
8
8
|
class OptionsCollection
|
9
|
-
SEP = ' '
|
10
|
-
IDENT = SEP * 2
|
11
|
-
OPTION_DESC_SEP = IDENT * 2
|
12
|
-
|
13
9
|
enable_simple_cache
|
14
10
|
common_constructor(:definition, :argv, :collector) { collect }
|
15
11
|
attr_reader :arguments
|
16
12
|
|
13
|
+
def options_first?
|
14
|
+
definition.options_first? || definition.subcommands?
|
15
|
+
end
|
16
|
+
|
17
17
|
private
|
18
18
|
|
19
|
+
def check_required_options
|
20
|
+
definition.options.each do |option|
|
21
|
+
next unless option.required?
|
22
|
+
next if collector.supplied?(option)
|
23
|
+
|
24
|
+
raise ::EacCli::Parser::Error.new(
|
25
|
+
definition, argv, "Option \"#{option}\" is required and a value was not supplied"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def collect
|
20
31
|
build_banner
|
21
32
|
build_options
|
22
|
-
|
33
|
+
parse_argv
|
34
|
+
check_required_options
|
23
35
|
end
|
24
36
|
|
25
37
|
def option_parser_uncached
|
26
38
|
::OptionParser.new
|
27
39
|
end
|
28
40
|
|
41
|
+
def parse_argv
|
42
|
+
@arguments = options_first? ? option_parser.order(argv) : option_parser.parse(argv)
|
43
|
+
rescue ::OptionParser::InvalidOption => e
|
44
|
+
raise ::EacCli::Parser::Error.new(definition, argv, e.message)
|
45
|
+
end
|
46
|
+
|
29
47
|
def build_banner
|
30
|
-
option_parser.banner =
|
48
|
+
option_parser.banner = definition.help_formatter.to_banner
|
31
49
|
end
|
32
50
|
|
33
51
|
def build_options
|
@@ -38,68 +56,13 @@ module EacCli
|
|
38
56
|
|
39
57
|
def build_option(option)
|
40
58
|
option_parser.on(
|
41
|
-
*[option_short(option),
|
59
|
+
*[::EacCli::Definition::HelpFormatter.option_short(option),
|
60
|
+
::EacCli::Definition::HelpFormatter.option_long(option),
|
61
|
+
option.description].reject(&:blank?)
|
42
62
|
) do |value|
|
43
63
|
collector.collect(option, value)
|
44
64
|
end
|
45
65
|
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
66
|
end
|
104
67
|
end
|
105
68
|
end
|