avm-tools 0.76.0 → 0.80.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/patches/class/i18n.rb +31 -0
- data/lib/avm/patches/object/i18n.rb +2 -10
- data/lib/avm/projects/stereotypes/ruby_gem/update.rb +4 -1
- data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +1 -2
- data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +7 -16
- data/lib/avm/tools/runner/git/subrepo/clone.rb +84 -0
- data/lib/avm/tools/runner/git/subrepo/fix.rb +65 -0
- data/lib/avm/tools/version.rb +1 -1
- data/template/avm/eac_redmine_base0/deploy/config/install.sh.template +12 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
- data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/runner.rb +6 -2
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- 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/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +57 -40
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +32 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +1 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
- 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 +7 -2
- 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/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- 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/module/abstract_methods.rb +10 -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/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- 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
- metadata +33 -5
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/parser/collector'
|
4
|
+
require 'eac_cli/parser/error'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacCli
|
8
|
+
class Parser
|
9
|
+
class Alternative
|
10
|
+
require_sub __FILE__, include_modules: true
|
11
|
+
enable_listable
|
12
|
+
lists.add_symbol :phase, :any, :option_argument, :positional
|
13
|
+
attr_reader :error
|
14
|
+
|
15
|
+
common_constructor :alternative, :argv do
|
16
|
+
alternative.assert_argument(::EacCli::Definition::Alternative, :alternative)
|
17
|
+
self.phase = PHASE_ANY
|
18
|
+
collect
|
19
|
+
end
|
20
|
+
|
21
|
+
def error?
|
22
|
+
error.present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def parsed
|
26
|
+
@parsed ||= collector.to_data.freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_accessor :phase
|
32
|
+
|
33
|
+
def any_collect_argv_value
|
34
|
+
if argv_current_option?
|
35
|
+
option_collect_argv_value
|
36
|
+
else
|
37
|
+
positional_collect_argv_value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def collector
|
42
|
+
@collector ||= ::EacCli::Parser::Collector.new(alternative)
|
43
|
+
end
|
44
|
+
|
45
|
+
def collect
|
46
|
+
loop do
|
47
|
+
break unless argv_pending?
|
48
|
+
|
49
|
+
collect_argv_value
|
50
|
+
end
|
51
|
+
validate
|
52
|
+
rescue ::EacCli::Parser::Error => e
|
53
|
+
@error = e
|
54
|
+
end
|
55
|
+
|
56
|
+
def collect_argv_value
|
57
|
+
send("#{phase}_collect_argv_value")
|
58
|
+
argv_enum.next
|
59
|
+
end
|
60
|
+
|
61
|
+
def collect_option_argv_value
|
62
|
+
alternative.options.each do |option|
|
63
|
+
end
|
64
|
+
|
65
|
+
raise ::EacCli::Parser::Error.new(
|
66
|
+
alternative, argv, "Invalid option: #{argv_enum.current}"
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def raise_error(message)
|
71
|
+
raise ::EacCli::Parser::Error.new(alternative, argv, message)
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate
|
75
|
+
(alternative.options + alternative.positional).each do |option|
|
76
|
+
validate_option(option)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def validate_option(option)
|
81
|
+
return unless option.required?
|
82
|
+
return if collector.supplied?(option)
|
83
|
+
|
84
|
+
raise_error("Required option/positional #{option} not supplied")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module DoubleDash
|
7
|
+
DOUBLE_DASH = '--'
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
attr_accessor :double_dash
|
12
|
+
|
13
|
+
def argv_current_double_dash?
|
14
|
+
argv_enum.peek == DOUBLE_DASH && !double_dash
|
15
|
+
end
|
16
|
+
|
17
|
+
def double_dash_collect_argv_value
|
18
|
+
self.phase = PHASE_POSITIONAL
|
19
|
+
self.double_dash = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module Options
|
7
|
+
DOUBLE_DASH = '--'
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
attr_accessor :argument_option, :double_dash
|
12
|
+
|
13
|
+
def argument_option_collect_argv(option)
|
14
|
+
self.argument_option = option
|
15
|
+
self.phase = PHASE_OPTION_ARGUMENT
|
16
|
+
end
|
17
|
+
|
18
|
+
def argv_current_option?
|
19
|
+
phase == PHASE_ANY && argv_enum.peek.start_with?('-')
|
20
|
+
end
|
21
|
+
|
22
|
+
def argv_current_double_dash?
|
23
|
+
argv_enum.peek == DOUBLE_DASH && !double_dash
|
24
|
+
end
|
25
|
+
|
26
|
+
def boolean_option_collect_argv(option)
|
27
|
+
collector.collect(option, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def option_argument_collect_argv_value
|
31
|
+
collector.collect(argument_option, argv_enum.peek)
|
32
|
+
self.argument_option = nil
|
33
|
+
self.phase = PHASE_ANY
|
34
|
+
end
|
35
|
+
|
36
|
+
def option_collect_argv_value
|
37
|
+
return double_dash_collect_argv_value if argv_current_double_dash?
|
38
|
+
|
39
|
+
alternative.options.any? do |option|
|
40
|
+
next false unless [option.short, option.long].include?(argv_enum.peek)
|
41
|
+
|
42
|
+
if option.argument?
|
43
|
+
argument_option_collect_argv(option)
|
44
|
+
else
|
45
|
+
boolean_option_collect_argv(option)
|
46
|
+
end
|
47
|
+
|
48
|
+
true
|
49
|
+
end || raise_argv_current_invalid_option
|
50
|
+
end
|
51
|
+
|
52
|
+
def raise_argv_current_invalid_option
|
53
|
+
raise_error "Invalid option: \"#{argv_enum.peek}\""
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacCli
|
4
|
+
class Parser
|
5
|
+
class Alternative
|
6
|
+
module Positionals
|
7
|
+
private
|
8
|
+
|
9
|
+
def positional_collect_argv_value
|
10
|
+
positional_check
|
11
|
+
collector.collect(positional_enum.peek, argv_enum.peek)
|
12
|
+
positional_next
|
13
|
+
end
|
14
|
+
|
15
|
+
def positional_enum
|
16
|
+
@positional_enum ||= alternative.positional.each
|
17
|
+
end
|
18
|
+
|
19
|
+
def positional_check
|
20
|
+
raise_error("Invalid positional: #{argv_enum.peek}") if positional_enum.stopped?
|
21
|
+
end
|
22
|
+
|
23
|
+
def positional_next
|
24
|
+
self.phase = PHASE_POSITIONAL if positional_enum.peek.subcommand?
|
25
|
+
positional_enum.next unless positional_enum.peek.repeat?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -5,13 +5,14 @@ require 'eac_cli/runner'
|
|
5
5
|
require 'eac_cli/runner_with'
|
6
6
|
|
7
7
|
class Object
|
8
|
-
def runner_with(*runners)
|
8
|
+
def runner_with(*runners, &block)
|
9
9
|
include ::EacCli::Runner
|
10
10
|
enable_simple_cache
|
11
11
|
enable_console_speaker
|
12
12
|
runners.each do |runner|
|
13
13
|
include runner_with_to_module(runner)
|
14
14
|
end
|
15
|
+
runner_definition(&block) if block
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -18,13 +18,17 @@ module EacCli
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def runner?(object)
|
22
|
+
object.is_a?(::Class) && object.included_modules.include?(::EacCli::Runner)
|
23
|
+
end
|
24
|
+
|
21
25
|
private
|
22
26
|
|
23
27
|
def alias_class_method(klass, from, to)
|
24
28
|
sklass = klass.singleton_class
|
25
29
|
return unless sklass.method_defined?(from)
|
26
30
|
|
27
|
-
sklass.alias_method to, from
|
31
|
+
sklass.send(:alias_method, to, from)
|
28
32
|
end
|
29
33
|
|
30
34
|
def build_method_name(name, suffix)
|
@@ -80,7 +84,7 @@ module EacCli
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def parsed
|
83
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition
|
87
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
84
88
|
end
|
85
89
|
end
|
86
90
|
end
|
@@ -2,12 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'eac_cli/runner'
|
4
4
|
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'eac_ruby_utils/abstract_methods'
|
5
6
|
|
6
7
|
module EacCli
|
7
8
|
module RunnerWith
|
8
9
|
module OutputFile
|
9
10
|
common_concern do
|
10
11
|
include ::EacCli::Runner
|
12
|
+
include ::EacRubyUtils::AbstractMethods
|
13
|
+
|
14
|
+
abstract_methods :output_content
|
11
15
|
|
12
16
|
runner_definition do
|
13
17
|
arg_opt '-o', '--output-file', 'Output to file.'
|
@@ -18,7 +22,7 @@ module EacCli
|
|
18
22
|
if parsed.output_file.present?
|
19
23
|
::File.write(parsed.output_file, output_content)
|
20
24
|
else
|
21
|
-
|
25
|
+
$stdout.write(output_content)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/definition/alternative'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Definition::Alternative do
|
6
|
+
let(:instance) { described_class.new }
|
7
|
+
|
8
|
+
it { expect { instance.arg_opt '-a', '--opt2', 'A argument option' }.not_to raise_error }
|
9
|
+
it { expect { instance.bool_opt '-b', '--opt1', 'A boolean option' }.not_to raise_error }
|
10
|
+
it { expect { instance.options_argument(true) }.not_to raise_error }
|
11
|
+
it { expect { instance.pos_arg :pos1 }.not_to raise_error }
|
12
|
+
it { expect { instance.pos_arg :pos2, optional: true, repeat: true }.not_to raise_error }
|
13
|
+
it { expect { instance.subcommands }.not_to raise_error }
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/runner_extension'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Docopt::RunnerExtension do
|
6
|
+
let(:stub_runner) do
|
7
|
+
r = Class.new(::EacRubyUtils::Console::DocoptRunner) do
|
8
|
+
def run; end
|
9
|
+
end
|
10
|
+
r.include ::EacCli::Runner
|
11
|
+
r.runner_definition do
|
12
|
+
desc 'A stub runner.'
|
13
|
+
arg_opt '-o', '--opt1', 'A argument option'
|
14
|
+
pos_arg 'pos1'
|
15
|
+
end
|
16
|
+
r
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:instance) { stub_runner.new(argv: %w[-o aaa bbb]) }
|
20
|
+
|
21
|
+
before { instance.run }
|
22
|
+
|
23
|
+
it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
|
24
|
+
it { expect(instance.options.fetch('<pos1>')).to eq('bbb') }
|
25
|
+
it { expect(instance.doc).to eq(<<~EXPECTED) }
|
26
|
+
A stub runner.
|
27
|
+
|
28
|
+
Usage:
|
29
|
+
__PROGRAM__ [options] <pos1>
|
30
|
+
|
31
|
+
Options:
|
32
|
+
-o --opt1=<value> A argument option
|
33
|
+
|
34
|
+
EXPECTED
|
35
|
+
end
|