cli 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -7
- data/Gemfile.lock +29 -37
- data/README.md +43 -44
- data/Rakefile +1 -28
- data/cli.gemspec +14 -84
- data/examples/httpclient +6 -6
- data/examples/ls +4 -4
- data/examples/processor +5 -5
- data/examples/sinatra +9 -9
- data/lib/cli/dsl.rb +3 -3
- data/rdoc/CLI/Arguments.html +178 -0
- data/rdoc/CLI/DSL/Argument.html +200 -0
- data/rdoc/CLI/DSL/Arguments.html +172 -0
- data/rdoc/CLI/DSL/Base.html +154 -0
- data/rdoc/CLI/DSL/Cast.html +152 -0
- data/rdoc/CLI/DSL/Description.html +150 -0
- data/rdoc/CLI/DSL/Input.html +143 -0
- data/rdoc/CLI/DSL/MultiDefault.html +151 -0
- data/rdoc/CLI/DSL/Option.html +143 -0
- data/rdoc/CLI/DSL/Options.html +142 -0
- data/rdoc/CLI/DSL/Switch.html +267 -0
- data/rdoc/CLI/DSL/Value.html +238 -0
- data/rdoc/CLI/DSL.html +91 -0
- data/rdoc/CLI/Options.html +200 -0
- data/rdoc/CLI/ParserError/ArgumentNameSpecifiedTwice.html +138 -0
- data/rdoc/CLI/ParserError/LongNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError/MultipleArgumentsSpecifierError.html +138 -0
- data/rdoc/CLI/ParserError/NameArgumetNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/OptionsArgumentNotHashError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameIsInvalidError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameNotSymbolError.html +138 -0
- data/rdoc/CLI/ParserError/ShortNameSpecifiedTwiceError.html +138 -0
- data/rdoc/CLI/ParserError.html +97 -0
- data/rdoc/CLI/ParsingError/CastError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryArgumentNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MandatoryOptionsNotSpecifiedError.html +138 -0
- data/rdoc/CLI/ParsingError/MissingOptionValueError.html +138 -0
- data/rdoc/CLI/ParsingError/UnknownSwitchError.html +138 -0
- data/rdoc/CLI/ParsingError/UsageError.html +97 -0
- data/rdoc/CLI/ParsingError.html +97 -0
- data/rdoc/CLI/Switches.html +306 -0
- data/rdoc/CLI/Values.html +202 -0
- data/rdoc/CLI.html +652 -0
- data/rdoc/README_md.html +553 -0
- data/rdoc/created.rid +7 -0
- data/rdoc/css/fonts.css +167 -0
- data/rdoc/css/rdoc.css +639 -0
- data/rdoc/fonts/Lato-Light.ttf +0 -0
- data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc/fonts/Lato-Regular.ttf +0 -0
- data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +120 -0
- data/rdoc/js/darkfish.js +84 -0
- data/rdoc/js/navigation.js +105 -0
- data/rdoc/js/navigation.js.gz +0 -0
- data/rdoc/js/search.js +110 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/search_index.js.gz +0 -0
- data/rdoc/js/searcher.js +229 -0
- data/rdoc/js/searcher.js.gz +0 -0
- data/rdoc/table_of_contents.html +533 -0
- data/spec/argument_spec.rb +122 -99
- data/spec/cli_spec.rb +27 -28
- data/spec/conflict_reporting_spec.rb +16 -17
- data/spec/option_spec.rb +79 -56
- data/spec/separator_spec.rb +19 -20
- data/spec/stdin_spec.rb +13 -14
- data/spec/switch_spec.rb +15 -16
- data/spec/usage_spec.rb +80 -81
- metadata +91 -104
- data/.document +0 -5
- data/.rspec +0 -1
- data/VERSION +0 -1
- data/features/cli.feature +0 -9
- data/features/step_definitions/cli_steps.rb +0 -0
- data/features/support/env.rb +0 -13
data/spec/argument_spec.rb
CHANGED
@@ -6,73 +6,97 @@ describe CLI do
|
|
6
6
|
ps = CLI.new do
|
7
7
|
argument :log
|
8
8
|
end.parse(['/tmp'])
|
9
|
-
|
10
|
-
|
9
|
+
expect(ps.log).to be_a String
|
10
|
+
expect(ps.log).to eq '/tmp'
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should cast mandatory argument" do
|
14
14
|
ps = CLI.new do
|
15
15
|
argument :log, :cast => Pathname
|
16
16
|
end.parse(['/tmp'])
|
17
|
-
|
18
|
-
|
17
|
+
expect(ps.log).to be_a Pathname
|
18
|
+
expect(ps.log.to_s).to eq '/tmp'
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should cast mandatory argument to numerical class" do
|
22
22
|
ps = CLI.new do
|
23
23
|
argument :number, :cast => Integer
|
24
24
|
end.parse(['123'])
|
25
|
-
|
26
|
-
|
25
|
+
expect(ps.number).to be_a Integer
|
26
|
+
expect(ps.number).to eq 123
|
27
27
|
|
28
28
|
ps = CLI.new do
|
29
29
|
argument :number, :cast => Float
|
30
30
|
end.parse(['123'])
|
31
|
-
|
32
|
-
|
31
|
+
expect(ps.number).to be_a Float
|
32
|
+
expect(ps.number).to eq 123.0
|
33
|
+
end
|
34
|
+
|
35
|
+
it "casting should fail if not proper integer given" do
|
36
|
+
expect {
|
37
|
+
ps = CLI.new do
|
38
|
+
argument :size, :cast => Integer
|
39
|
+
end.parse(['24.99'])
|
40
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "casting should fail if not proper float given" do
|
44
|
+
expect {
|
45
|
+
ps = CLI.new do
|
46
|
+
argument :size, :cast => Float
|
47
|
+
end.parse(['24.99x'])
|
48
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "casting should fail if there is error in cast lambda" do
|
52
|
+
expect {
|
53
|
+
ps = CLI.new do
|
54
|
+
argument :size, :cast => lambda{|v| fail 'test'}
|
55
|
+
end.parse(['24.99x'])
|
56
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
33
57
|
end
|
34
58
|
|
35
59
|
it "should cast default value" do
|
36
60
|
ps = CLI.new do
|
37
61
|
argument :number, :cast => Integer, :default => '123'
|
38
62
|
end.parse([])
|
39
|
-
|
40
|
-
|
63
|
+
expect(ps.number).to be_a Integer
|
64
|
+
expect(ps.number).to eq 123
|
41
65
|
end
|
42
66
|
|
43
67
|
it "should cast value of multiple arguments argument" do
|
44
68
|
ps = CLI.new do
|
45
69
|
arguments :numbers, :cast => Integer
|
46
70
|
end.parse(['1', '2', '3'])
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
71
|
+
expect(ps.numbers).to be_a Array
|
72
|
+
expect(ps.numbers[0]).to be_a Integer
|
73
|
+
expect(ps.numbers[0]).to eq 1
|
74
|
+
expect(ps.numbers[1]).to be_a Integer
|
75
|
+
expect(ps.numbers[1]).to eq 2
|
76
|
+
expect(ps.numbers[2]).to be_a Integer
|
77
|
+
expect(ps.numbers[2]).to eq 3
|
54
78
|
end
|
55
79
|
|
56
80
|
it "should cast single default value of multiple arguments argument" do
|
57
81
|
ps = CLI.new do
|
58
82
|
arguments :numbers, :cast => Integer, :default => '1'
|
59
83
|
end.parse([])
|
60
|
-
|
61
|
-
|
62
|
-
|
84
|
+
expect(ps.numbers).to be_a Array
|
85
|
+
expect(ps.numbers[0]).to be_a Integer
|
86
|
+
expect(ps.numbers[0]).to eq 1
|
63
87
|
end
|
64
88
|
|
65
89
|
it "should cast default value array of multiple arguments argument" do
|
66
90
|
ps = CLI.new do
|
67
91
|
arguments :numbers, :cast => Integer, :default => ['1', '2', '3']
|
68
92
|
end.parse([])
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
93
|
+
expect(ps.numbers).to be_a Array
|
94
|
+
expect(ps.numbers[0]).to be_a Integer
|
95
|
+
expect(ps.numbers[0]).to eq 1
|
96
|
+
expect(ps.numbers[1]).to be_a Integer
|
97
|
+
expect(ps.numbers[1]).to eq 2
|
98
|
+
expect(ps.numbers[2]).to be_a Integer
|
99
|
+
expect(ps.numbers[2]).to eq 3
|
76
100
|
end
|
77
101
|
|
78
102
|
it "should handle multiple arguments" do
|
@@ -80,10 +104,10 @@ describe CLI do
|
|
80
104
|
argument :log, :cast => Pathname
|
81
105
|
argument :test
|
82
106
|
end.parse(['/tmp', 'hello'])
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
107
|
+
expect(ps.log).to be_a Pathname
|
108
|
+
expect(ps.log.to_s).to eq '/tmp'
|
109
|
+
expect(ps.test).to be_a String
|
110
|
+
expect(ps.test).to eq 'hello'
|
87
111
|
end
|
88
112
|
|
89
113
|
it "should handle multi arguments" do
|
@@ -91,63 +115,63 @@ describe CLI do
|
|
91
115
|
argument :log, :cast => Pathname
|
92
116
|
arguments :words
|
93
117
|
end.parse(['/tmp', 'hello', 'world', 'test'])
|
94
|
-
|
95
|
-
|
118
|
+
expect(ps.log).to be_a Pathname
|
119
|
+
expect(ps.log.to_s).to eq '/tmp'
|
96
120
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
121
|
+
expect(ps.words).to be_a Array
|
122
|
+
expect(ps.words[0]).to eq 'hello'
|
123
|
+
expect(ps.words[1]).to eq 'world'
|
124
|
+
expect(ps.words[2]).to eq 'test'
|
101
125
|
end
|
102
126
|
|
103
127
|
it "should raise error if not symbol and optional hash is passed" do
|
104
|
-
|
128
|
+
expect {
|
105
129
|
ps = CLI.new do
|
106
130
|
argument 'number'
|
107
131
|
end
|
108
|
-
}.
|
132
|
+
}.to raise_error CLI::ParserError::NameArgumetNotSymbolError, "argument name has to be of type Symbol, got String"
|
109
133
|
|
110
|
-
|
134
|
+
expect {
|
111
135
|
ps = CLI.new do
|
112
136
|
argument :number, :test
|
113
137
|
end
|
114
|
-
}.
|
138
|
+
}.to raise_error CLI::ParserError::OptionsArgumentNotHashError, "argument options has to be of type Hash, got Symbol"
|
115
139
|
end
|
116
140
|
|
117
141
|
it "should raise error if artument name is specified twice" do
|
118
|
-
|
142
|
+
expect {
|
119
143
|
ps = CLI.new do
|
120
144
|
argument :number
|
121
145
|
argument :number
|
122
146
|
end
|
123
|
-
}.
|
147
|
+
}.to raise_error CLI::ParserError::ArgumentNameSpecifiedTwice, "argument 'number' specified twice"
|
124
148
|
end
|
125
149
|
|
126
150
|
it "should be required by default and raise error if not given" do
|
127
|
-
|
151
|
+
expect {
|
128
152
|
ps = CLI.new do
|
129
153
|
argument :log
|
130
154
|
end.parse([])
|
131
|
-
}.
|
155
|
+
}.to raise_error CLI::ParsingError::MandatoryArgumentNotSpecifiedError, "mandatory argument 'log' not given"
|
132
156
|
end
|
133
157
|
|
134
158
|
it "should raise error if casting fail" do
|
135
159
|
require 'ip'
|
136
|
-
|
160
|
+
expect {
|
137
161
|
ps = CLI.new do
|
138
162
|
argument :log, :cast => IP
|
139
163
|
end.parse(['abc'])
|
140
|
-
}.
|
164
|
+
}.to raise_error CLI::ParsingError::CastError, "failed to cast: 'log' to type: IP: invalid address"
|
141
165
|
end
|
142
166
|
|
143
167
|
it "should raise error if multiple artuments argument defined twice" do
|
144
|
-
|
168
|
+
expect {
|
145
169
|
ps = CLI.new do
|
146
170
|
arguments :test1
|
147
171
|
argument :test2
|
148
172
|
arguments :test3
|
149
173
|
end
|
150
|
-
}.
|
174
|
+
}.to raise_error CLI::ParserError::MultipleArgumentsSpecifierError, "only one 'arguments' specifier can be used, got: test1, test3"
|
151
175
|
end
|
152
176
|
|
153
177
|
describe "with defaults" do
|
@@ -159,11 +183,11 @@ describe CLI do
|
|
159
183
|
argument :test4, :default => 'd'
|
160
184
|
argument :test5, :default => 'e'
|
161
185
|
end.parse(['a', 'b'])
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
186
|
+
expect(ps.test1).to eq 'a'
|
187
|
+
expect(ps.test2).to eq 'b'
|
188
|
+
expect(ps.test3).to eq 'c'
|
189
|
+
expect(ps.test4).to eq 'd'
|
190
|
+
expect(ps.test5).to eq 'e'
|
167
191
|
|
168
192
|
ps = CLI.new do
|
169
193
|
argument :log, :cast => Pathname
|
@@ -171,10 +195,10 @@ describe CLI do
|
|
171
195
|
argument :test
|
172
196
|
argument :code, :cast => Integer, :default => '123'
|
173
197
|
end.parse(['/tmp', 'hello', 'world'])
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
198
|
+
expect(ps.log.to_s).to eq '/tmp'
|
199
|
+
expect(ps.magick).to eq 'hello'
|
200
|
+
expect(ps.test).to eq 'world'
|
201
|
+
expect(ps.code).to eq 123
|
178
202
|
end
|
179
203
|
|
180
204
|
it "should fill multiple argumets argument with remaining arguments after filling mandatory and default arguments" do
|
@@ -187,12 +211,12 @@ describe CLI do
|
|
187
211
|
argument :code, :cast => Integer, :default => '123'
|
188
212
|
end.parse(['/tmp', 'number', 'test', 'hello', 'world', 'abc', 'test2', '42'])
|
189
213
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
214
|
+
expect(ps.log.to_s).to eq '/tmp'
|
215
|
+
expect(ps.magick).to eq 'number'
|
216
|
+
expect(ps.test).to eq 'test'
|
217
|
+
expect(ps.words).to eq ['hello', 'world', 'abc']
|
218
|
+
expect(ps.test2).to eq 'test2'
|
219
|
+
expect(ps.code).to eq 42
|
196
220
|
end
|
197
221
|
|
198
222
|
it "should use default single value for multiple arguments argument when not enought arguments given" do
|
@@ -205,12 +229,12 @@ describe CLI do
|
|
205
229
|
argument :code, :cast => Integer, :default => '123'
|
206
230
|
end.parse(['/tmp', 'test', 'test2'])
|
207
231
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
232
|
+
expect(ps.log.to_s).to eq '/tmp'
|
233
|
+
expect(ps.magick).to eq 'word'
|
234
|
+
expect(ps.test).to eq 'test'
|
235
|
+
expect(ps.words).to eq ['hello']
|
236
|
+
expect(ps.test2).to eq 'test2'
|
237
|
+
expect(ps.code).to eq 123
|
214
238
|
end
|
215
239
|
|
216
240
|
it "should use default array of values for multiple arguments argument when not enought arguments given" do
|
@@ -223,12 +247,12 @@ describe CLI do
|
|
223
247
|
argument :code, :cast => Integer, :default => '123'
|
224
248
|
end.parse(['/tmp', 'test', 'test2'])
|
225
249
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
250
|
+
expect(ps.log.to_s).to eq '/tmp'
|
251
|
+
expect(ps.magick).to eq 'word'
|
252
|
+
expect(ps.test).to eq 'test'
|
253
|
+
expect(ps.words).to eq ['hello', 'world', 'abc']
|
254
|
+
expect(ps.test2).to eq 'test2'
|
255
|
+
expect(ps.code).to eq 123
|
232
256
|
end
|
233
257
|
|
234
258
|
it "should fill at least one value of required multiple arguments argument" do
|
@@ -239,11 +263,11 @@ describe CLI do
|
|
239
263
|
argument :test4, :default => 'd'
|
240
264
|
argument :test5, :default => 'e'
|
241
265
|
end.parse(['a', 'c'])
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
266
|
+
expect(ps.test1).to eq 'a'
|
267
|
+
expect(ps.test2).to eq 'b'
|
268
|
+
expect(ps.test3).to eq ['c']
|
269
|
+
expect(ps.test4).to eq 'd'
|
270
|
+
expect(ps.test5).to eq 'e'
|
247
271
|
end
|
248
272
|
end
|
249
273
|
|
@@ -256,19 +280,19 @@ describe CLI do
|
|
256
280
|
argument :test4, :required => false
|
257
281
|
argument :test5, :required => false
|
258
282
|
end.parse(['a', 'b'])
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
283
|
+
expect(ps.test1).to eq 'a'
|
284
|
+
expect(ps.test2).to eq 'b'
|
285
|
+
expect(ps.test3).to be_nil
|
286
|
+
expect(ps.test4).to be_nil
|
287
|
+
expect(ps.test5).to be_nil
|
264
288
|
|
265
289
|
ps = CLI.new do
|
266
290
|
argument :log, :cast => Pathname
|
267
291
|
argument :test, :required => false
|
268
292
|
end.parse(['/tmp'])
|
269
|
-
|
270
|
-
|
271
|
-
|
293
|
+
expect(ps.log).to be_a Pathname
|
294
|
+
expect(ps.log.to_s).to eq '/tmp'
|
295
|
+
expect(ps.test).to be_nil
|
272
296
|
end
|
273
297
|
|
274
298
|
it "should use empty array for multiple arguments argument when not enought arguments given and it is not required" do
|
@@ -277,9 +301,9 @@ describe CLI do
|
|
277
301
|
argument :test2, :required => false
|
278
302
|
arguments :test3, :required => false
|
279
303
|
end.parse(['a', 'b'])
|
280
|
-
|
281
|
-
|
282
|
-
|
304
|
+
expect(ps.test1).to eq 'a'
|
305
|
+
expect(ps.test2).to eq 'b'
|
306
|
+
expect(ps.test3).to eq []
|
283
307
|
|
284
308
|
ps = CLI.new do
|
285
309
|
argument :log, :cast => Pathname
|
@@ -290,14 +314,13 @@ describe CLI do
|
|
290
314
|
argument :code, :cast => Integer, :default => '123'
|
291
315
|
end.parse(['/tmp', 'test', 'test2'])
|
292
316
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
317
|
+
expect(ps.log.to_s).to eq '/tmp'
|
318
|
+
expect(ps.magick).to eq 'word'
|
319
|
+
expect(ps.test).to eq 'test'
|
320
|
+
expect(ps.words).to eq []
|
321
|
+
expect(ps.test2).to eq 'test2'
|
322
|
+
expect(ps.code).to eq 123
|
299
323
|
end
|
300
324
|
end
|
301
325
|
end
|
302
326
|
end
|
303
|
-
|
data/spec/cli_spec.rb
CHANGED
@@ -16,20 +16,20 @@ describe CLI do
|
|
16
16
|
argument :code, :cast => Integer, :default => '123'
|
17
17
|
end.parse(['-l', 'singapore', '--power-up', 'yes', '-s', '24', '--debug', '--size', 'XXXL', '/tmp', 'hello'])
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
expect(ps.group).to eq 'red'
|
20
|
+
expect(ps.power_up).to eq 'yes'
|
21
|
+
expect(ps.speed).to eq 24
|
22
|
+
expect(ps.size).to eq 'XXXL'
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
expect(ps.log.to_s).to eq '/tmp'
|
25
|
+
expect(ps.magick).to eq 'word'
|
26
|
+
expect(ps.test).to eq 'hello'
|
27
|
+
expect(ps.code).to eq 123
|
28
|
+
expect(ps.debug).to be true
|
29
29
|
end
|
30
30
|
|
31
31
|
it "provides name method that provides current program name" do
|
32
|
-
|
32
|
+
expect(CLI.name).to eq 'rspec'
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "parse!" do
|
@@ -40,9 +40,9 @@ describe CLI do
|
|
40
40
|
argument :code
|
41
41
|
end.parse!(['-l', 'singapore', '--debug', 'hello'])
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
expect(ps.location).to eq 'singapore'
|
44
|
+
expect(ps.debug).to be true
|
45
|
+
expect(ps.code).to eq 'hello'
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return value structure where all values are set" do
|
@@ -51,15 +51,15 @@ describe CLI do
|
|
51
51
|
switch :debug
|
52
52
|
end.parse!([]).marshal_dump
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
expect(h.member?(:location)).to be true
|
55
|
+
expect(h[:location]).to be_nil
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
expect(h.member?(:debug)).to be true
|
58
|
+
expect(h[:debug]).to be_nil
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should take a block that can be used to verify passed values" do
|
62
|
-
|
62
|
+
expect {
|
63
63
|
ps = CLI.new do
|
64
64
|
option :location, :short => :l
|
65
65
|
switch :debug
|
@@ -68,10 +68,10 @@ describe CLI do
|
|
68
68
|
end.parse!(['-l', 'singapore', '--debug', 'hello']) do |values|
|
69
69
|
fail '--debug can not be used with --verbose' if values.debug and values.verbose
|
70
70
|
end
|
71
|
-
}.
|
71
|
+
}.not_to raise_error
|
72
72
|
|
73
73
|
out = stderr_read do
|
74
|
-
|
74
|
+
expect {
|
75
75
|
ps = CLI.new do
|
76
76
|
option :location, :short => :l
|
77
77
|
switch :debug
|
@@ -80,23 +80,22 @@ describe CLI do
|
|
80
80
|
end.parse!(['-l', 'singapore', '--debug', '--verbose', 'hello']) do |values|
|
81
81
|
fail '--debug can not be used with --verbose' if values.debug and values.verbose
|
82
82
|
end
|
83
|
-
}.
|
83
|
+
}.to raise_error SystemExit
|
84
84
|
end
|
85
|
-
out.
|
86
|
-
out.
|
85
|
+
expect(out).to include('Error: --debug can not be used with --verbose')
|
86
|
+
expect(out).to include('Usage:')
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should exit displaying usage and error message on standard error on usage error" do
|
90
90
|
out = stderr_read do
|
91
|
-
|
91
|
+
expect {
|
92
92
|
ps = CLI.new do
|
93
93
|
option :weight, :required => true
|
94
94
|
end.parse!([])
|
95
|
-
}.
|
95
|
+
}.to raise_error SystemExit
|
96
96
|
end
|
97
|
-
|
98
|
-
|
97
|
+
expect(out).to include('Error: mandatory options not specified: --weight')
|
98
|
+
expect(out).to include('Usage:')
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
@@ -4,66 +4,65 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
4
4
|
describe CLI do
|
5
5
|
describe "name conflict reporting" do
|
6
6
|
it "raise error when long names configlict" do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
ps = CLI.new do
|
9
9
|
switch :location
|
10
10
|
switch :location
|
11
11
|
end
|
12
|
-
}.
|
12
|
+
}.to raise_error CLI::ParserError::LongNameSpecifiedTwiceError, 'switch --location specified twice'
|
13
13
|
|
14
|
-
|
14
|
+
expect {
|
15
15
|
ps = CLI.new do
|
16
16
|
option :location
|
17
17
|
option :location
|
18
18
|
end
|
19
|
-
}.
|
19
|
+
}.to raise_error CLI::ParserError::LongNameSpecifiedTwiceError, 'option --location specified twice'
|
20
20
|
|
21
|
-
|
21
|
+
expect {
|
22
22
|
ps = CLI.new do
|
23
23
|
switch :location
|
24
24
|
option :location
|
25
25
|
end
|
26
|
-
}.
|
26
|
+
}.to raise_error CLI::ParserError::LongNameSpecifiedTwiceError, 'switch and option --location specified twice'
|
27
27
|
|
28
|
-
|
28
|
+
expect {
|
29
29
|
ps = CLI.new do
|
30
30
|
option :location
|
31
31
|
switch :location
|
32
32
|
end
|
33
|
-
}.
|
33
|
+
}.to raise_error CLI::ParserError::LongNameSpecifiedTwiceError, 'option and switch --location specified twice'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "short name conflict reporting" do
|
38
38
|
it "raise error when short names configlict" do
|
39
|
-
|
39
|
+
expect {
|
40
40
|
ps = CLI.new do
|
41
41
|
switch :location, :short => :l
|
42
42
|
switch :location2, :short => :l
|
43
43
|
end
|
44
|
-
}.
|
44
|
+
}.to raise_error CLI::ParserError::ShortNameSpecifiedTwiceError, 'short switch -l specified twice'
|
45
45
|
|
46
|
-
|
46
|
+
expect {
|
47
47
|
ps = CLI.new do
|
48
48
|
option :location, :short => :l
|
49
49
|
option :location2, :short => :l
|
50
50
|
end
|
51
|
-
}.
|
51
|
+
}.to raise_error CLI::ParserError::ShortNameSpecifiedTwiceError, 'short option -l specified twice'
|
52
52
|
|
53
|
-
|
53
|
+
expect {
|
54
54
|
ps = CLI.new do
|
55
55
|
switch :location, :short => :l
|
56
56
|
option :location2, :short => :l
|
57
57
|
end
|
58
|
-
}.
|
58
|
+
}.to raise_error CLI::ParserError::ShortNameSpecifiedTwiceError, 'short switch and option -l specified twice'
|
59
59
|
|
60
|
-
|
60
|
+
expect {
|
61
61
|
ps = CLI.new do
|
62
62
|
option :location2, :short => :l
|
63
63
|
switch :location, :short => :l
|
64
64
|
end
|
65
|
-
}.
|
65
|
+
}.to raise_error CLI::ParserError::ShortNameSpecifiedTwiceError, 'short option and switch -l specified twice'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|