ehbrs-tools 0.13.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/runner.rb +9 -13
- data/lib/ehbrs/runner/fs/used_space.rb +4 -4
- data/lib/ehbrs/tools/version.rb +1 -1
- 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_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -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/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/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/require_sub.rb +8 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +47 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.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/struct_spec.rb +46 -0
- metadata +30 -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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9692fcad0f7b1e05f59f98e17e1d1e5042efa22f1bd1e8ada8a2b5b2d4909e66
|
4
|
+
data.tar.gz: 606f3be03e5b0f54564aaa78b466e89ed498cf4a7d316e187cb6432b34cd46f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc3d4a8dc042274ca49de459c5a18d8179cd0b2f1846016c9fcff06d909b5583aa282e645205bc502698b447ae2a8aab3bf53bfc9646e71eea23a9949c5b272
|
7
|
+
data.tar.gz: 48d655fe4a28192181f2e40d3f2f9041d7c3f4a41a80168446ee15ec176d54c2f5c0c4428d41fc0a5c3248f5dc3471b408c8f8d58b7ffecd5131d9040e7ef0ce
|
data/lib/ehbrs/runner.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_cli/default_runner'
|
3
4
|
require 'eac_ruby_utils/core_ext'
|
4
5
|
require 'eac_ruby_utils/console/docopt_runner'
|
5
6
|
require 'ehbrs/tools/version'
|
@@ -7,20 +8,15 @@ require 'ehbrs/tools/version'
|
|
7
8
|
module Ehbrs
|
8
9
|
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
10
|
require_sub __FILE__
|
10
|
-
|
11
|
+
include ::EacCli::DefaultRunner
|
11
12
|
|
12
|
-
|
13
|
-
Tools for EHB/RS.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Options:
|
21
|
-
-h --help Show this screen.
|
22
|
-
-V --version Show version.
|
23
|
-
DOCOPT
|
13
|
+
runner_definition do
|
14
|
+
desc 'Tools for EHB/RS.'
|
15
|
+
subcommands
|
16
|
+
alt do
|
17
|
+
bool_opt '-V', '--version', 'Show version.'
|
18
|
+
end
|
19
|
+
end
|
24
20
|
|
25
21
|
def run
|
26
22
|
if options.fetch('--version')
|
@@ -6,7 +6,7 @@ require 'filesize'
|
|
6
6
|
module Ehbrs
|
7
7
|
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
8
8
|
class Fs < ::EacRubyUtils::Console::DocoptRunner
|
9
|
-
class UsedSpace
|
9
|
+
class UsedSpace
|
10
10
|
include ::EacCli::DefaultRunner
|
11
11
|
|
12
12
|
runner_definition do
|
@@ -22,7 +22,7 @@ module Ehbrs
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def check?
|
25
|
-
|
25
|
+
parsed.check
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -40,11 +40,11 @@ module Ehbrs
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def paths_uncached
|
43
|
-
|
43
|
+
parsed.paths.map { |path| path_class.new(self, path) }
|
44
44
|
end
|
45
45
|
|
46
46
|
def verbose?
|
47
|
-
|
47
|
+
parsed.verbose
|
48
48
|
end
|
49
49
|
|
50
50
|
class PathBase
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -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.45'
|
16
|
+
|
17
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.2'
|
18
18
|
end
|
@@ -0,0 +1,72 @@
|
|
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
|
+
attr_accessor :description
|
12
|
+
attr_accessor :options_argument
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.description = '-- NO DESCRIPTION SET --'
|
16
|
+
self.options_argument = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def alt(&block)
|
20
|
+
r = ::EacCli::Definition.new
|
21
|
+
r.instance_eval(&block)
|
22
|
+
alternatives << r
|
23
|
+
r
|
24
|
+
end
|
25
|
+
|
26
|
+
def alternatives
|
27
|
+
@alternatives ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def arg_opt(short, long, description, option_options = {})
|
31
|
+
options << ::EacCli::Definition::ArgumentOption.new(
|
32
|
+
short, long, description, option_options
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def bool_opt(short, long, description, option_options = {})
|
37
|
+
options << ::EacCli::Definition::BooleanOption.new(short, long, description, option_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def desc(description)
|
41
|
+
self.description = description
|
42
|
+
end
|
43
|
+
|
44
|
+
def options_arg(options_argument)
|
45
|
+
self.options_argument = options_argument
|
46
|
+
end
|
47
|
+
|
48
|
+
def options
|
49
|
+
@options ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def pos_arg(name, arg_options = {})
|
53
|
+
positional << ::EacCli::Definition::PositionalArgument.new(name, arg_options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def positional
|
57
|
+
@positional ||= []
|
58
|
+
end
|
59
|
+
|
60
|
+
def subcommands
|
61
|
+
positional << ::EacCli::Definition::PositionalArgument.new('subcommand', subcommand: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
def options_first(enable = true)
|
65
|
+
@options_first = enable
|
66
|
+
end
|
67
|
+
|
68
|
+
def options_first?
|
69
|
+
@options_first ? true : false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
4
|
|
5
5
|
module EacCli
|
6
|
-
|
6
|
+
class Definition
|
7
7
|
class BaseOption
|
8
8
|
attr_reader :short, :long, :description, :options
|
9
9
|
|
@@ -14,6 +14,10 @@ module EacCli
|
|
14
14
|
@options = options.with_indifferent_access
|
15
15
|
end
|
16
16
|
|
17
|
+
def identifier
|
18
|
+
long.to_s.variableize.to_sym
|
19
|
+
end
|
20
|
+
|
17
21
|
def show_on_usage?
|
18
22
|
options[:usage]
|
19
23
|
end
|
@@ -3,10 +3,14 @@
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
4
|
|
5
5
|
module EacCli
|
6
|
-
|
6
|
+
class Definition
|
7
7
|
class PositionalArgument
|
8
8
|
common_constructor :name, :options, default: [{}]
|
9
9
|
|
10
|
+
def identifier
|
11
|
+
name.to_s.variableize.to_sym
|
12
|
+
end
|
13
|
+
|
10
14
|
def optional?
|
11
15
|
options[:optional]
|
12
16
|
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,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/doc_builder'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
|
6
|
+
module EacCli
|
7
|
+
module Docopt
|
8
|
+
module RunnerExtension
|
9
|
+
extend ::ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
singleton_class.prepend ClassMethods
|
13
|
+
prepend InstanceMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def check(klass)
|
18
|
+
return unless klass < ::EacRubyUtils::Console::DocoptRunner
|
19
|
+
|
20
|
+
klass.include(self)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def create(*context_args)
|
26
|
+
r = new(*context_args)
|
27
|
+
r.context = ::EacCli::Runner::Context.new(*context_args)
|
28
|
+
r
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module InstanceMethods
|
33
|
+
def doc
|
34
|
+
::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def docopt_options
|
38
|
+
super.merge(options_first: self.class.runner_definition.options_first?)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def extra_available_subcommands
|
43
|
+
self.class.constants
|
44
|
+
.map { |name| self.class.const_get(name) }
|
45
|
+
.select { |c| c.instance_of? Class }
|
46
|
+
.select { |c| c.included_modules.include?(::EacCli::Runner) }
|
47
|
+
.map { |c| c.name.demodulize.underscore.dasherize }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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,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
|