-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce CliAction, make it possible for every Symbol to define one #2095
Conversation
…ke async command handler and pass the cancellation token
@@ -346,5 +346,38 @@ public void Option_of_enum_can_limit_enum_members_as_valid_values() | |||
.Should() | |||
.BeEquivalentTo(new[] { $"Argument 'Fuschia' not recognized. Must be one of:\n\t'Red'\n\t'Green'" }); | |||
} | |||
|
|||
[Fact] | |||
public void Every_option_can_provide_a_handler_and_it_takes_precedence_over_command_handler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if two different options having handlers are both present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
ICommandHandler
withCliAction
Command.SetHandler
withCommand.SetAction
.Command.SetAction
do not need to return an int. In case somebody wants to reuturn an int, they need to implement their ownCliAction
type (pay for play)Action
property, but notSetAction
methods (no need to, as it should be rare to have active options and directives that don't need custom types)Contributes to #2071