ehbrs-tools 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -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,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRubyUtils
|
4
|
+
class Boolean
|
5
|
+
class << self
|
6
|
+
def parse(value)
|
7
|
+
return parse_string(value) if value.is_a?(::String)
|
8
|
+
return parse_string(value.to_s) if value.is_a?(::Symbol)
|
9
|
+
return parse_number(value) if value.is_a?(::Number)
|
10
|
+
|
11
|
+
value ? true : false
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parse_string(value)
|
17
|
+
['', 'n', 'no', 'f', 'false'].include?(value.strip.downcase) ? false : true
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse_number(value)
|
21
|
+
value.zero?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :value
|
26
|
+
|
27
|
+
def initialize(value)
|
28
|
+
@value = self.class.parse(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,11 +3,11 @@
|
|
3
3
|
module EacRubyUtils
|
4
4
|
module Console
|
5
5
|
class DocoptRunner
|
6
|
-
DOCOPT_ERROR_EXIT_CODE =
|
6
|
+
DOCOPT_ERROR_EXIT_CODE = 0xC0
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def run(options = {})
|
10
|
-
|
10
|
+
create(options).send(:run)
|
11
11
|
rescue Docopt::Exit => e
|
12
12
|
STDERR.write(e.message + "\n")
|
13
13
|
::Kernel.exit(DOCOPT_ERROR_EXIT_CODE) # rubocop:disable Rails/Exit
|
@@ -25,6 +25,8 @@ module EacRubyUtils
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module SubcommandsSupport
|
28
|
+
EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME = :extra_available_subcommands
|
29
|
+
|
28
30
|
def check_subcommands_arg
|
29
31
|
if subcommand_arg_as_list?
|
30
32
|
singleton_class.include(SubcommandsSupport::SubcommandArgAsList)
|
@@ -43,7 +45,7 @@ module EacRubyUtils
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def subcommand
|
46
|
-
@subcommand ||= subcommand_class_name(subcommand_name).constantize.
|
48
|
+
@subcommand ||= subcommand_class_name(subcommand_name).constantize.create(
|
47
49
|
argv: subcommand_args,
|
48
50
|
program_name: subcommand_program,
|
49
51
|
parent: self
|
@@ -77,7 +79,11 @@ module EacRubyUtils
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def available_subcommands
|
80
|
-
(setting_value(:subcommands, false) || auto_available_subcommands)
|
82
|
+
r = ::Set.new(setting_value(:subcommands, false) || auto_available_subcommands)
|
83
|
+
if respond_to?(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME, true)
|
84
|
+
r += send(EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME)
|
85
|
+
end
|
86
|
+
r.sort
|
81
87
|
end
|
82
88
|
|
83
89
|
def auto_available_subcommands
|
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'addressable'
|
4
4
|
require 'eac_ruby_utils/envs/base_env'
|
5
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
6
|
+
require 'eac_ruby_utils/patches/module/require_sub'
|
5
7
|
require 'net/ssh'
|
6
8
|
require 'shellwords'
|
7
9
|
|
8
10
|
module EacRubyUtils
|
9
11
|
module Envs
|
10
12
|
class SshEnv < ::EacRubyUtils::Envs::BaseEnv
|
13
|
+
require_sub __FILE__, include_modules: true
|
14
|
+
|
11
15
|
USER_PATTERN = /[a-z_][a-z0-9_-]*/.freeze
|
12
16
|
HOSTNAME_PATTERN = /[^@]+/.freeze
|
13
17
|
USER_HOSTNAME_PATTERN = /\A(?:(#{USER_PATTERN})@)?(#{HOSTNAME_PATTERN})\z/.freeze
|
@@ -49,17 +53,16 @@ module EacRubyUtils
|
|
49
53
|
private
|
50
54
|
|
51
55
|
def ssh_command_line
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
r.map { |a| Shellwords.escape(a) }.join(' ')
|
56
|
+
(%w[ssh] +
|
57
|
+
%w[nodasho dasho port].flat_map { |m| send("ssh_command_line_#{m}_args") } +
|
58
|
+
[user_hostname_uri])
|
59
|
+
.map { |a| Shellwords.escape(a) }.join(' ')
|
57
60
|
end
|
58
61
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
def ssh_command_line_port_args
|
63
|
+
uri.port.if_present([]) do |v|
|
64
|
+
['-p', v]
|
65
|
+
end
|
63
66
|
end
|
64
67
|
|
65
68
|
def user_hostname_uri
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/common_concern'
|
4
|
+
require 'eac_ruby_utils/patches/module/simple_cache'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
module Envs
|
8
|
+
class SshEnv < ::EacRubyUtils::Envs::BaseEnv
|
9
|
+
module DashoOptions
|
10
|
+
common_concern
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def add_nodasho_option(name)
|
14
|
+
return if nodasho_options.include?(name)
|
15
|
+
|
16
|
+
nodasho_options << name
|
17
|
+
const_set("#{name.underscore}_option".upcase, name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def nodasho_options
|
21
|
+
@nodasho_options ||= []
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module InstanceMethods
|
26
|
+
def ssh_command_line_dasho_args
|
27
|
+
r = []
|
28
|
+
uri.query_values&.each do |k, v|
|
29
|
+
r += ['-o', "#{k}=#{v}"] unless nodasho_options.include?(k)
|
30
|
+
end
|
31
|
+
r
|
32
|
+
end
|
33
|
+
|
34
|
+
def ssh_command_line_nodasho_args
|
35
|
+
nodasho_options.flat_map do |option_name|
|
36
|
+
uri_query_value(option_name).if_present([]) do |option_value|
|
37
|
+
send("ssh_command_line_#{option_name.underscore}_args", option_value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def nodasho_options
|
43
|
+
self.class.nodasho_options
|
44
|
+
end
|
45
|
+
|
46
|
+
def uri_query_value(name)
|
47
|
+
uri.query_values.if_present { |v| v[name] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/envs/ssh_env/dasho_options'
|
5
|
+
require 'eac_ruby_utils/listable'
|
6
|
+
require 'eac_ruby_utils/patches/object/if_present'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
module Envs
|
10
|
+
class SshEnv < ::EacRubyUtils::Envs::BaseEnv
|
11
|
+
module IdentityFile
|
12
|
+
extend ::ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
include ::EacRubyUtils::Envs::SshEnv::DashoOptions
|
16
|
+
add_nodasho_option('IdentityFile')
|
17
|
+
end
|
18
|
+
|
19
|
+
def ssh_command_line_identity_file_args(value)
|
20
|
+
['-i', value]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'eac_ruby_utils/boolean'
|
5
|
+
require 'eac_ruby_utils/envs/ssh_env/dasho_options'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
module Envs
|
9
|
+
class SshEnv < ::EacRubyUtils::Envs::BaseEnv
|
10
|
+
module Quiet
|
11
|
+
extend ::ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include ::EacRubyUtils::Envs::SshEnv::DashoOptions
|
15
|
+
add_nodasho_option('Quiet')
|
16
|
+
end
|
17
|
+
|
18
|
+
def ssh_command_line_quiet_args(value)
|
19
|
+
::EacRubyUtils::Boolean.parse(value) ? ['-q'] : []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|