@@ -441,8 +441,8 @@ public void Parser_options_can_supply_context_sensitive_matches()
441
441
{
442
442
var parser = new RootCommand
443
443
{
444
- new Option < string > ( "--bread" ) . AcceptOnlyFromAmong ( "wheat" , "sourdough" , "rye" ) ,
445
- new Option < string > ( "--cheese" ) . AcceptOnlyFromAmong ( "provolone" , "cheddar" , "cream cheese" )
444
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--bread" , "wheat" , "sourdough" , "rye" ) ,
445
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--cheese" , "provolone" , "cheddar" , "cream cheese" )
446
446
} ;
447
447
448
448
var commandLine = "--bread" ;
@@ -546,8 +546,8 @@ public void Argument_completions_can_be_based_on_the_proximate_option()
546
546
var parser = new Parser (
547
547
new Command ( "outer" )
548
548
{
549
- new Option < string > ( "--one" ) . AcceptOnlyFromAmong ( "one-a" , "one-b" ) ,
550
- new Option < string > ( "--two" ) . AcceptOnlyFromAmong ( "two-a" , "two-b" )
549
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--one" , "one-a" , "one-b" ) ,
550
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--two" , "two-a" , "two-b" )
551
551
} ) ;
552
552
553
553
var commandLine = "outer --two" ;
@@ -648,12 +648,9 @@ public void When_caller_does_the_tokenizing_then_argument_completions_are_based_
648
648
{
649
649
var command = new Command ( "outer" )
650
650
{
651
- new Option < string > ( "one" )
652
- . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" ) ,
653
- new Option < string > ( "two" )
654
- . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" ) ,
655
- new Option < string > ( "three" )
656
- . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
651
+ CreateOptionWithAcceptOnlyFromAmong ( name : "one" , "one-a" , "one-b" , "one-c" ) ,
652
+ CreateOptionWithAcceptOnlyFromAmong ( name : "two" , "two-a" , "two-b" , "two-c" ) ,
653
+ CreateOptionWithAcceptOnlyFromAmong ( name : "three" , "three-a" , "three-b" , "three-c" )
657
654
} ;
658
655
659
656
var parser = new CommandLineBuilder ( new RootCommand
@@ -675,12 +672,9 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
675
672
{
676
673
var command = new Command ( "outer" )
677
674
{
678
- new Option < string > ( "one" )
679
- . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" ) ,
680
- new Option < string > ( "two" )
681
- . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" ) ,
682
- new Option < string > ( "three" )
683
- . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
675
+ CreateOptionWithAcceptOnlyFromAmong ( name : "one" , "one-a" , "one-b" , "one-c" ) ,
676
+ CreateOptionWithAcceptOnlyFromAmong ( name : "two" , "two-a" , "two-b" , "two-c" ) ,
677
+ CreateOptionWithAcceptOnlyFromAmong ( name : "three" , "three-a" , "three-b" , "three-c" )
684
678
} ;
685
679
686
680
var result = command . Parse ( "outer two b" ) ;
@@ -698,15 +692,15 @@ public void When_parsing_from_text_then_argument_completions_are_based_on_the_pr
698
692
{
699
693
new Command ( "one" )
700
694
{
701
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
695
+ CreateArgumentWithAcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
702
696
} ,
703
697
new Command ( "two" )
704
698
{
705
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
699
+ CreateArgumentWithAcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
706
700
} ,
707
701
new Command ( "three" )
708
702
{
709
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
703
+ CreateArgumentWithAcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
710
704
}
711
705
} ;
712
706
@@ -725,15 +719,15 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
725
719
{
726
720
new Command ( "one" )
727
721
{
728
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
722
+ CreateArgumentWithAcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
729
723
} ,
730
724
new Command ( "two" )
731
725
{
732
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
726
+ CreateArgumentWithAcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
733
727
} ,
734
728
new Command ( "three" )
735
729
{
736
- new Argument < string > ( ) . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
730
+ CreateArgumentWithAcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
737
731
}
738
732
} ;
739
733
@@ -750,8 +744,8 @@ public void When_parsing_from_text_if_the_proximate_option_is_completed_then_com
750
744
{
751
745
var command = new RootCommand
752
746
{
753
- new Option < string > ( "--framework" ) . AcceptOnlyFromAmong ( "net7.0" ) ,
754
- new Option < string > ( "--language" ) . AcceptOnlyFromAmong ( "C#" ) ,
747
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--framework" , "net7.0" ) ,
748
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--language" , "C#" ) ,
755
749
new Option < string > ( "--langVersion" )
756
750
} ;
757
751
var parser = new CommandLineBuilder ( command ) . Build ( ) ;
@@ -767,8 +761,8 @@ public void When_parsing_from_array_if_the_proximate_option_is_completed_then_co
767
761
{
768
762
var command = new RootCommand
769
763
{
770
- new Option < string > ( "--framework" ) . AcceptOnlyFromAmong ( "net7.0" ) ,
771
- new Option < string > ( "--language" ) . AcceptOnlyFromAmong ( "C#" ) ,
764
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--framework" , "net7.0" ) ,
765
+ CreateOptionWithAcceptOnlyFromAmong ( name : "--language" , "C#" ) ,
772
766
new Option < string > ( "--langVersion" )
773
767
} ;
774
768
var parser = new CommandLineBuilder ( command ) . Build ( ) ;
@@ -968,5 +962,19 @@ public void When_option_completions_are_available_then_they_are_suggested_when_a
968
962
. Be (
969
963
$ "Cannot parse argument 'SleepyDay' for option '--day' as expected type 'System.DayOfWeek'. Did you mean one of the following?{ NewLine } Friday{ NewLine } Monday{ NewLine } Saturday{ NewLine } Sunday{ NewLine } Thursday{ NewLine } Tuesday{ NewLine } Wednesday") ;
970
964
}
965
+
966
+ private static Argument < string > CreateArgumentWithAcceptOnlyFromAmong ( params string [ ] values )
967
+ {
968
+ Argument < string > argument = new ( ) ;
969
+ argument . AcceptOnlyFromAmong ( values ) ;
970
+ return argument ;
971
+ }
972
+
973
+ private static Option < string > CreateOptionWithAcceptOnlyFromAmong ( string name , params string [ ] values )
974
+ {
975
+ Option < string > option = new ( name ) ;
976
+ option . AcceptOnlyFromAmong ( values ) ;
977
+ return option ;
978
+ }
971
979
}
972
980
}
0 commit comments