55using System . CommandLine . Invocation ;
66using System . CommandLine . Parsing ;
77using System . IO ;
8- using System . Runtime . InteropServices . ComTypes ;
98using System . Threading ;
109using System . Threading . Tasks ;
1110using FluentAssertions ;
@@ -195,10 +194,10 @@ public async Task Anonymous_RootCommand_int_returning_Action_can_set_custom_resu
195194 }
196195
197196 [ Fact ]
198- public void Option_action_takes_precedence_over_command_action ( )
197+ public void Terminating_option_action_short_circuits_command_action ( )
199198 {
200- bool wasCalled = false ;
201- SynchronousTestAction optionAction = new ( _ => wasCalled = true ) ;
199+ bool optionActionWasCalled = false ;
200+ SynchronousTestAction optionAction = new ( _ => optionActionWasCalled = true , terminating : true ) ;
202201 bool commandActionWasCalled = false ;
203202
204203 CliOption < bool > option = new ( "--test" )
@@ -214,17 +213,41 @@ public void Option_action_takes_precedence_over_command_action()
214213 commandActionWasCalled = true ;
215214 } ) ;
216215
217- ParseResult parseResult = command . Parse ( "cmd --test true " ) ;
216+ ParseResult parseResult = command . Parse ( "cmd --test" ) ;
218217
219218 parseResult . Action . Should ( ) . NotBeNull ( ) ;
220- wasCalled . Should ( ) . BeFalse ( ) ;
219+ optionActionWasCalled . Should ( ) . BeFalse ( ) ;
221220 commandActionWasCalled . Should ( ) . BeFalse ( ) ;
222221
223222 parseResult . Invoke ( ) . Should ( ) . Be ( 0 ) ;
224- wasCalled . Should ( ) . BeTrue ( ) ;
223+ optionActionWasCalled . Should ( ) . BeTrue ( ) ;
225224 commandActionWasCalled . Should ( ) . BeFalse ( ) ;
226225 }
227226
227+ [ Fact ]
228+ public void Nonterminating_option_action_does_not_short_circuit_command_action ( )
229+ {
230+ bool optionActionWasCalled = false ;
231+ SynchronousTestAction optionAction = new ( _ => optionActionWasCalled = true , terminating : false ) ;
232+ bool commandActionWasCalled = false ;
233+
234+ CliOption < bool > option = new ( "--test" )
235+ {
236+ Action = optionAction
237+ } ;
238+ CliCommand command = new CliCommand ( "cmd" )
239+ {
240+ option
241+ } ;
242+ command . SetAction ( _ => { commandActionWasCalled = true ; } ) ;
243+
244+ ParseResult parseResult = command . Parse ( "cmd --test" ) ;
245+
246+ parseResult . Invoke ( ) . Should ( ) . Be ( 0 ) ;
247+ optionActionWasCalled . Should ( ) . BeTrue ( ) ;
248+ commandActionWasCalled . Should ( ) . BeTrue ( ) ;
249+ }
250+
228251 [ Fact ]
229252 public void When_multiple_options_with_actions_are_present_then_only_the_last_one_is_invoked ( )
230253 {
@@ -286,7 +309,7 @@ public void Directive_action_takes_precedence_over_option_action()
286309 [ Theory ]
287310 [ InlineData ( true ) ]
288311 [ InlineData ( false ) ]
289- public async Task Nonexclusive_actions_handle_exceptions_and_return_an_error_return_code ( bool invokeAsync )
312+ public async Task Nontermninating_actions_handle_exceptions_and_return_an_error_return_code ( bool invokeAsync )
290313 {
291314 var nonexclusiveAction = new NonexclusiveTestAction
292315 {
0 commit comments