@@ -16,6 +16,11 @@ namespace CommandLine.Tests.Unit
1616{
1717 public class Issue6Tests
1818 {
19+ /// <summary>
20+ /// Test Verb aliases when one verb is set as a default
21+ /// </summary>
22+ /// <param name="args"></param>
23+ /// <param name="expectedArgType"></param>
1924 [ Theory ]
2025 [ InlineData ( "move -a bob" , typeof ( AliasedVerbOption1 ) ) ]
2126 [ InlineData ( "mv -a bob" , typeof ( AliasedVerbOption1 ) ) ]
@@ -43,6 +48,42 @@ public void Parse_option_with_aliased_verbs(string args, Type expectedArgType)
4348 Assert . Equal ( expectedArgType , options . GetType ( ) ) ;
4449 }
4550
51+ /// <summary>
52+ /// Test verb aliases with no default verb and 1 verb with no aliases
53+ /// </summary>
54+ /// <param name="args"></param>
55+ /// <param name="expectedArgType"></param>
56+ [ Theory ]
57+ [ InlineData ( "move -a bob" , typeof ( AliasedVerbOption1 ) ) ]
58+ [ InlineData ( "mv -a bob" , typeof ( AliasedVerbOption1 ) ) ]
59+ [ InlineData ( "delete -b fred" , typeof ( VerbNoAlias ) ) ]
60+ public void Parse_option_with_aliased_verb ( string args , Type expectedArgType )
61+ {
62+ var arguments = args . Split ( ' ' ) ;
63+ object options = null ;
64+ IEnumerable < Error > errors = null ;
65+ var result = Parser . Default . ParseArguments < AliasedVerbOption1 , VerbNoAlias > ( arguments )
66+ . WithParsed ( o => options = o )
67+ . WithNotParsed ( o => errors = o )
68+ ;
69+ if ( errors != null && errors . Any ( ) )
70+ {
71+ foreach ( Error e in errors )
72+ {
73+ System . Console . WriteLine ( e . ToString ( ) ) ;
74+ }
75+ }
76+
77+ Assert . NotNull ( options ) ;
78+ Assert . Equal ( expectedArgType , options . GetType ( ) ) ;
79+ }
80+
81+ /// <summary>
82+ /// Verify auto-help generation.
83+ /// </summary>
84+ /// <param name="args"></param>
85+ /// <param name="verbsIndex"></param>
86+ /// <param name="expected"></param>
4687 [ Theory ]
4788 [ InlineData ( "--help" , true , new string [ ]
4889 {
@@ -112,7 +153,81 @@ public void Parse_help_option_for_aliased_verbs(string args, bool verbsIndex, st
112153 }
113154 }
114155
115- [ Verb ( "move" , aliases : new string [ ] { "mv" } ) ]
156+ /// <summary>
157+ /// Verify auto-help generation with no default verb.
158+ /// </summary>
159+ /// <param name="args"></param>
160+ /// <param name="verbsIndex"></param>
161+ /// <param name="expected"></param>
162+ [ Theory ]
163+ [ InlineData ( "--help" , true , new string [ ]
164+ {
165+ "move, mv" ,
166+ "delete Delete stuff" ,
167+ "help Display more information on a specific command." ,
168+ "version Display version information." ,
169+ } ) ]
170+ [ InlineData ( "help" , true , new string [ ]
171+ {
172+ "move, mv" ,
173+ "delete Delete stuff" ,
174+ "help Display more information on a specific command." ,
175+ "version Display version information." ,
176+ } ) ]
177+ [ InlineData ( "move --help" , false , new string [ ]
178+ {
179+ "-a, --alpha Required." ,
180+ "--help Display this help screen." ,
181+ "--version Display version information." ,
182+ } ) ]
183+ [ InlineData ( "mv --help" , false , new string [ ]
184+ {
185+ "-a, --alpha Required." ,
186+ "--help Display this help screen." ,
187+ "--version Display version information." ,
188+ } ) ]
189+ [ InlineData ( "delete --help" , false , new string [ ]
190+ {
191+ "-b, --beta Required." ,
192+ "--help Display this help screen." ,
193+ "--version Display version information." ,
194+ } ) ]
195+ public void Parse_help_option_for_aliased_verbs_no_default ( string args , bool verbsIndex , string [ ] expected )
196+ {
197+ var arguments = args . Split ( ' ' ) ;
198+ object options = null ;
199+ IEnumerable < Error > errors = null ;
200+ // the order of the arguments here drives the order of the commands shown
201+ // in the help message
202+ var result = Parser . Default . ParseArguments <
203+ AliasedVerbOption1 ,
204+ VerbNoAlias
205+ > ( arguments )
206+ . WithParsed ( o => options = o )
207+ . WithNotParsed ( o => errors = o )
208+ ;
209+
210+ var message = HelpText . AutoBuild ( result ,
211+ error => error ,
212+ ex => ex ,
213+ verbsIndex : verbsIndex
214+ ) ;
215+
216+ string helpMessage = message . ToString ( ) ;
217+ var helps = helpMessage . Split ( new [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) . Skip ( 2 ) . ToList < string > ( ) ;
218+
219+ expected . Length . Should ( ) . Be ( helps . Count ) ;
220+ int i = 0 ;
221+ foreach ( var expect in expected )
222+ {
223+ helps [ i ] . Trim ( ) . Should ( ) . Be ( expect ) ;
224+ i ++ ;
225+ }
226+ }
227+
228+ [ Verb ( "move" ,
229+ aliases : new string [ ] { "mv" }
230+ ) ]
116231 public class AliasedVerbOption1
117232 {
118233 [ Option ( 'a' , "alpha" , Required = true ) ]
@@ -130,7 +245,7 @@ public class AliasedVerbOption2
130245 public string Option { get ; set ; }
131246 }
132247
133- [ Verb ( "delete" , HelpText = "Delete stuff" ) ]
248+ [ Verb ( "delete" , HelpText = "Delete stuff" ) ]
134249 public class VerbNoAlias
135250 {
136251 [ Option ( 'b' , "beta" , Required = true ) ]
0 commit comments