cft_smartcloud 0.2.2 → 0.3.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.
- data/.gitignore +1 -0
- data/CHANGELOG +11 -0
- data/README.md +106 -0
- data/VERSION +1 -1
- data/bin/cft_smartcloud +33 -7
- data/bin/smartcloud +33 -7
- data/cft_smartcloud.gemspec +84 -20
- data/lib/config/config.yml +2 -0
- data/lib/curl_client.rb +42 -0
- data/lib/rest-client-1.6.6-master/.gitignore +6 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/README.rdoc +10 -1
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/Rakefile +0 -0
- data/lib/rest-client-1.6.6-master/VERSION +1 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/bin/restclient +5 -4
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/history.md +22 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest-client.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest_client.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/abstract_response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/exceptions.rb +0 -0
- data/lib/rest-client-1.6.6-master/lib/restclient/net_http_ext.rb +55 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/payload.rb +17 -2
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/raw_response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/request.rb +21 -19
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/resource.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/response.rb +0 -0
- data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient.rb +0 -0
- data/lib/rest-client-1.6.6-master/rest-client.gemspec +76 -0
- data/lib/rest-client-1.6.6-master/spec/abstract_response_spec.rb +85 -0
- data/lib/rest-client-1.6.6-master/spec/base.rb +16 -0
- data/lib/rest-client-1.6.6-master/spec/exceptions_spec.rb +98 -0
- data/lib/rest-client-1.6.6-master/spec/integration/certs/equifax.crt +19 -0
- data/lib/rest-client-1.6.6-master/spec/integration/certs/verisign.crt +14 -0
- data/lib/rest-client-1.6.6-master/spec/integration/request_spec.rb +25 -0
- data/lib/rest-client-1.6.6-master/spec/integration_spec.rb +38 -0
- data/lib/rest-client-1.6.6-master/spec/master_shake.jpg +0 -0
- data/lib/rest-client-1.6.6-master/spec/payload_spec.rb +234 -0
- data/lib/rest-client-1.6.6-master/spec/raw_response_spec.rb +17 -0
- data/lib/rest-client-1.6.6-master/spec/request2_spec.rb +40 -0
- data/lib/rest-client-1.6.6-master/spec/request_spec.rb +536 -0
- data/lib/rest-client-1.6.6-master/spec/resource_spec.rb +134 -0
- data/lib/rest-client-1.6.6-master/spec/response_spec.rb +169 -0
- data/lib/rest-client-1.6.6-master/spec/restclient_spec.rb +73 -0
- data/lib/slop-2.3.1/.gemtest +0 -0
- data/lib/slop-2.3.1/.gitignore +6 -0
- data/lib/slop-2.3.1/.yardopts +6 -0
- data/lib/slop-2.3.1/CHANGES.md +137 -0
- data/lib/slop-2.3.1/LICENSE +20 -0
- data/lib/slop-2.3.1/README.md +293 -0
- data/lib/slop-2.3.1/Rakefile +6 -0
- data/lib/slop-2.3.1/lib/slop.rb +1022 -0
- data/lib/slop-2.3.1/slop.gemspec +11 -0
- data/lib/slop-2.3.1/test/commands_test.rb +151 -0
- data/lib/slop-2.3.1/test/helper.rb +13 -0
- data/lib/slop-2.3.1/test/option_test.rb +198 -0
- data/lib/slop-2.3.1/test/slop_test.rb +574 -0
- data/lib/smartcloud.rb +186 -116
- data/lib/terminal-table-1.4.4/History.rdoc +53 -0
- data/lib/terminal-table-1.4.4/Manifest +24 -0
- data/lib/terminal-table-1.4.4/README.rdoc +240 -0
- data/lib/terminal-table-1.4.4/Rakefile +15 -0
- data/lib/terminal-table-1.4.4/Todo.rdoc +14 -0
- data/lib/terminal-table-1.4.4/examples/examples.rb +80 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/cell.rb +88 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/core_ext.rb +8 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/import.rb +4 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/row.rb +48 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/separator.rb +14 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/style.rb +61 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/table.rb +217 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/table_helper.rb +9 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table/version.rb +6 -0
- data/lib/terminal-table-1.4.4/lib/terminal-table.rb +27 -0
- data/lib/terminal-table-1.4.4/spec/cell_spec.rb +54 -0
- data/lib/terminal-table-1.4.4/spec/core_ext_spec.rb +18 -0
- data/lib/terminal-table-1.4.4/spec/import_spec.rb +11 -0
- data/lib/terminal-table-1.4.4/spec/spec.opts +1 -0
- data/lib/terminal-table-1.4.4/spec/spec_helper.rb +8 -0
- data/lib/terminal-table-1.4.4/spec/table_spec.rb +525 -0
- data/lib/terminal-table-1.4.4/tasks/docs.rake +13 -0
- data/lib/terminal-table-1.4.4/tasks/gemspec.rake +3 -0
- data/lib/terminal-table-1.4.4/tasks/spec.rake +25 -0
- data/lib/terminal-table-1.4.4/terminal-table.gemspec +30 -0
- data/responses/addresses +26 -0
- data/responses/addresses.blank +2 -0
- data/responses/instances +74 -0
- data/responses/keys +33 -0
- data/responses/locations +142 -0
- data/responses/offerings_image +3780 -0
- data/responses/storage +379 -0
- metadata +86 -22
- data/README.rdoc +0 -75
- data/lib/rest-client-1.6.3/VERSION +0 -1
- data/lib/rest-client-1.6.3/lib/restclient/net_http_ext.rb +0 -21
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class SlopTest < TestCase
|
|
4
|
+
def clean_options(*args)
|
|
5
|
+
Slop.new.send(:clean_options, args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def temp_argv(items)
|
|
9
|
+
old_argv = ARGV.clone
|
|
10
|
+
ARGV.replace items
|
|
11
|
+
yield
|
|
12
|
+
ensure
|
|
13
|
+
ARGV.replace old_argv
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'includes Enumerable' do
|
|
17
|
+
assert Slop.included_modules.include?(Enumerable)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'new accepts a hash or array of symbols' do
|
|
21
|
+
slop = Slop.new :strict, :multiple_switches => true
|
|
22
|
+
[ :@multiple_switches, :@strict ].each do |var|
|
|
23
|
+
assert slop.instance_variable_get var
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'parse returns a Slop object' do
|
|
28
|
+
slop = Slop.parse([])
|
|
29
|
+
assert_kind_of Slop, slop
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'parsing calls to_s on all of the items in the array' do
|
|
33
|
+
opts = Slop.parse([:'--foo']) { on :foo }
|
|
34
|
+
assert opts.foo?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test '#opt returns an Slop::Option' do
|
|
38
|
+
assert_kind_of Slop::Option, Slop.new.option(:n)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'enumerating options' do
|
|
42
|
+
slop = Slop.new
|
|
43
|
+
slop.opt(:f, :foo, 'foo')
|
|
44
|
+
slop.opt(:b, :bar, 'bar')
|
|
45
|
+
|
|
46
|
+
slop.each { |option| assert_kind_of Slop::Option, option }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'defaulting to ARGV' do
|
|
50
|
+
temp_argv(%w/--name lee/) do
|
|
51
|
+
assert_equal('lee', Slop.parse { on :name, true }[:name])
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'callback when option array is empty' do
|
|
56
|
+
item1 = nil
|
|
57
|
+
temp_argv([]) do
|
|
58
|
+
Slop.new { on_empty { item1 = 'foo' } }.parse
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
assert_equal 'foo', item1
|
|
62
|
+
|
|
63
|
+
temp_argv([]) do
|
|
64
|
+
assert_equal [], Slop.new { on_empty {} }.parse
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
test 'callback when arguments contain no options' do
|
|
69
|
+
item = nil
|
|
70
|
+
Slop.new { on_optionless { item = 'foo' } }.parse %w/a b c/
|
|
71
|
+
assert_equal 'foo', item
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'multiple switches with the :multiple_switches flag' do
|
|
75
|
+
slop = Slop.new :multiple_switches => true, :strict => true
|
|
76
|
+
%w/a b c/.each { |f| slop.on f }
|
|
77
|
+
slop.on :z, true
|
|
78
|
+
slop.parse %w/-abc/
|
|
79
|
+
|
|
80
|
+
%w/a b c/.each do |flag|
|
|
81
|
+
assert slop[flag]
|
|
82
|
+
assert slop.send(flag + '?')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
assert_raises(Slop::InvalidOptionError, /d/) { slop.parse %w/-abcd/ }
|
|
86
|
+
assert_raises(Slop::MissingArgumentError, /z/) { slop.parse %w/-abcz/ }
|
|
87
|
+
|
|
88
|
+
slop = Slop.new(:multiple_switches)
|
|
89
|
+
slop.on :a
|
|
90
|
+
slop.on :f, true
|
|
91
|
+
args = %w[-abc -f foo bar]
|
|
92
|
+
slop.parse! args
|
|
93
|
+
|
|
94
|
+
assert_equal %w[ bar ], args
|
|
95
|
+
assert_equal 'foo', slop[:f]
|
|
96
|
+
assert slop[:a]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
test 'passing a block' do
|
|
100
|
+
assert Slop.new {}
|
|
101
|
+
slop = nil
|
|
102
|
+
assert Slop.new {|s| slop = s }
|
|
103
|
+
assert_kind_of Slop, slop
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
test 'automatically adding the help option' do
|
|
107
|
+
slop = Slop.new
|
|
108
|
+
assert_empty slop.options
|
|
109
|
+
|
|
110
|
+
slop = Slop.new :help => true
|
|
111
|
+
refute_empty slop.options
|
|
112
|
+
assert_equal 'Print this help message', slop.options[:help].description
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
test ':all_accept_arguments' do
|
|
116
|
+
opts = Slop.new(:all_accept_arguments) do
|
|
117
|
+
on :foo
|
|
118
|
+
on :bar, :optional => true
|
|
119
|
+
end
|
|
120
|
+
opts.parse %w[ --foo hello --bar ]
|
|
121
|
+
|
|
122
|
+
assert_equal 'hello', opts[:foo]
|
|
123
|
+
assert_nil opts[:bar]
|
|
124
|
+
assert_raises(Slop::MissingArgumentError) { opts.parse %w[ --foo --bar ] }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
test 'yielding non-options when a block is passed to "parse"' do
|
|
128
|
+
opts = Slop.new do
|
|
129
|
+
on :name, true
|
|
130
|
+
end
|
|
131
|
+
opts.parse(%w/--name lee a/) do |v|
|
|
132
|
+
assert_equal 'a', v
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
test 'preserving order when yielding non-options' do
|
|
137
|
+
items = []
|
|
138
|
+
slop = Slop.new { on(:name, true) { |name| items << name } }
|
|
139
|
+
slop.parse(%w/foo --name bar baz/) { |value| items << value }
|
|
140
|
+
assert_equal %w/foo bar baz/, items
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
test 'only parsing options' do
|
|
144
|
+
slop = Slop.new { on :n, true }
|
|
145
|
+
assert slop.parse %w/n/
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
test 'setting the banner' do
|
|
149
|
+
slop = Slop.new
|
|
150
|
+
slop.banner = "foo bar"
|
|
151
|
+
|
|
152
|
+
assert_equal "foo bar", slop.banner
|
|
153
|
+
assert slop.to_s =~ /^foo bar/
|
|
154
|
+
|
|
155
|
+
slop.banner = nil
|
|
156
|
+
assert_equal "", slop.to_s
|
|
157
|
+
|
|
158
|
+
slop = Slop.new "foo bar"
|
|
159
|
+
assert_equal "foo bar", slop.banner
|
|
160
|
+
|
|
161
|
+
slop = Slop.new :banner => "foo bar"
|
|
162
|
+
assert_equal "foo bar", slop.banner
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
test 'setting the summary' do
|
|
166
|
+
slop = Slop.new
|
|
167
|
+
slop.banner = "foo bar"
|
|
168
|
+
slop.summary = "does stuff"
|
|
169
|
+
|
|
170
|
+
assert_equal "foo bar\n\ndoes stuff", slop.to_s
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
test 'setting the description' do
|
|
174
|
+
slop = Slop.new
|
|
175
|
+
slop.banner = "foo bar"
|
|
176
|
+
slop.summary = "does stuff"
|
|
177
|
+
slop.description = "This does stuff."
|
|
178
|
+
|
|
179
|
+
assert_equal "foo bar\n\ndoes stuff\n\n This does stuff.", slop.to_s
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
test 'setting the description without matching summary' do
|
|
183
|
+
slop = Slop.new
|
|
184
|
+
slop.banner = "foo bar"
|
|
185
|
+
slop.description = "This does stuff."
|
|
186
|
+
|
|
187
|
+
assert_equal "foo bar\n\n This does stuff.", slop.to_s
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
test 'storing long option lengths' do
|
|
191
|
+
slop = Slop.new
|
|
192
|
+
assert_equal 0, slop.longest_flag
|
|
193
|
+
slop.opt(:name)
|
|
194
|
+
assert_equal 4, slop.longest_flag
|
|
195
|
+
slop.opt(:username)
|
|
196
|
+
assert_equal 8, slop.longest_flag
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
test 'parse returning the list of arguments left after parsing' do
|
|
200
|
+
opts = Slop.new do
|
|
201
|
+
on :name, true
|
|
202
|
+
end
|
|
203
|
+
assert_equal %w/a/, opts.parse!(%w/--name lee a/)
|
|
204
|
+
assert_equal %w/--name lee a/, opts.parse(%w/--name lee a/)
|
|
205
|
+
assert_equal ['foo', :bar, 1], opts.parse(['foo', :bar, 1])
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
test '#parse does not remove parsed items' do
|
|
209
|
+
items = %w/--foo/
|
|
210
|
+
Slop.new { |opt| opt.on :foo }.parse(items)
|
|
211
|
+
assert_equal %w/--foo/, items
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
test '#parse! removes parsed items' do
|
|
215
|
+
items = %w/--foo/
|
|
216
|
+
Slop.new { |opt| opt.on :foo }.parse!(items)
|
|
217
|
+
assert_empty items
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
test '#parse! does not remove unparsed items with same value as a parsed item' do
|
|
221
|
+
items = %w/bar --foo bar/
|
|
222
|
+
Slop.new { |opt| opt.on :foo, 'foo', true }.parse!(items)
|
|
223
|
+
assert_equal %w/bar/, items
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
test '#parse! removes parsed items prefixed with --no-' do
|
|
227
|
+
items = %w/--no-foo/
|
|
228
|
+
Slop.new { |opt| opt.on :foo }.parse!(items)
|
|
229
|
+
assert_empty items
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
test 'the shit out of clean_options' do
|
|
233
|
+
assert_equal(
|
|
234
|
+
['s', 'short', 'short option', false, {}],
|
|
235
|
+
clean_options('-s', '--short', 'short option')
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
assert_equal(
|
|
239
|
+
[nil, 'long', 'long option only', true, {}],
|
|
240
|
+
clean_options('--long', 'long option only', true)
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
assert_equal(
|
|
244
|
+
['S', 'symbol', 'symbolize', false, {}],
|
|
245
|
+
clean_options(:S, :symbol, 'symbolize')
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
assert_equal(
|
|
249
|
+
['a', nil, 'alphabetical only', true, {}],
|
|
250
|
+
clean_options('a', 'alphabetical only', true)
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
assert_equal( # for description-less options
|
|
254
|
+
[nil, 'optiononly', nil, false, {}],
|
|
255
|
+
clean_options('--optiononly')
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
assert_equal(
|
|
259
|
+
['f', 'foo', 'some description', false, {:optional => false, :help => 'BAR'}],
|
|
260
|
+
clean_options(:f, 'foo BAR', 'some description')
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
assert_equal(
|
|
264
|
+
[nil, 'bar', nil, false, {:optional => true, :help => '[STUFF]'}],
|
|
265
|
+
clean_options('bar [STUFF]')
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
assert_equal([nil, 'foo', nil, false, {:as => Array}], clean_options(:foo, Array, false))
|
|
269
|
+
assert_equal([nil, 'foo', nil, false, {:as => Array}], clean_options(Array, :foo, false))
|
|
270
|
+
|
|
271
|
+
assert_equal(['c', nil, nil, true, {}], clean_options(:c, true))
|
|
272
|
+
assert_equal(['c', nil, nil, false, {}], clean_options(:c, false))
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
test '[] returns an options argument value or a command or nil (in that order)' do
|
|
276
|
+
slop = Slop.new
|
|
277
|
+
slop.opt :n, :name, true
|
|
278
|
+
slop.opt :foo
|
|
279
|
+
slop.command(:foo) { }
|
|
280
|
+
slop.command(:bar) { }
|
|
281
|
+
slop.parse %w/--name lee --foo/
|
|
282
|
+
|
|
283
|
+
assert_equal 'lee', slop[:name]
|
|
284
|
+
assert_equal 'lee', slop[:n]
|
|
285
|
+
|
|
286
|
+
assert_equal true, slop[:foo]
|
|
287
|
+
assert_kind_of Slop, slop[:bar]
|
|
288
|
+
|
|
289
|
+
assert_nil slop[:baz]
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
test 'arguments ending ? test for option existance' do
|
|
293
|
+
slop = Slop.new
|
|
294
|
+
slop.opt :v, :verbose
|
|
295
|
+
slop.opt :d, :debug
|
|
296
|
+
slop.parse %w/--verbose/
|
|
297
|
+
|
|
298
|
+
assert slop[:verbose]
|
|
299
|
+
assert slop.verbose?
|
|
300
|
+
|
|
301
|
+
refute slop[:debug]
|
|
302
|
+
refute slop.debug?
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
test 'options are present' do
|
|
306
|
+
opts = Slop.new do
|
|
307
|
+
on :f, 'foo-bar'
|
|
308
|
+
on :b, 'bar-baz'
|
|
309
|
+
on :h, :optional => true
|
|
310
|
+
end
|
|
311
|
+
opts.parse %w/--foo-bar -h/
|
|
312
|
+
|
|
313
|
+
assert opts.present?('foo-bar')
|
|
314
|
+
refute opts.present?('bar-baz')
|
|
315
|
+
refute opts.present?('foo-bar', 'bar-baz')
|
|
316
|
+
assert opts.present?(:h)
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
test 'raises if an option expects an argument and none is given' do
|
|
320
|
+
slop = Slop.new
|
|
321
|
+
slop.opt :name, true
|
|
322
|
+
slop.opt :age, :optional => true
|
|
323
|
+
|
|
324
|
+
assert_raises(Slop::MissingArgumentError, /name/) { slop.parse %w/--name/ }
|
|
325
|
+
assert slop.parse %w/--name 'foo'/
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
test 'returning a hash of options' do
|
|
329
|
+
slop = Slop.new
|
|
330
|
+
slop.opt :name, true
|
|
331
|
+
slop.opt :version
|
|
332
|
+
slop.opt :V, :verbose, :default => false
|
|
333
|
+
slop.parse %w/--name lee --version/
|
|
334
|
+
|
|
335
|
+
assert_equal({'name' => 'lee', 'version' => true, 'verbose' => false}, slop.to_hash(false))
|
|
336
|
+
assert_equal({:name => 'lee', :version => true, :verbose => false}, slop.to_hash(true))
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
test 'iterating options' do
|
|
340
|
+
slop = Slop.new
|
|
341
|
+
slop.opt :a, :abc
|
|
342
|
+
slop.opt :f, :foo
|
|
343
|
+
|
|
344
|
+
assert_equal 2, slop.count
|
|
345
|
+
slop.each {|opt| assert_kind_of Slop::Option, opt }
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
test 'fetching options and option values' do
|
|
349
|
+
slop = Slop.new
|
|
350
|
+
slop.opt :foo, true
|
|
351
|
+
slop.parse %w/--foo bar/
|
|
352
|
+
|
|
353
|
+
assert_kind_of Slop::Option, slop.options[:foo]
|
|
354
|
+
assert_equal "bar", slop[:foo]
|
|
355
|
+
assert_equal "bar", slop['foo']
|
|
356
|
+
assert_kind_of Slop::Option, slop.options[0]
|
|
357
|
+
assert_nil slop.options['0']
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
test 'printing help' do
|
|
361
|
+
slop = Slop.new
|
|
362
|
+
slop.banner = 'Usage: foo [options]'
|
|
363
|
+
slop.parse
|
|
364
|
+
assert slop.to_s =~ /^Usage: foo/
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
test 'passing argument values to blocks' do
|
|
368
|
+
name = nil
|
|
369
|
+
opts = Slop.new
|
|
370
|
+
opts.on :name, true, :callback => proc {|n| name = n}
|
|
371
|
+
opts.parse %w/--name lee/
|
|
372
|
+
assert_equal 'lee', name
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
test 'strict mode' do
|
|
376
|
+
strict = Slop.new :strict => true
|
|
377
|
+
totallynotstrict = Slop.new
|
|
378
|
+
|
|
379
|
+
assert_raises(Slop::InvalidOptionError, /--foo/) { strict.parse %w/--foo/ }
|
|
380
|
+
assert totallynotstrict.parse %w/--foo/
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
test 'strict mode parses options before raising Slop::InvalidOptionError' do
|
|
384
|
+
strict = Slop.new :strict => true
|
|
385
|
+
strict.opt :n, :name, true
|
|
386
|
+
|
|
387
|
+
assert_raises(Slop::InvalidOptionError, /--foo/) { strict.parse %w/--foo --name nelson/ }
|
|
388
|
+
assert_equal 'nelson', strict[:name]
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
test 'short option flag with no space between flag and argument, with :multiple_switches => false' do
|
|
392
|
+
slop = Slop.new :multiple_switches => false
|
|
393
|
+
slop.opt :p, :password, true
|
|
394
|
+
slop.opt :s, :shortpass, true
|
|
395
|
+
slop.parse %w/-pfoo -sbar/
|
|
396
|
+
|
|
397
|
+
assert_equal 'foo', slop[:password]
|
|
398
|
+
assert_equal 'bar', slop[:shortpass]
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
test 'prefixing --no- onto options for a negative result' do
|
|
402
|
+
slop = Slop.new
|
|
403
|
+
slop.opt :d, :debug
|
|
404
|
+
slop.opt :v, :verbose, :default => true
|
|
405
|
+
slop.parse %w/--no-debug --no-verbose --no-nothing/
|
|
406
|
+
|
|
407
|
+
refute slop.verbose?
|
|
408
|
+
refute slop.debug?
|
|
409
|
+
refute slop[:verbose]
|
|
410
|
+
refute slop[:debug]
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
test 'option=value' do
|
|
414
|
+
slop = Slop.new
|
|
415
|
+
slop.opt :n, :name, true
|
|
416
|
+
slop.parse %w/--name=lee/
|
|
417
|
+
|
|
418
|
+
assert_equal 'lee', slop[:name]
|
|
419
|
+
assert slop.name?
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
test 'parsing options with options as arguments' do
|
|
423
|
+
slop = Slop.new { on :f, :foo, true }
|
|
424
|
+
assert_raises(Slop::MissingArgumentError) { slop.parse %w/-f --bar/ }
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
test 'custom IO object' do
|
|
428
|
+
io = StringIO.new
|
|
429
|
+
slop = Slop.new(:help => true, :io => io)
|
|
430
|
+
slop.on :f, :foo, 'something fooey'
|
|
431
|
+
begin
|
|
432
|
+
slop.parse %w/--help/
|
|
433
|
+
rescue SystemExit
|
|
434
|
+
end
|
|
435
|
+
assert io.string.include? 'something fooey'
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
test 'exiting when using :help option' do
|
|
439
|
+
io = StringIO.new
|
|
440
|
+
opts = Slop.new(:help => true, :io => io)
|
|
441
|
+
assert_raises(SystemExit) { opts.parse %w/--help/ }
|
|
442
|
+
|
|
443
|
+
opts = Slop.new(:help => true, :io => io, :exit_on_help => false)
|
|
444
|
+
assert opts.parse %w/--help/
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
test 'ignoring case' do
|
|
448
|
+
opts = Slop.new(:ignore_case => true)
|
|
449
|
+
opts.on :n, :name, true
|
|
450
|
+
opts.parse %w/--NAME lee/
|
|
451
|
+
assert_equal 'lee', opts[:name]
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
test 'autocreating options' do
|
|
455
|
+
opts = Slop.new(:autocreate => true) do |o|
|
|
456
|
+
o.on '--lorem', true
|
|
457
|
+
end
|
|
458
|
+
opts.parse %w/--hello --foo bar -a --lorem ipsum/
|
|
459
|
+
|
|
460
|
+
assert opts.hello?
|
|
461
|
+
assert opts.foo?
|
|
462
|
+
assert_equal 'bar', opts[:foo]
|
|
463
|
+
assert opts.a?
|
|
464
|
+
assert_equal 'ipsum', opts[:lorem]
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
test 'multiple elements for array option' do
|
|
468
|
+
opts = Slop.new do
|
|
469
|
+
on :a, true, :as => Array
|
|
470
|
+
end
|
|
471
|
+
opts.parse %w/-a foo -a bar baz -a etc/
|
|
472
|
+
|
|
473
|
+
assert_equal %w/foo bar etc/, opts[:a]
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
test ':arguments => true' do
|
|
477
|
+
opts = Slop.new(:arguments) { on :foo }
|
|
478
|
+
opts.parse %w/--foo bar/
|
|
479
|
+
|
|
480
|
+
assert_equal 'bar', opts[:foo]
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
test 'long flag strings' do
|
|
484
|
+
opts = Slop.new do
|
|
485
|
+
on 'f', 'foo BAR'
|
|
486
|
+
on 'bar [HELLO]'
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
assert opts.options[:foo].expects_argument?
|
|
490
|
+
assert opts.options[:bar].accepts_optional_argument?
|
|
491
|
+
|
|
492
|
+
assert_equal ' -f, --foo BAR ', opts.options[:foo].to_s
|
|
493
|
+
assert_equal ' --bar [HELLO] ', opts.options[:bar].to_s
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
test 'not parsing options if after --' do
|
|
497
|
+
args = %w[ foo bar -- --foo bar ]
|
|
498
|
+
opts = Slop.parse!(args) do
|
|
499
|
+
on :foo, true
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
assert_equal %w[ foo bar --foo bar ], args
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
test 'inline classes' do
|
|
506
|
+
opts = Slop.new do
|
|
507
|
+
on :foo, Array, true
|
|
508
|
+
on Symbol, :bar, true
|
|
509
|
+
end
|
|
510
|
+
opts.parse %w/--foo one,two --bar hello/
|
|
511
|
+
|
|
512
|
+
assert_equal %w[one two], opts[:foo]
|
|
513
|
+
assert_equal :hello, opts[:bar]
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
test 'wrap and indent' do
|
|
517
|
+
slop = Slop.new
|
|
518
|
+
|
|
519
|
+
assert_equal(
|
|
520
|
+
"Lorem ipsum dolor sit amet, consectetur\n" +
|
|
521
|
+
"adipisicing elit, sed do eiusmod tempor\n" +
|
|
522
|
+
"incididunt ut labore et dolore magna\n" +
|
|
523
|
+
"aliqua.",
|
|
524
|
+
slop.send(:wrap_and_indent, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 40, 0))
|
|
525
|
+
|
|
526
|
+
assert_equal(
|
|
527
|
+
" Lorem ipsum dolor sit amet,\n" +
|
|
528
|
+
" consectetur adipisicing elit, sed\n" +
|
|
529
|
+
" do eiusmod tempor incididunt ut\n" +
|
|
530
|
+
" labore et dolore magna aliqua.",
|
|
531
|
+
slop.send(:wrap_and_indent, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 36, 4))
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
test 'to_struct' do
|
|
535
|
+
assert_nil Slop.new.to_struct
|
|
536
|
+
|
|
537
|
+
slop = Slop.new { on :a, true }
|
|
538
|
+
slop.parse %w[ -a foo -b ]
|
|
539
|
+
struct = slop.to_struct
|
|
540
|
+
|
|
541
|
+
assert_equal 'foo', struct.a
|
|
542
|
+
assert_kind_of Struct, struct
|
|
543
|
+
assert_raises(NoMethodError) { struct.b }
|
|
544
|
+
|
|
545
|
+
pstruct = slop.to_struct('Foo')
|
|
546
|
+
assert_kind_of Struct::Foo, pstruct
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
test 'returning missing options' do
|
|
550
|
+
slop = Slop.new { on :a; on :b, :bar; on :c; }
|
|
551
|
+
slop.parse %w[ -a ]
|
|
552
|
+
|
|
553
|
+
assert_equal %w[ bar c ], slop.missing
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
test 'parsing an optspec and building options' do
|
|
557
|
+
optspec = <<-SPEC
|
|
558
|
+
ruby foo.rb [options]
|
|
559
|
+
--
|
|
560
|
+
v,verbose enable verbose mode
|
|
561
|
+
q,quiet enable quiet mode
|
|
562
|
+
debug enable debug mode
|
|
563
|
+
H enable hax mode (srsly)
|
|
564
|
+
n,name= set your name
|
|
565
|
+
-a,--age= set your age
|
|
566
|
+
SPEC
|
|
567
|
+
opts = Slop.optspec(optspec.gsub(/^\s+/, ''))
|
|
568
|
+
opts.parse %w[ --verbose --name Lee ]
|
|
569
|
+
|
|
570
|
+
assert_equal 'Lee', opts[:name]
|
|
571
|
+
assert opts.verbose?
|
|
572
|
+
assert_equal 'enable quiet mode', opts.options[:quiet].description
|
|
573
|
+
end
|
|
574
|
+
end
|