Introduce CliAction, make it possible for every Symbol to define one#2095
Introduce CliAction, make it possible for every Symbol to define one#2095adamsitnik merged 8 commits intodotnet:mainfrom
Conversation
…ke async command handler and pass the cancellation token
| } | ||
|
|
||
| [Fact] | ||
| public void Every_option_can_provide_a_handler_and_it_takes_precedence_over_command_handler() |
There was a problem hiding this comment.
What if two different options having handlers are both present?
There was a problem hiding this comment.
We have two possibilities:
- stop on the first active option
- let the last one to be the effective (this is what we already do for commands)
@jonsequitur choosing the last one is the most intuitive way for me. What do you think?
There was a problem hiding this comment.
We could also make it a parse error. Of course certain options (like -h) ignore that and the action still runs.
I wasn't expecting this to be available on |
expose Action only for Command, Directive and Option expose SetAction only for Command, make it an actual Action (no exit code returning)
That is very true. I've applied following changes:
|
…ffective + some polishing
# Conflicts: # src/System.CommandLine/ParseResult.cs
Sure, let's discuss it offline with @KathleenDollard. I am going to merge this PR right now to avoid conflict with my next PR (removal of middleware!) |
|
@adamsitnik in #2046 you said: all handlers should return an And here the design is:
Failures are often expected in command line applications. Without the capability to return an This lead to a bad user experience. |
Overall it was way easier than I expected.
This PR:
ICommandHandlerwithCliActionCommand.SetHandlerwithCommand.SetAction.Command.SetActiondo not need to return an int. In case somebody wants to reuturn an int, they need to implement their ownCliActiontype (pay for play)Actionproperty, but notSetActionmethods (no need to, as it should be rare to have active options and directives that don't need custom types)Contributes to #2071