File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/System.CommandLine.Tests Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -260,4 +260,37 @@ public void ThrowIfInvalid_throws_if_a_parentage_cycle_is_detected()
260
260
. Should ( )
261
261
. Be ( $ "Cycle detected in command tree. Command '{ rootCommand . Name } ' is its own ancestor.") ;
262
262
}
263
+
264
+ [ Fact ]
265
+ public void It_can_be_subclassed_to_provide_additional_context ( )
266
+ {
267
+ var command = new CliRootCommand ( ) ;
268
+ var commandWasInvoked = false ;
269
+ command . SetAction ( parseResult =>
270
+ {
271
+ var appConfig = ( CustomAppConfiguration ) parseResult . Configuration ;
272
+
273
+ // access custom config
274
+
275
+ commandWasInvoked = true ;
276
+
277
+ return 0 ;
278
+ } ) ;
279
+
280
+ var config = new CustomAppConfiguration ( command ) ;
281
+
282
+ config . Invoke ( "" ) ;
283
+
284
+ commandWasInvoked . Should ( ) . BeTrue ( ) ;
285
+ }
286
+ }
287
+
288
+ public class CustomAppConfiguration : CliConfiguration
289
+ {
290
+ public CustomAppConfiguration ( CliRootCommand command ) : base ( command )
291
+ {
292
+ EnableDefaultExceptionHandler = false ;
293
+ }
294
+
295
+ public IServiceProvider ServiceProvider { get ; }
263
296
}
You can’t perform that action at this time.
0 commit comments