avm-tools 0.76.1 → 0.81.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/code_runner.rb +1 -2
- data/lib/avm/eac_rails_base1/runner/rails_server.rb +33 -0
- 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/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 +34 -39
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- 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/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -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/runner.rb +12 -4
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +16 -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 +1 -1
- 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 +10 -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 +17 -5
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- 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 +0 -1
- 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_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -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/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- 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_concern_spec.rb +30 -17
- 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/struct_spec.rb +12 -1
- metadata +28 -7
- data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +0 -36
- data/lib/avm/tools/runner/eac_rails_base0/runner.rb +0 -14
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -68
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
@@ -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
|
@@ -28,7 +28,7 @@ module EacCli
|
|
28
28
|
sklass = klass.singleton_class
|
29
29
|
return unless sklass.method_defined?(from)
|
30
30
|
|
31
|
-
sklass.alias_method to, from
|
31
|
+
sklass.send(:alias_method, to, from)
|
32
32
|
end
|
33
33
|
|
34
34
|
def build_method_name(name, suffix)
|
@@ -44,6 +44,8 @@ module EacCli
|
|
44
44
|
extend AfterClassMethods
|
45
45
|
include InstanceMethods
|
46
46
|
::EacCli::Docopt::RunnerExtension.check(self)
|
47
|
+
include ActiveSupport::Callbacks
|
48
|
+
define_callbacks :run
|
47
49
|
end
|
48
50
|
|
49
51
|
module AfterClassMethods
|
@@ -55,8 +57,7 @@ module EacCli
|
|
55
57
|
|
56
58
|
def run(*runner_context_args)
|
57
59
|
r = create(*runner_context_args)
|
58
|
-
r.
|
59
|
-
r.run
|
60
|
+
r.run_run
|
60
61
|
r
|
61
62
|
end
|
62
63
|
|
@@ -72,6 +73,13 @@ module EacCli
|
|
72
73
|
end
|
73
74
|
|
74
75
|
module InstanceMethods
|
76
|
+
def run_run
|
77
|
+
parsed
|
78
|
+
run_callbacks(:run) { run }
|
79
|
+
rescue ::EacCli::Runner::Exit # rubocop:disable Lint/SuppressedException
|
80
|
+
# Do nothing
|
81
|
+
end
|
82
|
+
|
75
83
|
def runner_context
|
76
84
|
return @runner_context if @runner_context
|
77
85
|
|
@@ -84,7 +92,7 @@ module EacCli
|
|
84
92
|
end
|
85
93
|
|
86
94
|
def parsed
|
87
|
-
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition
|
95
|
+
@parsed ||= ::EacCli::Parser.new(self.class.runner_definition, runner_context.argv).parsed
|
88
96
|
end
|
89
97
|
end
|
90
98
|
end
|
@@ -10,9 +10,24 @@ module EacCli
|
|
10
10
|
include ::EacCli::Runner
|
11
11
|
|
12
12
|
runner_definition.alt do
|
13
|
-
|
13
|
+
options_argument false
|
14
14
|
bool_opt '-h', '--help', 'Show help.', usage: true
|
15
15
|
end
|
16
|
+
|
17
|
+
set_callback :run, :before do
|
18
|
+
help_run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def help_run
|
23
|
+
return unless parsed.help?
|
24
|
+
|
25
|
+
puts help_text
|
26
|
+
raise ::EacCli::Runner::Exit
|
27
|
+
end
|
28
|
+
|
29
|
+
def help_text
|
30
|
+
::EacCli::Docopt::DocBuilder.new(self.class.runner_definition).to_s
|
16
31
|
end
|
17
32
|
end
|
18
33
|
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,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
|
@@ -22,4 +22,14 @@ RSpec.describe ::EacCli::Docopt::RunnerExtension do
|
|
22
22
|
|
23
23
|
it { expect(instance.options.fetch('--opt1')).to eq('aaa') }
|
24
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
|
25
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
|
@@ -23,9 +23,17 @@ RSpec.describe ::EacCli::Runner do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
let(:instance) { runner_class.create(argv) }
|
27
|
+
let(:parsed_actual) { instance.parsed.to_h.symbolize_keys }
|
28
|
+
|
26
29
|
context 'when all args are supplied' do
|
27
|
-
let(:
|
30
|
+
let(:argv) { %w[--opt1 aaa --opt2 bbb ccc ddd] }
|
31
|
+
let(:parsed_expected) do
|
32
|
+
{ opt1: 'aaa', opt2: true, opt3: false, pos1: 'bbb',
|
33
|
+
pos2: %w[ccc ddd] }
|
34
|
+
end
|
28
35
|
|
36
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
29
37
|
it { expect(instance.parsed.opt1).to eq('aaa') }
|
30
38
|
it { expect(instance.parsed.opt2?).to eq(true) }
|
31
39
|
it { expect(instance.parsed.pos1).to eq('bbb') }
|
@@ -33,8 +41,10 @@ RSpec.describe ::EacCli::Runner do
|
|
33
41
|
end
|
34
42
|
|
35
43
|
context 'when only required args are supplied' do
|
36
|
-
let(:
|
44
|
+
let(:argv) { %w[bbb] }
|
45
|
+
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: false, pos1: 'bbb', pos2: [] } }
|
37
46
|
|
47
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
38
48
|
it { expect(instance.parsed.opt1).to be_nil }
|
39
49
|
it { expect(instance.parsed.opt2?).to eq(false) }
|
40
50
|
it { expect(instance.parsed.pos1).to eq('bbb') }
|
@@ -42,7 +52,7 @@ RSpec.describe ::EacCli::Runner do
|
|
42
52
|
end
|
43
53
|
|
44
54
|
context 'when required args are not supplied' do
|
45
|
-
let(:
|
55
|
+
let(:argv) { %w[] }
|
46
56
|
|
47
57
|
it do
|
48
58
|
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
@@ -50,8 +60,10 @@ RSpec.describe ::EacCli::Runner do
|
|
50
60
|
end
|
51
61
|
|
52
62
|
context 'when alternative args are supplied' do
|
53
|
-
let(:
|
63
|
+
let(:argv) { %w[--opt3] }
|
64
|
+
let(:parsed_expected) { { opt1: nil, opt2: false, opt3: true, pos1: nil, pos2: [] } }
|
54
65
|
|
66
|
+
it { expect(parsed_actual).to eq(parsed_expected) }
|
55
67
|
it { expect(instance.parsed.opt3?).to eq(true) }
|
56
68
|
end
|
57
69
|
|
@@ -69,7 +81,7 @@ RSpec.describe ::EacCli::Runner do
|
|
69
81
|
end
|
70
82
|
end
|
71
83
|
|
72
|
-
let(:
|
84
|
+
let(:argv) { %w[aaa bbb] }
|
73
85
|
|
74
86
|
it do
|
75
87
|
expect { instance.parsed }.to raise_error(::EacCli::Parser::Error)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner_with/help'
|
4
|
+
require 'eac_ruby_utils/fs/temp'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::RunnerWith::Help do
|
7
|
+
let(:runner) do
|
8
|
+
the_module = described_class
|
9
|
+
Class.new do
|
10
|
+
include the_module
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
desc 'A stub runner.'
|
14
|
+
pos_arg :a_argument
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
puts 'Runner run'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:runner_argv) { ['--help'] }
|
24
|
+
let(:instance) { runner.create(argv: runner_argv) }
|
25
|
+
let(:expected_output) do
|
26
|
+
<<~OUTPUT
|
27
|
+
A stub runner.
|
28
|
+
|
29
|
+
Usage:
|
30
|
+
__PROGRAM__ [options] <a_argument>
|
31
|
+
__PROGRAM__ --help
|
32
|
+
|
33
|
+
Options:
|
34
|
+
-h --help Show help.
|
35
|
+
|
36
|
+
OUTPUT
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'show help text' do
|
40
|
+
expect { instance.run_run }.to output(expected_output).to_stdout_from_any_process
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/runner_with/output_file'
|
4
|
+
require 'eac_ruby_utils/fs/temp'
|
5
|
+
|
6
|
+
RSpec.describe ::EacCli::RunnerWith::OutputFile do
|
7
|
+
let(:runner) do
|
8
|
+
the_module = described_class
|
9
|
+
Class.new do
|
10
|
+
include the_module
|
11
|
+
|
12
|
+
runner_definition do
|
13
|
+
desc 'A stub root runner.'
|
14
|
+
pos_arg :input_text
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
run_output
|
19
|
+
end
|
20
|
+
|
21
|
+
def output_content
|
22
|
+
parsed.input_text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:stub_text) { 'STUB_TEXT' }
|
28
|
+
let(:instance) { runner.create(argv: runner_argv) }
|
29
|
+
|
30
|
+
context 'without --output-file option' do
|
31
|
+
let(:runner_argv) { [stub_text] }
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect { instance.run }.to output(stub_text).to_stdout_from_any_process
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with --output-file option' do
|
39
|
+
let(:output_file) { ::EacRubyUtils::Fs::Temp.file }
|
40
|
+
let(:runner_argv) { ['--output-file', output_file.to_path, stub_text] }
|
41
|
+
|
42
|
+
before do
|
43
|
+
instance.run
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
output_file.remove
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect(output_file).to exist }
|
51
|
+
it { expect(output_file.read).to eq(stub_text) }
|
52
|
+
end
|
53
|
+
end
|