avm-tools 0.74.1 → 0.77.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/eac_rails_base1/runner/bundle.rb +2 -2
- data/lib/avm/eac_rails_base1/runner/code_runner.rb +3 -3
- data/lib/avm/eac_webapp_base0/deploy.rb +17 -40
- data/lib/avm/eac_webapp_base0/deploy/build.rb +48 -0
- data/lib/avm/eac_webapp_base0/deploy/git_info.rb +13 -0
- data/lib/avm/eac_webapp_base0/deploy/version.rb +4 -0
- data/lib/avm/eac_webapp_base0/deploy/write_on_target.rb +18 -0
- data/lib/avm/eac_webapp_base0/runner/deploy.rb +1 -0
- data/lib/avm/eac_writings_base0/apache_host.rb +17 -0
- data/lib/avm/eac_writings_base0/deploy.rb +36 -0
- data/lib/avm/eac_writings_base0/instance.rb +11 -0
- data/lib/avm/files/appendable.rb +55 -0
- data/lib/avm/files/appendable/file_content.rb +24 -0
- data/lib/avm/files/appendable/plain_directory.rb +25 -0
- data/lib/avm/files/appendable/resource_base.rb +13 -0
- data/lib/avm/files/appendable/tar_output_command.rb +26 -0
- data/lib/avm/files/appendable/templatized_directory.rb +28 -0
- data/lib/avm/files/appender.rb +11 -0
- data/lib/avm/files/deploy.rb +72 -0
- data/lib/avm/files/formatter.rb +8 -4
- data/lib/avm/git/auto_commit_path.rb +2 -4
- data/lib/avm/git/auto_commit_path/ruby.rb +20 -0
- data/lib/avm/git/commit/deploy.rb +8 -61
- data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +1 -0
- data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +7 -16
- data/lib/avm/tools/runner/eac_writings_base0.rb +15 -0
- data/lib/avm/tools/runner/files/format.rb +3 -2
- data/lib/avm/tools/runner/git/auto_commit.rb +11 -0
- data/lib/avm/tools/runner/git/deploy.rb +1 -1
- data/lib/avm/tools/version.rb +1 -1
- data/template/avm/eac_redmine_base0/deploy/config/install.sh.template +12 -0
- data/template/avm/{stereotypes/eac_ubuntu_base0 → eac_ubuntu_base0}/docker_image/Dockerfile +0 -0
- data/template/avm/{stereotypes/eac_wordpress_base0 → eac_wordpress_base0}/deploy/wp-config.php.template +0 -0
- data/template/avm/eac_writings_base0/deploy/index.html.template +9 -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/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/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 +59 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -107
- 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/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/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/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 +45 -12
- data/lib/avm/git/commit/deploy/appended.rb +0 -37
- data/lib/avm/git/commit/deploy/appended/base.rb +0 -17
- data/lib/avm/git/commit/deploy/appended/directory.rb +0 -32
- data/lib/avm/git/commit/deploy/appended/file_content.rb +0 -28
- data/lib/avm/tools/runner/eac_rails_base0/bundle.rb +0 -14
- 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,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
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/docopt/runner_extension'
|
4
|
+
|
5
|
+
RSpec.describe ::EacCli::Parser::Alternative do
|
6
|
+
let(:instance) { described_class.new(alternative, argv) }
|
7
|
+
let(:actual_parsed) { instance.parsed.to_h.symbolize_keys }
|
8
|
+
|
9
|
+
context 'without subcommands' do
|
10
|
+
let(:alternative) do
|
11
|
+
r = ::EacCli::Definition::Alternative.new
|
12
|
+
r.bool_opt '-b', '--opt1', 'A boolean option'
|
13
|
+
r.arg_opt '-a', '--opt2', 'A argument option'
|
14
|
+
r.bool_opt '-c', '--opt3', 'A required boolean option', required: true
|
15
|
+
r.pos_arg :pos1
|
16
|
+
r.pos_arg :pos2, optional: true, repeat: true
|
17
|
+
r
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with all values' do
|
21
|
+
let(:argv) { %w[--opt1 --opt2 OPT2 --opt3 POS1 POS2_1 POS2_2] }
|
22
|
+
let(:parsed_expected) do
|
23
|
+
{
|
24
|
+
opt1: true, opt2: 'OPT2', opt3: true, pos1: 'POS1', pos2: %w[POS2_1 POS2_2]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it { expect(instance.error).to be_blank }
|
29
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with only required values' do
|
33
|
+
let(:argv) { %w[--opt3 POS1] }
|
34
|
+
let(:parsed_expected) { { opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: [] } }
|
35
|
+
|
36
|
+
it { expect(instance.error).to be_blank }
|
37
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with double dash' do
|
41
|
+
let(:argv) { %w[--opt3 POS1 -- --opt1 --] }
|
42
|
+
let(:parsed_expected) do
|
43
|
+
{ opt1: false, opt2: nil, opt3: true, pos1: 'POS1', pos2: %w[--opt1 --] }
|
44
|
+
end
|
45
|
+
|
46
|
+
it { expect(instance.error).to be_blank }
|
47
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'without required positional' do
|
51
|
+
let(:argv) { %w[--opt1 --opt3] }
|
52
|
+
let(:parsed_expected) { { opt1: true, opt2: nil, opt3: true, pos1: nil, pos2: [] } }
|
53
|
+
|
54
|
+
it { expect(instance.error).to be_present }
|
55
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'without required option' do
|
59
|
+
let(:argv) { %w[--opt1 POS1] }
|
60
|
+
let(:parsed_expected) { { opt1: true, opt2: nil, opt3: false, pos1: 'POS1', pos2: [] } }
|
61
|
+
|
62
|
+
it { expect(instance.error).to be_present }
|
63
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'without any required option or positional' do
|
67
|
+
let(:argv) { %w[] }
|
68
|
+
let(:parsed_expected) { { opt1: false, opt2: nil, opt3: false, pos1: nil, pos2: [] } }
|
69
|
+
|
70
|
+
it { expect(instance.error).to be_present }
|
71
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with excedent positional' do
|
75
|
+
let(:alternative) do
|
76
|
+
r = ::EacCli::Definition::Alternative.new
|
77
|
+
r.pos_arg :pos1
|
78
|
+
r
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:argv) { %w[POS1 POS2] }
|
82
|
+
let(:parsed_expected) { { pos1: 'POS1' } }
|
83
|
+
|
84
|
+
it { expect(instance.error).to be_present }
|
85
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with subcommands' do
|
90
|
+
let(:alternative) do
|
91
|
+
r = ::EacCli::Definition::Alternative.new
|
92
|
+
r.bool_opt '-b', '--opt1', 'A boolean option'
|
93
|
+
r.arg_opt '-a', '--opt2', 'A argument option'
|
94
|
+
r.subcommands
|
95
|
+
r
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with all values' do
|
99
|
+
let(:argv) { %w[--opt1 --opt2 OPT2 CMD CMD_ARG_1 --CMD_ARG_2] }
|
100
|
+
let(:parsed_expected) do
|
101
|
+
{
|
102
|
+
opt1: true, opt2: 'OPT2',
|
103
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
|
104
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => %w[CMD_ARG_1 --CMD_ARG_2]
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
it { expect(instance.error).to be_blank }
|
109
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with only required values' do
|
113
|
+
let(:argv) { %w[CMD] }
|
114
|
+
let(:parsed_expected) do
|
115
|
+
{
|
116
|
+
opt1: false, opt2: nil,
|
117
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => 'CMD',
|
118
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
it { expect(instance.error).to be_blank }
|
123
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'without required values' do
|
127
|
+
let(:argv) { %w[--opt1] }
|
128
|
+
let(:parsed_expected) do
|
129
|
+
{
|
130
|
+
opt1: true, opt2: nil,
|
131
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_NAME_ARG => nil,
|
132
|
+
::EacCli::Definition::Alternative::SUBCOMMAND_ARGS_ARG => []
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
it { expect(instance.error).to be_present }
|
137
|
+
it { expect(actual_parsed).to eq(parsed_expected) }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -4,67 +4,84 @@ require 'eac_ruby_utils/console/docopt_runner'
|
|
4
4
|
require 'eac_cli/runner'
|
5
5
|
|
6
6
|
RSpec.describe ::EacCli::Runner do
|
7
|
-
let(:
|
8
|
-
|
7
|
+
let(:runner_class) do
|
8
|
+
the_module = described_class
|
9
|
+
::Class.new do
|
10
|
+
include the_module
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
arg_opt '-o', '--opt1', 'A arg option.'
|
14
|
+
bool_opt '-o', '--opt2', 'A boolean option'
|
15
|
+
pos_arg :pos1
|
16
|
+
pos_arg :pos2, repeat: true, optional: true
|
17
|
+
alt do
|
18
|
+
bool_opt '-a', '--opt3', 'A boolean option in a alternative.', required: true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
def run; end
|
10
23
|
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
24
|
end
|
19
25
|
|
20
|
-
let(:instance) {
|
26
|
+
let(:instance) { runner_class.create(argv) }
|
27
|
+
let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
|
28
|
+
|
29
|
+
context 'when all args are supplied' do
|
30
|
+
let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
|
31
|
+
let(:parsed_expected) { { opt1: 'aaa', opt2: true, pos1: 'bbb', pos2: %w[ccc ddd] } }
|
32
|
+
|
33
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
34
|
+
it { expect(instance.parsed.opt1).to eq('aaa') }
|
35
|
+
it { expect(instance.parsed.opt2?).to eq(true) }
|
36
|
+
it { expect(instance.parsed.pos1).to eq('bbb') }
|
37
|
+
it { expect(instance.parsed.pos2).to eq(%w[ccc ddd]) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when only required args are supplied' do
|
41
|
+
let(:argv) { %w[bbb] }
|
42
|
+
let(:parsed_expected) { { opt1: nil, opt2: false, pos1: 'bbb', pos2: [] } }
|
21
43
|
|
22
|
-
|
44
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
45
|
+
it { expect(instance.parsed.opt1).to be_nil }
|
46
|
+
it { expect(instance.parsed.opt2?).to eq(false) }
|
47
|
+
it { expect(instance.parsed.pos1).to eq('bbb') }
|
48
|
+
it { expect(instance.parsed.pos2).to eq([]) }
|
49
|
+
end
|
23
50
|
|
24
|
-
|
25
|
-
|
51
|
+
context 'when required args are not supplied' do
|
52
|
+
let(:argv) { %w[] }
|
26
53
|
|
27
|
-
|
54
|
+
it do
|
55
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when alternative args are supplied' do
|
60
|
+
let(:argv) { %w[--opt3] }
|
61
|
+
let(:parsed_expected) { { opt3: true } }
|
62
|
+
|
63
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
64
|
+
it { expect(instance.parsed.opt3?).to eq(true) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when extra args are not supplied' do
|
28
68
|
let(:runner_class) do
|
29
69
|
the_module = described_class
|
30
70
|
::Class.new do
|
31
71
|
include the_module
|
32
72
|
|
33
73
|
runner_definition do
|
34
|
-
arg_opt '-o', '--opt1', 'A arg option.'
|
35
|
-
bool_opt '-o', '--opt2', 'A boolean option'
|
36
74
|
pos_arg :pos1
|
37
|
-
pos_arg :pos2, repeat: true, optional: true
|
38
75
|
end
|
39
76
|
|
40
77
|
def run; end
|
41
78
|
end
|
42
79
|
end
|
43
80
|
|
44
|
-
|
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
|
81
|
+
let(:argv) { %w[aaa bbb] }
|
52
82
|
|
53
|
-
|
54
|
-
|
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
|
83
|
+
it do
|
84
|
+
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
68
85
|
end
|
69
86
|
end
|
70
87
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner'
|
4
|
+
require 'eac_cli/runner_with/subcommands'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::RunnerWith::Subcommands do
|
7
|
+
let(:parent_runner) do
|
8
|
+
the_module = described_class
|
9
|
+
the_child = child_runner
|
10
|
+
Class.new do
|
11
|
+
include ::EacCli::Runner
|
12
|
+
include the_module
|
13
|
+
const_set('ChildCmd', the_child)
|
14
|
+
|
15
|
+
runner_definition do
|
16
|
+
desc 'A stub root runner.'
|
17
|
+
arg_opt '-r', '--root-var', 'A root variable.'
|
18
|
+
subcommands
|
19
|
+
end
|
20
|
+
|
21
|
+
delegate :root_var, to: :parsed
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:child_runner) do
|
26
|
+
::Class.new do
|
27
|
+
include ::EacCli::Runner
|
28
|
+
|
29
|
+
runner_definition do
|
30
|
+
bool_opt '-c', '--child-opt', 'A boolean option.'
|
31
|
+
pos_arg :child_var
|
32
|
+
end
|
33
|
+
|
34
|
+
def run; end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:instance) { parent_runner.create(argv: parent_argv) }
|
39
|
+
|
40
|
+
context 'when subcommand is supplied' do
|
41
|
+
let(:parent_argv) { %w[--root-var 123 child-cmd --child-opt 456] }
|
42
|
+
|
43
|
+
it { expect(instance.parsed.root_var).to eq('123') }
|
44
|
+
it { expect(instance.parsed.subcommand).to eq('child-cmd') }
|
45
|
+
it { expect(instance.parsed.subcommand_args).to eq(%w[--child-opt 456]) }
|
46
|
+
it { expect(instance.subcommand_runner.parsed.child_opt).to eq(true) }
|
47
|
+
it { expect(instance.subcommand_runner.parsed.child_var).to eq('456') }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when subcommand is not supplied' do
|
51
|
+
let(:instance) { parent_runner.create(%w[456]) }
|
52
|
+
|
53
|
+
it do
|
54
|
+
expect { instance.run }.to raise_error(::EacCli::Parser::Error)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_ruby_utils/filesystem_cache'
|
4
5
|
|
5
6
|
module EacRubyBase0
|
6
7
|
class Application
|
7
8
|
enable_simple_cache
|
8
|
-
|
9
|
+
enable_listable
|
10
|
+
lists.add_symbol :option, :name, :home_dir
|
11
|
+
|
12
|
+
common_constructor :gemspec_dir, :options, default: [{}] do
|
9
13
|
self.gemspec_dir = gemspec_dir.to_pathname
|
14
|
+
self.options = options.symbolize_keys.assert_valid_keys(self.class.lists.option.values).freeze
|
10
15
|
end
|
11
16
|
|
12
17
|
delegate :version, to: :self_gem
|
@@ -15,6 +20,32 @@ module EacRubyBase0
|
|
15
20
|
vendor_gems + [self_gem]
|
16
21
|
end
|
17
22
|
|
23
|
+
{ cache: '.cache', config: '.config', data: '.local/share' }.each do |item, subpath|
|
24
|
+
xdg_env_method_name = "#{item}_xdg_env"
|
25
|
+
|
26
|
+
define_method xdg_env_method_name do
|
27
|
+
ENV["XDG_#{item.upcase}_HOME"].if_present(&:to_pathname)
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method "#{item}_dir" do
|
31
|
+
(send(xdg_env_method_name) || home_dir.join(subpath)).join(name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def fs_cache
|
36
|
+
@fs_cache ||= ::EacRubyUtils::FilesystemCache.new(
|
37
|
+
cache_dir.join(::EacRubyUtils::FilesystemCache.name.parameterize)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def home_dir
|
42
|
+
@home_dir ||= (options[OPTION_HOME_DIR] || ENV.fetch('HOME')).to_pathname
|
43
|
+
end
|
44
|
+
|
45
|
+
def name
|
46
|
+
options[OPTION_NAME] || self_gem.name
|
47
|
+
end
|
48
|
+
|
18
49
|
def vendor_dir
|
19
50
|
gemspec_dir.join('vendor')
|
20
51
|
end
|