cli 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -7
- data/Gemfile.lock +29 -37
- data/README.md +17 -18
- data/Rakefile +1 -28
- data/cli.gemspec +14 -84
- 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 +104 -105
- data/spec/cli_spec.rb +27 -28
- data/spec/conflict_reporting_spec.rb +16 -17
- data/spec/option_spec.rb +60 -61
- 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 -139
- 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,97 +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
33
|
end
|
34
34
|
|
35
35
|
it "casting should fail if not proper integer given" do
|
36
|
-
|
36
|
+
expect {
|
37
37
|
ps = CLI.new do
|
38
38
|
argument :size, :cast => Integer
|
39
39
|
end.parse(['24.99'])
|
40
|
-
}.
|
40
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "casting should fail if not proper float given" do
|
44
|
-
|
44
|
+
expect {
|
45
45
|
ps = CLI.new do
|
46
46
|
argument :size, :cast => Float
|
47
47
|
end.parse(['24.99x'])
|
48
|
-
}.
|
48
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "casting should fail if there is error in cast lambda" do
|
52
|
-
|
52
|
+
expect {
|
53
53
|
ps = CLI.new do
|
54
54
|
argument :size, :cast => lambda{|v| fail 'test'}
|
55
55
|
end.parse(['24.99x'])
|
56
|
-
}.
|
56
|
+
}.to raise_error(CLI::ParsingError::CastError)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should cast default value" do
|
60
60
|
ps = CLI.new do
|
61
61
|
argument :number, :cast => Integer, :default => '123'
|
62
62
|
end.parse([])
|
63
|
-
|
64
|
-
|
63
|
+
expect(ps.number).to be_a Integer
|
64
|
+
expect(ps.number).to eq 123
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should cast value of multiple arguments argument" do
|
68
68
|
ps = CLI.new do
|
69
69
|
arguments :numbers, :cast => Integer
|
70
70
|
end.parse(['1', '2', '3'])
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should cast single default value of multiple arguments argument" do
|
81
81
|
ps = CLI.new do
|
82
82
|
arguments :numbers, :cast => Integer, :default => '1'
|
83
83
|
end.parse([])
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should cast default value array of multiple arguments argument" do
|
90
90
|
ps = CLI.new do
|
91
91
|
arguments :numbers, :cast => Integer, :default => ['1', '2', '3']
|
92
92
|
end.parse([])
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should handle multiple arguments" do
|
@@ -104,10 +104,10 @@ describe CLI do
|
|
104
104
|
argument :log, :cast => Pathname
|
105
105
|
argument :test
|
106
106
|
end.parse(['/tmp', 'hello'])
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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'
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should handle multi arguments" do
|
@@ -115,63 +115,63 @@ describe CLI do
|
|
115
115
|
argument :log, :cast => Pathname
|
116
116
|
arguments :words
|
117
117
|
end.parse(['/tmp', 'hello', 'world', 'test'])
|
118
|
-
|
119
|
-
|
118
|
+
expect(ps.log).to be_a Pathname
|
119
|
+
expect(ps.log.to_s).to eq '/tmp'
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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'
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should raise error if not symbol and optional hash is passed" do
|
128
|
-
|
128
|
+
expect {
|
129
129
|
ps = CLI.new do
|
130
130
|
argument 'number'
|
131
131
|
end
|
132
|
-
}.
|
132
|
+
}.to raise_error CLI::ParserError::NameArgumetNotSymbolError, "argument name has to be of type Symbol, got String"
|
133
133
|
|
134
|
-
|
134
|
+
expect {
|
135
135
|
ps = CLI.new do
|
136
136
|
argument :number, :test
|
137
137
|
end
|
138
|
-
}.
|
138
|
+
}.to raise_error CLI::ParserError::OptionsArgumentNotHashError, "argument options has to be of type Hash, got Symbol"
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should raise error if artument name is specified twice" do
|
142
|
-
|
142
|
+
expect {
|
143
143
|
ps = CLI.new do
|
144
144
|
argument :number
|
145
145
|
argument :number
|
146
146
|
end
|
147
|
-
}.
|
147
|
+
}.to raise_error CLI::ParserError::ArgumentNameSpecifiedTwice, "argument 'number' specified twice"
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should be required by default and raise error if not given" do
|
151
|
-
|
151
|
+
expect {
|
152
152
|
ps = CLI.new do
|
153
153
|
argument :log
|
154
154
|
end.parse([])
|
155
|
-
}.
|
155
|
+
}.to raise_error CLI::ParsingError::MandatoryArgumentNotSpecifiedError, "mandatory argument 'log' not given"
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should raise error if casting fail" do
|
159
159
|
require 'ip'
|
160
|
-
|
160
|
+
expect {
|
161
161
|
ps = CLI.new do
|
162
162
|
argument :log, :cast => IP
|
163
163
|
end.parse(['abc'])
|
164
|
-
}.
|
164
|
+
}.to raise_error CLI::ParsingError::CastError, "failed to cast: 'log' to type: IP: invalid address"
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should raise error if multiple artuments argument defined twice" do
|
168
|
-
|
168
|
+
expect {
|
169
169
|
ps = CLI.new do
|
170
170
|
arguments :test1
|
171
171
|
argument :test2
|
172
172
|
arguments :test3
|
173
173
|
end
|
174
|
-
}.
|
174
|
+
}.to raise_error CLI::ParserError::MultipleArgumentsSpecifierError, "only one 'arguments' specifier can be used, got: test1, test3"
|
175
175
|
end
|
176
176
|
|
177
177
|
describe "with defaults" do
|
@@ -183,11 +183,11 @@ describe CLI do
|
|
183
183
|
argument :test4, :default => 'd'
|
184
184
|
argument :test5, :default => 'e'
|
185
185
|
end.parse(['a', 'b'])
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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'
|
191
191
|
|
192
192
|
ps = CLI.new do
|
193
193
|
argument :log, :cast => Pathname
|
@@ -195,10 +195,10 @@ describe CLI do
|
|
195
195
|
argument :test
|
196
196
|
argument :code, :cast => Integer, :default => '123'
|
197
197
|
end.parse(['/tmp', 'hello', 'world'])
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
202
202
|
end
|
203
203
|
|
204
204
|
it "should fill multiple argumets argument with remaining arguments after filling mandatory and default arguments" do
|
@@ -211,12 +211,12 @@ describe CLI do
|
|
211
211
|
argument :code, :cast => Integer, :default => '123'
|
212
212
|
end.parse(['/tmp', 'number', 'test', 'hello', 'world', 'abc', 'test2', '42'])
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should use default single value for multiple arguments argument when not enought arguments given" do
|
@@ -229,12 +229,12 @@ describe CLI do
|
|
229
229
|
argument :code, :cast => Integer, :default => '123'
|
230
230
|
end.parse(['/tmp', 'test', 'test2'])
|
231
231
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should use default array of values for multiple arguments argument when not enought arguments given" do
|
@@ -247,12 +247,12 @@ describe CLI do
|
|
247
247
|
argument :code, :cast => Integer, :default => '123'
|
248
248
|
end.parse(['/tmp', 'test', 'test2'])
|
249
249
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
256
256
|
end
|
257
257
|
|
258
258
|
it "should fill at least one value of required multiple arguments argument" do
|
@@ -263,11 +263,11 @@ describe CLI do
|
|
263
263
|
argument :test4, :default => 'd'
|
264
264
|
argument :test5, :default => 'e'
|
265
265
|
end.parse(['a', 'c'])
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
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'
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
@@ -280,19 +280,19 @@ describe CLI do
|
|
280
280
|
argument :test4, :required => false
|
281
281
|
argument :test5, :required => false
|
282
282
|
end.parse(['a', 'b'])
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
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
|
288
288
|
|
289
289
|
ps = CLI.new do
|
290
290
|
argument :log, :cast => Pathname
|
291
291
|
argument :test, :required => false
|
292
292
|
end.parse(['/tmp'])
|
293
|
-
|
294
|
-
|
295
|
-
|
293
|
+
expect(ps.log).to be_a Pathname
|
294
|
+
expect(ps.log.to_s).to eq '/tmp'
|
295
|
+
expect(ps.test).to be_nil
|
296
296
|
end
|
297
297
|
|
298
298
|
it "should use empty array for multiple arguments argument when not enought arguments given and it is not required" do
|
@@ -301,9 +301,9 @@ describe CLI do
|
|
301
301
|
argument :test2, :required => false
|
302
302
|
arguments :test3, :required => false
|
303
303
|
end.parse(['a', 'b'])
|
304
|
-
|
305
|
-
|
306
|
-
|
304
|
+
expect(ps.test1).to eq 'a'
|
305
|
+
expect(ps.test2).to eq 'b'
|
306
|
+
expect(ps.test3).to eq []
|
307
307
|
|
308
308
|
ps = CLI.new do
|
309
309
|
argument :log, :cast => Pathname
|
@@ -314,14 +314,13 @@ describe CLI do
|
|
314
314
|
argument :code, :cast => Integer, :default => '123'
|
315
315
|
end.parse(['/tmp', 'test', 'test2'])
|
316
316
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
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
|
323
323
|
end
|
324
324
|
end
|
325
325
|
end
|
326
326
|
end
|
327
|
-
|
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
|
-
|