@@ -6,7 +6,6 @@ def create(opts, defaults = {}, stop_on_unknown = false)
6
6
opts . each do |key , value |
7
7
opts [ key ] = Thor ::Option . parse ( key , value ) unless value . is_a? ( Thor ::Option )
8
8
end
9
-
10
9
@opt = Thor ::Options . new ( opts , defaults , stop_on_unknown )
11
10
end
12
11
@@ -302,6 +301,13 @@ def remaining
302
301
expect { parse ( "--fruit" , "orange" ) } . to raise_error ( Thor ::MalformattedArgumentError ,
303
302
"Expected '--fruit' to be one of #{ enum . join ( ', ' ) } ; got orange" )
304
303
end
304
+
305
+ it "allows multiple values if repeatable is specified" do
306
+ create :foo => Thor ::Option . new ( "foo" , :type => :string , :repeatable => true )
307
+
308
+ expect ( parse ( "--foo=bar" , "--foo" , "12" ) [ "foo" ] ) . to eq ( [ "bar" , "12" ] )
309
+ expect ( parse ( "--foo" , "13" , "--foo" , "14" ) [ "foo" ] ) . to eq ( [ "bar" , "12" , "13" , "14" ] )
310
+ end
305
311
end
306
312
307
313
describe "with :boolean type" do
@@ -362,6 +368,11 @@ def remaining
362
368
expect ( parse ( "--skip-foo" , "bar" ) ) . to eq ( "foo" => false )
363
369
expect ( @opt . remaining ) . to eq ( %w( bar ) )
364
370
end
371
+
372
+ it "allows multiple values if repeatable is specified" do
373
+ create :verbose => Thor ::Option . new ( "verbose" , :type => :boolean , :aliases => '-v' , :repeatable => true )
374
+ expect ( parse ( "-v" , "-v" , "-v" ) [ "verbose" ] . count ) . to eq ( 3 )
375
+ end
365
376
end
366
377
367
378
describe "with :hash type" do
@@ -384,6 +395,11 @@ def remaining
384
395
it "must not allow the same hash key to be specified multiple times" do
385
396
expect { parse ( "--attributes" , "name:string" , "name:integer" ) } . to raise_error ( Thor ::MalformattedArgumentError , "You can't specify 'name' more than once in option '--attributes'; got name:string and name:integer" )
386
397
end
398
+
399
+ it "allows multiple values if repeatable is specified" do
400
+ create :attributes => Thor ::Option . new ( "attributes" , :type => :hash , :repeatable => true )
401
+ expect ( parse ( "--attributes" , "name:one" , "foo:1" , "--attributes" , "name:two" , "bar:2" ) [ "attributes" ] ) . to eq ( { "name" => "two" , "foo" => "1" , "bar" => "2" } )
402
+ end
387
403
end
388
404
389
405
describe "with :array type" do
@@ -402,6 +418,11 @@ def remaining
402
418
it "must not mix values with other switches" do
403
419
expect ( parse ( "--attributes" , "a" , "b" , "c" , "--baz" , "cool" ) [ "attributes" ] ) . to eq ( %w( a b c ) )
404
420
end
421
+
422
+ it "allows multiple values if repeatable is specified" do
423
+ create :attributes => Thor ::Option . new ( "attributes" , :type => :array , :repeatable => true )
424
+ expect ( parse ( "--attributes" , "1" , "2" , "--attributes" , "3" , "4" ) [ "attributes" ] ) . to eq ( [ [ "1" , "2" ] , [ "3" , "4" ] ] )
425
+ end
405
426
end
406
427
407
428
describe "with :numeric type" do
@@ -428,6 +449,11 @@ def remaining
428
449
expect { parse ( "--limit" , "3" ) } . to raise_error ( Thor ::MalformattedArgumentError ,
429
450
"Expected '--limit' to be one of #{ enum . join ( ', ' ) } ; got 3" )
430
451
end
452
+
453
+ it "allows multiple values if repeatable is specified" do
454
+ create :run => Thor ::Option . new ( "run" , :type => :numeric , :repeatable => true )
455
+ expect ( parse ( "--run" , "1" , "--run" , "2" ) [ "run" ] ) . to eq ( [ 1 , 2 ] )
456
+ end
431
457
end
432
458
end
433
459
end
0 commit comments