@@ -26,10 +26,7 @@ public CommandApp(ITypeRegistrar? registrar = null)
2626 _executor = new CommandExecutor ( registrar ) ;
2727 }
2828
29- /// <summary>
30- /// Configures the command line application.
31- /// </summary>
32- /// <param name="configuration">The configuration.</param>
29+ /// <inheritdoc/>
3330 public void Configure ( Action < IConfigurator > configuration )
3431 {
3532 if ( configuration == null )
@@ -51,22 +48,14 @@ public DefaultCommandConfigurator SetDefaultCommand<TCommand>()
5148 return new DefaultCommandConfigurator ( GetConfigurator ( ) . SetDefaultCommand < TCommand > ( ) ) ;
5249 }
5350
54- /// <summary>
55- /// Runs the command line application with specified arguments.
56- /// </summary>
57- /// <param name="args">The arguments.</param>
58- /// <returns>The exit code from the executed command.</returns>
59- public int Run ( IEnumerable < string > args )
51+ /// <inheritdoc/>
52+ public int Run ( IEnumerable < string > args , CancellationToken cancellationToken = default )
6053 {
61- return RunAsync ( args ) . GetAwaiter ( ) . GetResult ( ) ;
54+ return RunAsync ( args , cancellationToken ) . GetAwaiter ( ) . GetResult ( ) ;
6255 }
6356
64- /// <summary>
65- /// Runs the command line application with specified arguments.
66- /// </summary>
67- /// <param name="args">The arguments.</param>
68- /// <returns>The exit code from the executed command.</returns>
69- public async Task < int > RunAsync ( IEnumerable < string > args )
57+ /// <inheritdoc/>
58+ public async Task < int > RunAsync ( IEnumerable < string > args , CancellationToken cancellationToken = default )
7059 {
7160 try
7261 {
@@ -86,7 +75,7 @@ public async Task<int> RunAsync(IEnumerable<string> args)
8675 }
8776
8877 return await _executor
89- . Execute ( _configurator , args )
78+ . ExecuteAsync ( _configurator , args , cancellationToken )
9079 . ConfigureAwait ( false ) ;
9180 }
9281 catch ( Exception ex )
@@ -109,6 +98,11 @@ public async Task<int> RunAsync(IEnumerable<string> args)
10998 return _configurator . Settings . ExceptionHandler ( ex , null ) ;
11099 }
111100
101+ if ( ex is OperationCanceledException )
102+ {
103+ return _configurator . Settings . CancellationExitCode ;
104+ }
105+
112106 // Render the exception.
113107 var pretty = GetRenderableErrorMessage ( ex ) ;
114108 if ( pretty != null )
0 commit comments