escort 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +8 -0
- data/README.md +365 -14
- data/TODO.md +157 -44
- data/escort.gemspec +1 -0
- data/examples/{1_1_basic.rb → attic/1_1_basic.rb} +0 -0
- data/examples/{1_2_basic_requires_arguments.rb → attic/1_2_basic_requires_arguments.rb} +0 -0
- data/examples/{2_2_command.rb → attic/2_2_command.rb} +0 -0
- data/examples/{2_2_command_requires_arguments.rb → attic/2_2_command_requires_arguments.rb} +0 -0
- data/examples/{2_3_nested_commands.rb → attic/2_3_nested_commands.rb} +0 -0
- data/examples/{3_validations.rb → attic/3_validations.rb} +0 -0
- data/examples/{4_1_config_file.rb → attic/4_1_config_file.rb} +0 -0
- data/examples/{argument_handling → attic/argument_handling}/basic.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/basic_command.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/no_arguments.rb +0 -0
- data/examples/{argument_handling → attic/argument_handling}/no_arguments_command.rb +0 -0
- data/examples/{command_aliases → attic/command_aliases}/app.rb +0 -0
- data/examples/{config_file → attic/config_file}/.apprc2 +0 -0
- data/examples/{config_file → attic/config_file}/app.rb +0 -0
- data/examples/{config_file → attic/config_file}/sub_commands.rb +0 -0
- data/examples/{default_command → attic/default_command}/app.rb +0 -0
- data/examples/{sub_commands → attic/sub_commands}/app.rb +0 -0
- data/examples/{validation_basic → attic/validation_basic}/app.rb +0 -0
- data/examples/basic +10 -0
- data/examples/basic_conflicts +17 -0
- data/examples/basic_depends_on +25 -0
- data/examples/basic_flags +15 -0
- data/examples/basic_options +14 -0
- data/examples/basic_options_multi +15 -0
- data/examples/basic_require_arguments +17 -0
- data/examples/basic_texts +21 -0
- data/examples/basic_validations +21 -0
- data/examples/command +19 -0
- data/examples/commands/example_command.rb +13 -0
- data/lib/escort/action_command/base.rb +4 -0
- data/lib/escort/app.rb +33 -11
- data/lib/escort/formatter/borderless_table.rb +4 -0
- data/lib/escort/formatter/command.rb +87 -0
- data/lib/escort/formatter/commands.rb +36 -0
- data/lib/escort/formatter/default_help_formatter.rb +68 -73
- data/lib/escort/formatter/global_command.rb +17 -0
- data/lib/escort/formatter/option.rb +138 -0
- data/lib/escort/formatter/options.rb +17 -3
- data/lib/escort/formatter/shell_command_executor.rb +49 -0
- data/lib/escort/formatter/terminal.rb +17 -9
- data/lib/escort/formatter/terminal_formatter.rb +6 -0
- data/lib/escort/logger.rb +4 -4
- data/lib/escort/option_dependency_validator.rb +83 -0
- data/lib/escort/option_parser.rb +11 -1
- data/lib/escort/setup/configuration/reader.rb +0 -2
- data/lib/escort/setup/configuration/writer.rb +0 -2
- data/lib/escort/setup/dsl/command.rb +2 -7
- data/lib/escort/setup/dsl/global.rb +2 -9
- data/lib/escort/setup/dsl/options.rb +56 -0
- data/lib/escort/setup_accessor.rb +23 -6
- data/lib/escort/trollop.rb +4 -3
- data/lib/escort/validator.rb +4 -1
- data/lib/escort/version.rb +1 -1
- data/lib/escort.rb +8 -1
- data/spec/integration/basic_conflicts_spec.rb +47 -0
- data/spec/integration/basic_depends_on_spec.rb +275 -0
- data/spec/integration/basic_options_spec.rb +9 -21
- data/spec/integration/basic_options_with_multi_spec.rb +30 -0
- data/spec/integration/basic_spec.rb +5 -6
- data/spec/integration/basic_validations_spec.rb +77 -0
- data/spec/integration/basic_with_arguments_spec.rb +33 -0
- data/spec/integration/basic_with_text_fields_spec.rb +21 -0
- data/spec/lib/escort/formatter/command_spec.rb +238 -0
- data/spec/lib/escort/formatter/global_command_spec.rb +50 -0
- data/spec/lib/escort/formatter/option_spec.rb +300 -0
- data/spec/lib/escort/formatter/shell_command_executor_spec.rb +59 -0
- data/spec/lib/escort/formatter/string_splitter_spec.rb +12 -0
- data/spec/lib/escort/formatter/terminal_spec.rb +19 -0
- data/spec/lib/escort/setup_accessor_spec.rb +1 -0
- data/spec/spec_helper.rb +9 -3
- data/spec/support/integration_helpers.rb +2 -0
- data/spec/{helpers/execute_action_matcher.rb → support/matchers/execute_action_for_command_matcher.rb} +3 -3
- data/spec/support/matchers/execute_action_with_arguments_matcher.rb +25 -0
- data/spec/support/matchers/execute_action_with_options_matcher.rb +29 -0
- data/spec/support/matchers/exit_with_code_matcher.rb +29 -0
- data/spec/support/shared_contexts/integration_setup.rb +34 -0
- metadata +86 -28
- data/examples/basic/app.rb +0 -16
- data/lib/escort/formatter/common.rb +0 -58
- data/spec/helpers/exit_with_code_matcher.rb +0 -21
- data/spec/helpers/give_option_to_action_with_value_matcher.rb +0 -22
@@ -0,0 +1,275 @@
|
|
1
|
+
describe "Escort basic app with dependent options", :integration => true do
|
2
|
+
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
+
|
4
|
+
context "when dependency specification has no 'on' parameter" do
|
5
|
+
let(:app_configuration) do
|
6
|
+
lambda do |app|
|
7
|
+
app.options do |opts|
|
8
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
9
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
10
|
+
|
11
|
+
opts.dependency :option1
|
12
|
+
end
|
13
|
+
|
14
|
+
app.action do |options, arguments|
|
15
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
let(:option_string) { "-f" }
|
20
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when option dependent on presence of flag" do
|
24
|
+
let(:app_configuration) do
|
25
|
+
lambda do |app|
|
26
|
+
app.options do |opts|
|
27
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
28
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
29
|
+
|
30
|
+
opts.dependency :option1, :on => :flag1
|
31
|
+
end
|
32
|
+
|
33
|
+
app.action do |options, arguments|
|
34
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "and flag is not present" do
|
40
|
+
let(:option_string) { "-o foo" }
|
41
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "and flag is present" do
|
45
|
+
let(:option_string) { "-f -o foo" }
|
46
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when flag depends on another flag" do
|
51
|
+
let(:app_configuration) do
|
52
|
+
lambda do |app|
|
53
|
+
app.options do |opts|
|
54
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
55
|
+
opts.opt :flag2, "Flag 2", :short => :none, :long => '--flag2', :type => :boolean, :default => true
|
56
|
+
opts.opt :flag3, "Flag 3", :short => :none, :long => '--flag3', :type => :boolean
|
57
|
+
opts.opt :flag4, "Flag 4", :short => :none, :long => '--flag4', :type => :boolean
|
58
|
+
|
59
|
+
opts.dependency :flag3, :on => :flag1
|
60
|
+
opts.dependency :flag4, :on => :flag2
|
61
|
+
end
|
62
|
+
|
63
|
+
app.action do |options, arguments|
|
64
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "and other flag has a default value of false" do
|
70
|
+
context "and other flag is present" do
|
71
|
+
let(:option_string) { "--flag1 --flag3" }
|
72
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and other flag is not present" do
|
76
|
+
let(:option_string) { "--flag3" }
|
77
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "and other flag has a default value of true" do
|
82
|
+
context "and other flag is present" do
|
83
|
+
let(:option_string) { "--flag2 --flag4" }
|
84
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "and other flag is not present" do
|
88
|
+
let(:option_string) { "--flag4" }
|
89
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "and other flag negative option is used" do
|
93
|
+
let(:option_string) { "--no-flag2 --flag4" }
|
94
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when option dependent on presence of multiple other options" do
|
100
|
+
let(:app_configuration) do
|
101
|
+
lambda do |app|
|
102
|
+
app.options do |opts|
|
103
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
104
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
105
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
|
106
|
+
|
107
|
+
opts.dependency :option2, :on => [:flag1, :option1]
|
108
|
+
end
|
109
|
+
|
110
|
+
app.action do |options, arguments|
|
111
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "and one of the other options is not present" do
|
117
|
+
let(:option_string) { "-f --option2=foo" }
|
118
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
119
|
+
end
|
120
|
+
|
121
|
+
context "and none of the other options are present" do
|
122
|
+
let(:option_string) { "--option2=foo" }
|
123
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
124
|
+
end
|
125
|
+
|
126
|
+
context "and all of the other options are present" do
|
127
|
+
let(:option_string) { "-f -o bar --option2=foo" }
|
128
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when option dependent on other option value" do
|
133
|
+
let(:app_configuration) do
|
134
|
+
lambda do |app|
|
135
|
+
app.options do |opts|
|
136
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
137
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
138
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
|
139
|
+
|
140
|
+
opts.dependency :option2, :on => {:option1 => 'bar'}
|
141
|
+
end
|
142
|
+
|
143
|
+
app.action do |options, arguments|
|
144
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "and other option is supplied with this value" do
|
150
|
+
let(:option_string) { "-o bar --option2=foo" }
|
151
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
152
|
+
end
|
153
|
+
|
154
|
+
context "and other option is supplied with different value" do
|
155
|
+
let(:option_string) { "-o baz --option2=foo" }
|
156
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and other option is not supplied" do
|
160
|
+
let(:option_string) { "--option2=foo" }
|
161
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "when option dependent on other option value and presence of yet another option" do
|
166
|
+
let(:app_configuration) do
|
167
|
+
lambda do |app|
|
168
|
+
app.options do |opts|
|
169
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
170
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
171
|
+
opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string, :multi => true
|
172
|
+
|
173
|
+
opts.dependency :option2, :on => [:flag1, {:option1 => 'bar'}]
|
174
|
+
end
|
175
|
+
|
176
|
+
app.action do |options, arguments|
|
177
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "and yet another option is not present" do
|
183
|
+
let(:option_string) { "-o bar --option2=foo" }
|
184
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
185
|
+
end
|
186
|
+
|
187
|
+
context "and other option has different value" do
|
188
|
+
let(:option_string) { "-o baz -f --option2=foo" }
|
189
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
190
|
+
end
|
191
|
+
|
192
|
+
context "and other option has the right value and yet another option is present" do
|
193
|
+
let(:option_string) { "-o bar -f --option2=foo" }
|
194
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when option dependent on itself" do
|
199
|
+
let(:app_configuration) do
|
200
|
+
lambda do |app|
|
201
|
+
app.options do |opts|
|
202
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
203
|
+
|
204
|
+
opts.dependency :option1, :on => :option1
|
205
|
+
end
|
206
|
+
|
207
|
+
app.action do |options, arguments|
|
208
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
let(:option_string) { "-o bar" }
|
213
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
214
|
+
end
|
215
|
+
|
216
|
+
context "when dependency specified for non-existant option" do
|
217
|
+
let(:app_configuration) do
|
218
|
+
lambda do |app|
|
219
|
+
app.options do |opts|
|
220
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
221
|
+
|
222
|
+
opts.dependency :option2, :on => :option1
|
223
|
+
end
|
224
|
+
|
225
|
+
app.action do |options, arguments|
|
226
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
let(:option_string) { "-o bar" }
|
231
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
232
|
+
end
|
233
|
+
|
234
|
+
context "when option dependent on non-existant option" do
|
235
|
+
let(:app_configuration) do
|
236
|
+
lambda do |app|
|
237
|
+
app.options do |opts|
|
238
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
|
239
|
+
|
240
|
+
opts.dependency :option1, :on => :option2
|
241
|
+
end
|
242
|
+
|
243
|
+
app.action do |options, arguments|
|
244
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
let(:option_string) { "-o bar" }
|
249
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
250
|
+
end
|
251
|
+
|
252
|
+
context "when dependency is specified inline" do
|
253
|
+
let(:app_configuration) do
|
254
|
+
lambda do |app|
|
255
|
+
app.options do |opts|
|
256
|
+
opts.opt :flag1, "Flag 1", :short => '-f', :long => '--flag1', :type => :boolean
|
257
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :depends_on => :flag1
|
258
|
+
end
|
259
|
+
|
260
|
+
app.action do |options, arguments|
|
261
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
context "and dependency is satisfied" do
|
266
|
+
let(:option_string) { "-f -o bar" }
|
267
|
+
it("it should exit successfully") { expect{subject}.to exit_with_code(0) }
|
268
|
+
end
|
269
|
+
|
270
|
+
context "and dependency is not satisfied" do
|
271
|
+
let(:option_string) { "-o bar" }
|
272
|
+
it("it should not exit successfully") { expect{subject}.to_not exit_with_code(0) }
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
@@ -1,26 +1,14 @@
|
|
1
|
-
describe "Escort basic app with options defined" do
|
1
|
+
describe "Escort basic app with options defined", :integration => true do
|
2
2
|
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
-
let(:result) { [] }
|
4
|
-
|
5
|
-
before do
|
6
|
-
$stderr = StringIO.new
|
7
|
-
$stdout = StringIO.new
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
$stderr = STDERR
|
12
|
-
$stdout = STDOUT
|
13
|
-
end
|
14
3
|
|
15
4
|
let(:app_configuration) do
|
16
|
-
|
5
|
+
lambda do |app|
|
17
6
|
app.options do |opts|
|
18
7
|
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :default => "option 1"
|
19
8
|
end
|
20
9
|
|
21
10
|
app.action do |options, arguments|
|
22
|
-
result
|
23
|
-
result << {:option1 => options[:global][:options][:option1]}
|
11
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
24
12
|
end
|
25
13
|
end
|
26
14
|
end
|
@@ -28,22 +16,22 @@ describe "Escort basic app with options defined" do
|
|
28
16
|
context "when called with empty option string" do
|
29
17
|
let(:option_string) { "" }
|
30
18
|
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
31
|
-
it("should execute the global action") { expect{subject}.to
|
32
|
-
it("option1 have its default value in action") { expect{subject}.to
|
19
|
+
it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
|
20
|
+
it("option1 have its default value in action") { expect{subject}.to execute_action_with_options(result, :option1 => 'option 1') }
|
33
21
|
end
|
34
22
|
|
35
23
|
context "when called with option string with short code option" do
|
36
24
|
let(:option_string) { "-o blah" }
|
37
25
|
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
38
|
-
it("should execute the global action") { expect{subject}.to
|
39
|
-
it("option1 have the value 'blah' in action") { expect{subject}.to
|
26
|
+
it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
|
27
|
+
it("option1 have the value 'blah' in action") { expect{subject}.to execute_action_with_options(result, :option1 => 'blah') }
|
40
28
|
end
|
41
29
|
|
42
30
|
context "when called with option string with long code option" do
|
43
31
|
let(:option_string) { "--option1=blah" }
|
44
32
|
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
45
|
-
it("should execute the global action") { expect{subject}.to
|
46
|
-
it("option1 have the value 'blah' in action") { expect{subject}.to
|
33
|
+
it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
|
34
|
+
it("option1 have the value 'blah' in action") { expect{subject}.to execute_action_with_options(result, :option1 => 'blah') }
|
47
35
|
end
|
48
36
|
|
49
37
|
context "when called with option string with unknown option" do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
describe "Escort basic app with multi option", :integration => true do
|
2
|
+
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
+
|
4
|
+
let(:app_configuration) do
|
5
|
+
lambda do |app|
|
6
|
+
app.options do |opts|
|
7
|
+
opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :multi => true
|
8
|
+
end
|
9
|
+
|
10
|
+
app.action do |options, arguments|
|
11
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when called with empty option string" do
|
17
|
+
let(:option_string) { "" }
|
18
|
+
it("option1 should be an empty array") { expect{subject}.to execute_action_with_options(result, :option1 => []) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when called with option1 specified once" do
|
22
|
+
let(:option_string) { "-o blah" }
|
23
|
+
it("option1 have the value ['blah'] in action") { expect{subject}.to execute_action_with_options(result, :option1 => ['blah']) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when called with option1 specified 3 times" do
|
27
|
+
let(:option_string) { "-o blah --option1=blah2 -o blah3" }
|
28
|
+
it("option1 have the value ['blah', 'blah2', 'blah3'] in action") { expect{subject}.to execute_action_with_options(result, :option1 => ['blah', 'blah2', 'blah3']) }
|
29
|
+
end
|
30
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
describe "Escort basic app with no options defined" do
|
1
|
+
describe "Escort basic app with no options defined", :integration => true do
|
2
2
|
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
-
let(:result) { [] }
|
4
3
|
|
5
4
|
let(:app_configuration) do
|
6
|
-
|
5
|
+
lambda do |app|
|
7
6
|
app.action do |options, arguments|
|
8
|
-
result
|
7
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -13,12 +12,12 @@ describe "Escort basic app with no options defined" do
|
|
13
12
|
context "when called with empty option string" do
|
14
13
|
let(:option_string) { "" }
|
15
14
|
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
16
|
-
it("should execute the global action") { expect{subject}.to
|
15
|
+
it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
|
17
16
|
end
|
18
17
|
|
19
18
|
context "when called with non-empty option string" do
|
20
19
|
let(:option_string) { "hello" }
|
21
20
|
it("exit code should be 0") { expect{ subject }.to exit_with_code(0) }
|
22
|
-
it("should execute the global action") { expect{subject}.to
|
21
|
+
it("should execute the global action") { expect{subject}.to execute_action_for_command(result, :global) }
|
23
22
|
end
|
24
23
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
describe "Escort basic app with validations", :integration => true do
|
2
|
+
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
+
|
4
|
+
context "when validation exists for non-existant option" do
|
5
|
+
let(:app_configuration) do
|
6
|
+
lambda do |app|
|
7
|
+
app.options do |opts|
|
8
|
+
opts.opt :option1, "Option 1", :short => '-o', :long => '--option1', :type => :string
|
9
|
+
opts.validate(:option2, "must be either 'foo' or 'bar'") { |option| ["foo", "bar"].include?(option) }
|
10
|
+
end
|
11
|
+
|
12
|
+
app.action do |options, arguments|
|
13
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
let(:option_string) { "-o bar" }
|
18
|
+
|
19
|
+
it("should exit with code 2") { expect{ subject }.to exit_with_code(2) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when option has a validation" do
|
23
|
+
let(:app_configuration) do
|
24
|
+
lambda do |app|
|
25
|
+
app.options do |opts|
|
26
|
+
opts.opt :option1, "Option 1", :short => '-o', :long => '--option1', :type => :string
|
27
|
+
opts.validate(:option1, "must be either 'foo' or 'bar'") { |option| ["foo", "bar"].include?(option) }
|
28
|
+
end
|
29
|
+
|
30
|
+
app.action do |options, arguments|
|
31
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "and validation fails" do
|
37
|
+
let(:option_string) { "-o baz" }
|
38
|
+
it("should exit with code 3") { expect{ subject }.to exit_with_code(3) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "and validation does not fail" do
|
42
|
+
let(:option_string) { "-o foo" }
|
43
|
+
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when option has multiple validations" do
|
48
|
+
let(:app_configuration) do
|
49
|
+
lambda do |app|
|
50
|
+
app.options do |opts|
|
51
|
+
opts.opt :option2, "Option 2", :short => :none, :long => '--option2', :type => :string
|
52
|
+
opts.validate(:option2, "must be two words") {|option| option =~ /\w\s\w/}
|
53
|
+
opts.validate(:option2, "must be at least 20 characters long") {|option| option.length >= 20}
|
54
|
+
end
|
55
|
+
|
56
|
+
app.action do |options, arguments|
|
57
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "and one validation fails" do
|
63
|
+
let(:option_string) { "--option2='hb'" }
|
64
|
+
it("should exit with code 3") { expect{ subject }.to exit_with_code(3) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "and the other validation fails" do
|
68
|
+
let(:option_string) { "--option2='h bssfs'" }
|
69
|
+
it("should exit with code 3") { expect{ subject }.to exit_with_code(3) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "and both validations pass" do
|
73
|
+
let(:option_string) { "--option2='h bssfsfsdfsdfsfsdsf'" }
|
74
|
+
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
describe "Escort basic app that requires arguments", :integration => true do
|
2
|
+
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
+
|
4
|
+
let(:app_configuration) do
|
5
|
+
lambda do |app|
|
6
|
+
app.requires_arguments
|
7
|
+
|
8
|
+
app.action do |options, arguments|
|
9
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when called with no arguments" do
|
15
|
+
let(:option_string) { "" }
|
16
|
+
|
17
|
+
before do
|
18
|
+
Readline.stub(:readline).and_return('1', nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
it("action should receive ['1'] as arguments") { expect{subject}.to execute_action_with_arguments(result, ['1']) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when called with one argument" do
|
25
|
+
let(:option_string) { "1" }
|
26
|
+
it("action should receive ['1'] as arguments") { expect{subject}.to execute_action_with_arguments(result, ['1']) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when called with three arguments" do
|
30
|
+
let(:option_string) { "1 2 3" }
|
31
|
+
it("action should receive ['1', '2', '3'] as arguments") { expect{subject}.to execute_action_with_arguments(result, ['1', '2', '3']) }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Escort basic app with version, description, and summary", :integration => true do
|
2
|
+
subject { Escort::App.create(option_string, &app_configuration) }
|
3
|
+
|
4
|
+
let(:app_configuration) do
|
5
|
+
lambda do |app|
|
6
|
+
app.version "0.1.1"
|
7
|
+
app.summary "Sum1"
|
8
|
+
app.description "Desc1"
|
9
|
+
|
10
|
+
app.action do |options, arguments|
|
11
|
+
Escort::IntegrationTestCommand.new(options, arguments).execute(result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when called" do
|
17
|
+
let(:option_string) { "" }
|
18
|
+
|
19
|
+
it("should exit with code 0") { expect{ subject }.to exit_with_code(0) }
|
20
|
+
end
|
21
|
+
end
|