@@ -439,6 +439,157 @@ pos_c"
439
439
) ;
440
440
}
441
441
442
+ #[ test]
443
+ fn suggest_argument_multi_values ( ) {
444
+ let mut cmd = Command :: new ( "dynamic" )
445
+ . arg (
446
+ clap:: Arg :: new ( "certain-num" )
447
+ . long ( "certain-num" )
448
+ . short ( 'Y' )
449
+ . value_parser ( [ "val1" , "val2" , "val3" ] )
450
+ . num_args ( 3 ) ,
451
+ )
452
+ . arg (
453
+ clap:: Arg :: new ( "uncertain-num" )
454
+ . long ( "uncertain-num" )
455
+ . short ( 'N' )
456
+ . value_parser ( [ "val1" , "val2" , "val3" ] )
457
+ . num_args ( 1 ..=3 ) ,
458
+ ) ;
459
+
460
+ assert_data_eq ! (
461
+ complete!( cmd, "--certain-num [TAB]" ) ,
462
+ snapbox:: str ![
463
+ "val1
464
+ val2
465
+ val3"
466
+ ]
467
+ ) ;
468
+
469
+ assert_data_eq ! (
470
+ complete!( cmd, "--certain-num val1 [TAB]" ) ,
471
+ snapbox:: str ![
472
+ "--certain-num
473
+ --uncertain-num
474
+ --help\t Print help
475
+ -Y
476
+ -N
477
+ -h\t Print help"
478
+ ]
479
+ ) ;
480
+
481
+ assert_data_eq ! (
482
+ complete!( cmd, "--certain-num val1 val2 val3 [TAB]" ) ,
483
+ snapbox:: str ![
484
+ "--certain-num
485
+ --uncertain-num
486
+ --help\t Print help
487
+ -Y
488
+ -N
489
+ -h\t Print help"
490
+ ]
491
+ ) ;
492
+
493
+ assert_data_eq ! (
494
+ complete!( cmd, "--uncertain-num [TAB]" ) ,
495
+ snapbox:: str ![
496
+ "val1
497
+ val2
498
+ val3"
499
+ ]
500
+ ) ;
501
+
502
+ assert_data_eq ! (
503
+ complete!( cmd, "--uncertain-num val1 [TAB]" ) ,
504
+ snapbox:: str ![
505
+ "--certain-num
506
+ --uncertain-num
507
+ --help\t Print help
508
+ -Y
509
+ -N
510
+ -h\t Print help"
511
+ ]
512
+ ) ;
513
+
514
+ assert_data_eq ! (
515
+ complete!( cmd, "--uncertain-num val1 val2 val3 [TAB]" ) ,
516
+ snapbox:: str ![
517
+ "--certain-num
518
+ --uncertain-num
519
+ --help\t Print help
520
+ -Y
521
+ -N
522
+ -h\t Print help"
523
+ ]
524
+ ) ;
525
+
526
+ assert_data_eq ! (
527
+ complete!( cmd, "-Y [TAB]" ) ,
528
+ snapbox:: str ![
529
+ "val1
530
+ val2
531
+ val3"
532
+ ]
533
+ ) ;
534
+
535
+ assert_data_eq ! (
536
+ complete!( cmd, "-Y val1 [TAB]" ) ,
537
+ snapbox:: str ![
538
+ "--certain-num
539
+ --uncertain-num
540
+ --help\t Print help
541
+ -Y
542
+ -N
543
+ -h\t Print help"
544
+ ]
545
+ ) ;
546
+
547
+ assert_data_eq ! (
548
+ complete!( cmd, "-Y val1 val2 val3 [TAB]" ) ,
549
+ snapbox:: str ![
550
+ "--certain-num
551
+ --uncertain-num
552
+ --help\t Print help
553
+ -Y
554
+ -N
555
+ -h\t Print help"
556
+ ]
557
+ ) ;
558
+
559
+ assert_data_eq ! (
560
+ complete!( cmd, "-N [TAB]" ) ,
561
+ snapbox:: str ![
562
+ "val1
563
+ val2
564
+ val3"
565
+ ]
566
+ ) ;
567
+
568
+ assert_data_eq ! (
569
+ complete!( cmd, "-N val1 [TAB]" ) ,
570
+ snapbox:: str ![
571
+ "--certain-num
572
+ --uncertain-num
573
+ --help\t Print help
574
+ -Y
575
+ -N
576
+ -h\t Print help"
577
+ ]
578
+ ) ;
579
+
580
+ assert_data_eq ! (
581
+ complete!( cmd, "-N val1 val2 val3 [TAB]" ) ,
582
+ snapbox:: str ![
583
+ "--certain-num
584
+ --uncertain-num
585
+ --help\t Print help
586
+ -Y
587
+ -N
588
+ -h\t Print help"
589
+ ]
590
+ ) ;
591
+ }
592
+
442
593
fn complete ( cmd : & mut Command , args : impl AsRef < str > , current_dir : Option < & Path > ) -> String {
443
594
let input = args. as_ref ( ) ;
444
595
let mut args = vec ! [ std:: ffi:: OsString :: from( cmd. get_name( ) ) ] ;
0 commit comments