Skip to content

Return values from actions on Options? #2768

@jalfd

Description

@jalfd

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions