@@ -83,7 +83,6 @@ public void When_a_required_argument_is_not_supplied_then_an_error_is_returned()
83
83
. Contain ( e => e . Message == "Required argument missing for option: -x" ) ;
84
84
}
85
85
86
-
87
86
[ Fact ]
88
87
public void When_a_required_option_is_not_supplied_then_an_error_is_returned ( )
89
88
{
@@ -147,7 +146,6 @@ public void Required_options_on_parent_commands_do_not_create_parse_errors_when_
147
146
result . Errors . Should ( ) . BeEmpty ( ) ;
148
147
}
149
148
150
-
151
149
[ Fact ]
152
150
public void When_no_option_accepts_arguments_but_one_is_supplied_then_an_error_is_returned ( )
153
151
{
@@ -246,6 +244,35 @@ public void A_custom_validator_can_be_added_to_an_argument()
246
244
. Be ( "Argument x cannot be set to 123" ) ;
247
245
}
248
246
247
+ [ Theory ]
248
+ [ InlineData ( "--file \" Foo\" subcommand" ) ]
249
+ [ InlineData ( "subcommand --file \" Foo\" " ) ]
250
+ public void Validators_on_global_options_are_executed_when_invoking_a_subcommand ( string commandLine )
251
+ {
252
+ var option = new Option < FileInfo > ( "--file" ) ;
253
+ option . Argument . AddValidator ( r =>
254
+ {
255
+ return "Invoked validator" ;
256
+ } ) ;
257
+
258
+ var subCommand = new Command ( "subcommand" ) ;
259
+ var rootCommand = new RootCommand
260
+ {
261
+ subCommand
262
+ } ;
263
+ rootCommand . AddGlobalOption ( option ) ;
264
+
265
+ var result = rootCommand . Parse ( commandLine ) ;
266
+
267
+ result . Errors
268
+ . Should ( )
269
+ . ContainSingle ( e => e . SymbolResult . Symbol == option . Argument )
270
+ . Which
271
+ . Message
272
+ . Should ( )
273
+ . Be ( "Invoked validator" ) ;
274
+ }
275
+
249
276
[ Theory ]
250
277
[ InlineData ( "--value 123" ) ]
251
278
[ InlineData ( "--value=123 child" ) ]
0 commit comments