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.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +1 -1
- data/lib/ehbrs/runner.rb +10 -17
- 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 +8 -9
- 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/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/eac_cli/eac_cli.gemspec +3 -3
- 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 +94 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
- 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 +46 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
- 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 +68 -7
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
- 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 +78 -0
- 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/boolean.rb +31 -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 +8 -40
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
- 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 +2 -2
- 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/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/clearable_directory.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -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 +5 -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/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 +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/require_sub.rb +8 -8
- 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 +57 -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/inflector_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/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- 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 +77 -10
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
- 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
- data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -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.
|
16
|
-
|
17
|
-
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1'
|
15
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.50'
|
16
|
+
|
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
|
@@ -0,0 +1,94 @@
|
|
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
|
+
require 'eac_ruby_utils/core_ext'
|
7
|
+
|
8
|
+
module EacCli
|
9
|
+
class Definition
|
10
|
+
require_sub __FILE__
|
11
|
+
|
12
|
+
SUBCOMMAND_NAME_ARG = 'subcommand'
|
13
|
+
SUBCOMMAND_ARGS_ARG = 'subcommand_args'
|
14
|
+
|
15
|
+
attr_accessor :description
|
16
|
+
attr_accessor :options_argument
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
self.description = '-- NO DESCRIPTION SET --'
|
20
|
+
self.options_argument = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def alt(&block)
|
24
|
+
r = ::EacCli::Definition.new
|
25
|
+
r.instance_eval(&block)
|
26
|
+
alternatives << r
|
27
|
+
r
|
28
|
+
end
|
29
|
+
|
30
|
+
def alternatives
|
31
|
+
@alternatives ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
def arg_opt(short, long, description, option_options = {})
|
35
|
+
options << ::EacCli::Definition::ArgumentOption.new(
|
36
|
+
short, long, description, option_options
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def bool_opt(short, long, description, option_options = {})
|
41
|
+
options << ::EacCli::Definition::BooleanOption.new(short, long, description, option_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def desc(description)
|
45
|
+
self.description = description
|
46
|
+
end
|
47
|
+
|
48
|
+
def options_arg(options_argument)
|
49
|
+
self.options_argument = options_argument
|
50
|
+
end
|
51
|
+
|
52
|
+
def options
|
53
|
+
@options ||= []
|
54
|
+
end
|
55
|
+
|
56
|
+
def pos_arg(name, arg_options = {})
|
57
|
+
raise 'Positional arguments are blocked' if positional_arguments_blocked?
|
58
|
+
|
59
|
+
pos_set << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def positional
|
63
|
+
pos_set.to_a
|
64
|
+
end
|
65
|
+
|
66
|
+
def positional_arguments_blocked?
|
67
|
+
pos_set.any? { |e| e.optional? || e.repeat? }
|
68
|
+
end
|
69
|
+
|
70
|
+
def subcommands
|
71
|
+
pos_arg(SUBCOMMAND_NAME_ARG, subcommand: true)
|
72
|
+
pos_set << ::EacCli::Definition::PositionalArgument.new(SUBCOMMAND_ARGS_ARG,
|
73
|
+
optional: true, repeat: true)
|
74
|
+
end
|
75
|
+
|
76
|
+
def subcommands?
|
77
|
+
pos_set.any?(&:subcommand?)
|
78
|
+
end
|
79
|
+
|
80
|
+
def options_first(enable = true)
|
81
|
+
@options_first = enable
|
82
|
+
end
|
83
|
+
|
84
|
+
def options_first?
|
85
|
+
@options_first ? true : false
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def pos_set
|
91
|
+
@pos_set ||= []
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Definition
|
7
|
+
class BaseOption
|
8
|
+
DEFAULT_REQUIRED = false
|
9
|
+
|
10
|
+
enable_listable
|
11
|
+
lists.add_symbol :option, :optional, :usage, :required
|
12
|
+
attr_reader :short, :long, :description, :options
|
13
|
+
|
14
|
+
def initialize(short, long, description, options = {})
|
15
|
+
@short = short
|
16
|
+
@long = long
|
17
|
+
@description = description
|
18
|
+
@options = options.symbolize_keys
|
19
|
+
@options.assert_valid_keys(::EacCli::Definition::BaseOption.lists.option.values)
|
20
|
+
end
|
21
|
+
|
22
|
+
def identifier
|
23
|
+
long.to_s.variableize.to_sym
|
24
|
+
end
|
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
|
+
|
37
|
+
def show_on_usage?
|
38
|
+
options[:usage]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Definition
|
7
|
+
class PositionalArgument
|
8
|
+
enable_listable
|
9
|
+
lists.add_symbol :option, :optional, :repeat, :subcommand
|
10
|
+
common_constructor :name, :options, default: [{}] do
|
11
|
+
options.assert_valid_keys(self.class.lists.option.values)
|
12
|
+
end
|
13
|
+
|
14
|
+
def identifier
|
15
|
+
name.to_s.variableize.to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
def optional?
|
19
|
+
options[OPTION_OPTIONAL]
|
20
|
+
end
|
21
|
+
|
22
|
+
def repeat?
|
23
|
+
options[OPTION_REPEAT]
|
24
|
+
end
|
25
|
+
|
26
|
+
def subcommand?
|
27
|
+
options[OPTION_SUBCOMMAND]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -4,8 +4,8 @@ require 'eac_ruby_utils/core_ext'
|
|
4
4
|
require 'eac_ruby_utils/console/docopt_runner'
|
5
5
|
|
6
6
|
module EacCli
|
7
|
-
module
|
8
|
-
class
|
7
|
+
module Docopt
|
8
|
+
class DocBuilder
|
9
9
|
common_constructor :definition
|
10
10
|
|
11
11
|
SEP = ' '
|
@@ -51,15 +51,22 @@ module EacCli
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def self_usage
|
54
|
-
|
55
|
-
b += "#{SEP}[options]" if definition.options_argument
|
56
|
-
b + self_usage_arguments
|
54
|
+
IDENT + self_usage_arguments.join(SEP)
|
57
55
|
end
|
58
56
|
|
59
57
|
def self_usage_arguments
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
[::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
|
59
|
+
definition.options_argument.if_present([]) { |_v| ['[options]'] } +
|
60
|
+
self_usage_arguments_options +
|
61
|
+
self_usage_arguments_positional
|
62
|
+
end
|
63
|
+
|
64
|
+
def self_usage_arguments_options
|
65
|
+
definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self_usage_arguments_positional
|
69
|
+
definition.positional.map { |p| positional_argument(p) }
|
63
70
|
end
|
64
71
|
|
65
72
|
def to_s
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/doc_builder'
|
4
|
+
require 'eac_cli/runner'
|
5
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
6
|
+
|
7
|
+
module EacCli
|
8
|
+
module Docopt
|
9
|
+
module RunnerExtension
|
10
|
+
extend ::ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do
|
13
|
+
prepend InstanceMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def check(klass)
|
18
|
+
return unless klass < ::EacRubyUtils::Console::DocoptRunner
|
19
|
+
|
20
|
+
::EacCli::Runner.alias_runner_class_methods(klass, '', 'eac_cli')
|
21
|
+
::EacCli::Runner.alias_runner_class_methods(klass, 'original', '')
|
22
|
+
|
23
|
+
klass.include(self)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
def doc
|
29
|
+
::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def docopt_options
|
33
|
+
super.merge(options_first: self.class.runner_definition.options_first?)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def extra_available_subcommands
|
38
|
+
self.class.constants
|
39
|
+
.map { |name| self.class.const_get(name) }
|
40
|
+
.select { |c| c.instance_of? Class }
|
41
|
+
.select { |c| c.included_modules.include?(::EacCli::Runner) }
|
42
|
+
.map { |c| c.name.demodulize.underscore.dasherize }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacCli
|
6
|
+
class Parser
|
7
|
+
require_sub __FILE__
|
8
|
+
common_constructor :definition
|
9
|
+
|
10
|
+
def parse(argv)
|
11
|
+
::EacCli::Parser::ParseResult.new(definition, argv).result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
def supplied?(option)
|
35
|
+
data[option].present?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def data
|
41
|
+
@data ||= {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_values
|
45
|
+
definition.options.each { |option| data[option] = option_default_value(option) }
|
46
|
+
definition.positional.each do |positional|
|
47
|
+
data[positional] = positional_default_value(positional)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def option_default_value(option)
|
52
|
+
option.argument? ? nil : false
|
53
|
+
end
|
54
|
+
|
55
|
+
def positional_default_value(positional)
|
56
|
+
positional.repeat? ? [] : nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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,127 @@
|
|
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
|
+
def options_first?
|
18
|
+
definition.options_first? || definition.subcommands?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def check_required_options
|
24
|
+
definition.options.each do |option|
|
25
|
+
next unless option.required?
|
26
|
+
next if collector.supplied?(option)
|
27
|
+
|
28
|
+
raise ::EacCli::Parser::Error.new(
|
29
|
+
definition, argv, "Option \"#{option}\" is required and a value was not supplied"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def collect
|
35
|
+
build_banner
|
36
|
+
build_options
|
37
|
+
parse_argv
|
38
|
+
check_required_options
|
39
|
+
end
|
40
|
+
|
41
|
+
def option_parser_uncached
|
42
|
+
::OptionParser.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_argv
|
46
|
+
@arguments = options_first? ? option_parser.order(argv) : option_parser.parse(argv)
|
47
|
+
rescue ::OptionParser::InvalidOption => e
|
48
|
+
raise ::EacCli::Parser::Error.new(definition, argv, e.message)
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_banner
|
52
|
+
option_parser.banner = "#{definition.description}\n\n#{section('usage')}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_options
|
56
|
+
definition.options.each do |option|
|
57
|
+
build_option(option)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_option(option)
|
62
|
+
option_parser.on(
|
63
|
+
*[option_short(option), option_long(option), option.description].reject(&:blank?)
|
64
|
+
) do |value|
|
65
|
+
collector.collect(option, value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def positional_argument(positional)
|
70
|
+
if positional.subcommand?
|
71
|
+
::EacRubyUtils::Console::DocoptRunner::SUBCOMMANDS_MACRO
|
72
|
+
else
|
73
|
+
r = "<#{positional.name}>"
|
74
|
+
r += '...' if positional.repeat?
|
75
|
+
r = "[#{r}]" if positional.optional?
|
76
|
+
r
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def option_argument(option)
|
81
|
+
option_long(option)
|
82
|
+
end
|
83
|
+
|
84
|
+
def option_long(option)
|
85
|
+
b = option.long
|
86
|
+
b += '=VALUE' if option.argument?
|
87
|
+
b
|
88
|
+
end
|
89
|
+
|
90
|
+
def option_short(option)
|
91
|
+
b = option.short
|
92
|
+
b += 'VALUE' if option.argument?
|
93
|
+
b
|
94
|
+
end
|
95
|
+
|
96
|
+
def section(header, include_header = true)
|
97
|
+
b = include_header ? "#{header.humanize}:\n" : ''
|
98
|
+
b += send("self_#{header}") + "\n"
|
99
|
+
# TO-DO: implement alternatives
|
100
|
+
b
|
101
|
+
end
|
102
|
+
|
103
|
+
def self_options
|
104
|
+
definition.options.map { |option| IDENT + option_definition(option) }.join("\n")
|
105
|
+
end
|
106
|
+
|
107
|
+
def self_usage
|
108
|
+
IDENT + self_usage_arguments.join(SEP)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self_usage_arguments
|
112
|
+
[::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO] +
|
113
|
+
definition.options_argument.if_present([]) { |_v| ['[options]'] } +
|
114
|
+
self_usage_arguments_options +
|
115
|
+
self_usage_arguments_positional
|
116
|
+
end
|
117
|
+
|
118
|
+
def self_usage_arguments_options
|
119
|
+
definition.options.select(&:show_on_usage?).map { |option| option_argument(option) }
|
120
|
+
end
|
121
|
+
|
122
|
+
def self_usage_arguments_positional
|
123
|
+
definition.positional.map { |p| positional_argument(p) }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|