File tree Expand file tree Collapse file tree 4 files changed +38
-14
lines changed Expand file tree Collapse file tree 4 files changed +38
-14
lines changed Original file line number Diff line number Diff line change 8
8
using System . CommandLine . Tests . Utility ;
9
9
using System . Threading . Tasks ;
10
10
using FluentAssertions ;
11
- using FluentAssertions . Primitives ;
12
11
using Xunit ;
13
12
14
13
namespace System . CommandLine . Tests
@@ -144,6 +143,25 @@ public void There_are_no_parse_errors_when_help_is_invoked_on_a_command_with_sub
144
143
result . Errors . Should ( ) . BeEmpty ( ) ;
145
144
}
146
145
146
+ [ Fact ]
147
+ public void There_are_no_parse_errors_when_help_is_invoked_on_a_command_with_required_options ( )
148
+ {
149
+ var command = new RootCommand
150
+ {
151
+ new Option < string > ( "-x" )
152
+ {
153
+ Required = true
154
+ } ,
155
+ } ;
156
+
157
+ var result = new CommandLineBuilder ( command )
158
+ . UseHelp ( )
159
+ . Build ( )
160
+ . Parse ( "-h" ) ;
161
+
162
+ result . Errors . Should ( ) . BeEmpty ( ) ;
163
+ }
164
+
147
165
[ Theory ]
148
166
[ InlineData ( "-h" ) ]
149
167
[ InlineData ( "inner -h" ) ]
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public CommandLineBuilder(Command? rootCommand = null)
27
27
28
28
internal Func < BindingContext , IHelpBuilder > ? HelpBuilderFactory { get ; set ; }
29
29
30
- internal Option ? HelpOption { get ; set ; }
30
+ internal HelpOption ? HelpOption { get ; set ; }
31
31
32
32
internal ValidationMessages ? ValidationMessages { get ; set ; }
33
33
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ public static CommandLineBuilder UseHelp(this CommandLineBuilder builder)
282
282
283
283
internal static CommandLineBuilder UseHelp (
284
284
this CommandLineBuilder builder ,
285
- Option helpOption )
285
+ HelpOption helpOption )
286
286
{
287
287
if ( builder . HelpOption is null )
288
288
{
Original file line number Diff line number Diff line change @@ -154,8 +154,18 @@ protected override void VisitUnknownNode(SyntaxNode node)
154
154
155
155
protected override void Stop ( SyntaxNode node )
156
156
{
157
+ var helpWasRequested =
158
+ _innermostCommandResult
159
+ ? . Children
160
+ . Any ( o => o . Symbol is HelpOption ) == true ;
161
+
162
+ if ( helpWasRequested )
163
+ {
164
+ return ;
165
+ }
166
+
157
167
ValidateCommandHandler ( ) ;
158
-
168
+
159
169
PopulateDefaultValues ( ) ;
160
170
161
171
ValidateCommandResult ( ) ;
@@ -229,7 +239,7 @@ private void ValidateCommandResult()
229
239
230
240
private void ValidateCommandHandler ( )
231
241
{
232
- if ( ! ( _innermostCommandResult ! . Command is Command cmd ) ||
242
+ if ( ! ( _innermostCommandResult ! . Command is Command cmd ) ||
233
243
cmd . Handler != null )
234
244
{
235
245
return ;
@@ -240,15 +250,11 @@ private void ValidateCommandHandler()
240
250
return ;
241
251
}
242
252
243
- if ( ! _innermostCommandResult
244
- . Children
245
- . Select ( o => o . Symbol is HelpOption ) . Any ( ) )
246
- {
247
- _errors . Insert ( 0 ,
248
- new ParseError (
249
- _innermostCommandResult . ValidationMessages . RequiredCommandWasNotProvided ( ) ,
250
- _innermostCommandResult ) ) ;
251
- }
253
+ _errors . Insert (
254
+ 0 ,
255
+ new ParseError (
256
+ _innermostCommandResult . ValidationMessages . RequiredCommandWasNotProvided ( ) ,
257
+ _innermostCommandResult ) ) ;
252
258
}
253
259
254
260
private void ValidateOptionResult ( OptionResult optionResult )
You can’t perform that action at this time.
0 commit comments