dotnet / dotnet/command-line-api

Return values from actions on Options?

Open
#2,768 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

I'm trying to work out the "right" way to use this library, and a very simple use case that puzzles me is "detect that `--help` was invoked, so we can terminate the application after handling arguments", and it is not really clear to me how that should be done.

My first thought was that I should attach an Action to the `Option`, and have that action return non-zero, which would propagate out to the top-level `Invoke` call. Then I'd check the return value there, and if non-zero, terminate the application.

But if an `Option`'s action returns non-zero the return value just seems to be discarded.

I also noted that none of the documentation seems to use actions on `Option` objects, and that while actions on `Command` objects can just be lambdas, the ones on `Option` *have* to be a class derived from `CommandLineAction`. It kind of feels like Option actions are a bit half-baked? Are they not supposed to be used?

So two questions:

1. what is the point of setting actions on an `Option` object? (And what is the point of being able to return an integer from those actions?)
2. what is the _intended_ way to detect that --help was invoked so you can terminate the application?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.