@@ -441,8 +441,8 @@ public void Parser_options_can_supply_context_sensitive_matches()
441441 {
442442 var parser = new RootCommand
443443 {
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" )
446446 } ;
447447
448448 var commandLine = "--bread" ;
@@ -546,8 +546,8 @@ public void Argument_completions_can_be_based_on_the_proximate_option()
546546 var parser = new Parser (
547547 new Command ( "outer" )
548548 {
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" )
551551 } ) ;
552552
553553 var commandLine = "outer --two" ;
@@ -648,12 +648,9 @@ public void When_caller_does_the_tokenizing_then_argument_completions_are_based_
648648 {
649649 var command = new Command ( "outer" )
650650 {
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" )
657654 } ;
658655
659656 var parser = new CommandLineBuilder ( new RootCommand
@@ -675,12 +672,9 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
675672 {
676673 var command = new Command ( "outer" )
677674 {
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" )
684678 } ;
685679
686680 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
698692 {
699693 new Command ( "one" )
700694 {
701- new Argument < string > ( ) . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
695+ CreateArgumentWithAcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
702696 } ,
703697 new Command ( "two" )
704698 {
705- new Argument < string > ( ) . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
699+ CreateArgumentWithAcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
706700 } ,
707701 new Command ( "three" )
708702 {
709- new Argument < string > ( ) . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
703+ CreateArgumentWithAcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
710704 }
711705 } ;
712706
@@ -725,15 +719,15 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
725719 {
726720 new Command ( "one" )
727721 {
728- new Argument < string > ( ) . AcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
722+ CreateArgumentWithAcceptOnlyFromAmong ( "one-a" , "one-b" , "one-c" )
729723 } ,
730724 new Command ( "two" )
731725 {
732- new Argument < string > ( ) . AcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
726+ CreateArgumentWithAcceptOnlyFromAmong ( "two-a" , "two-b" , "two-c" )
733727 } ,
734728 new Command ( "three" )
735729 {
736- new Argument < string > ( ) . AcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
730+ CreateArgumentWithAcceptOnlyFromAmong ( "three-a" , "three-b" , "three-c" )
737731 }
738732 } ;
739733
@@ -750,8 +744,8 @@ public void When_parsing_from_text_if_the_proximate_option_is_completed_then_com
750744 {
751745 var command = new RootCommand
752746 {
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#" ) ,
755749 new Option < string > ( "--langVersion" )
756750 } ;
757751 var parser = new CommandLineBuilder ( command ) . Build ( ) ;
@@ -767,8 +761,8 @@ public void When_parsing_from_array_if_the_proximate_option_is_completed_then_co
767761 {
768762 var command = new RootCommand
769763 {
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#" ) ,
772766 new Option < string > ( "--langVersion" )
773767 } ;
774768 var parser = new CommandLineBuilder ( command ) . Build ( ) ;
@@ -968,5 +962,19 @@ public void When_option_completions_are_available_then_they_are_suggested_when_a
968962 . Be (
969963 $ "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") ;
970964 }
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+ }
971979 }
972980}
0 commit comments