Skip to content
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

Expose val command: Command[IO[ExitCode]] in CommandIOApp #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lolgab
Copy link

@lolgab lolgab commented May 29, 2024

If you want to show the help when handling errors in the IO part of the app, you need to call .showHelp on the command instance. This is not possible with CommandIOApp since it doesn't expose the app but creates and uses it on the fly.
This PR adds a val command: Command[IO[ExitCode]] to CommandIOApp so you can have similar errors to the errors printed by validate but when handling IO errors in the app with .handleErrorWith in the application logic.

This came out as a problem while implementing Quafadas/live-server-scala-cli-js#17 and the current workaround is to copy paste the --version option from CommandIOApp and move to IOApp

If you want to show the help when handling errors in the `IO` part of
the app, you need to call `.showHelp` on the command instance.
This is not possible with `CommandIOApp` since it doesn't expose the
app but creates and uses it on the fly.
This PR adds a `val command: Command[IO[ExitCode]]` to `CommandIOApp`
so you can have similar errors to the errors printed by `validate` but
when handling IO errors in the app with `.handleErrorWith` in the
application logic
@bkirwi
Copy link
Owner

bkirwi commented Jun 20, 2024

Thanks for the contribution!

I suspect this is a breaking change, but I'll need to confirm. (Offhand this sort of thing is usually not enough to prompt a breaking release, though I do hang on to minorly-breaking PRs for whenever that time does come.)

Generally the thinking has been that IO errors are not validation errors, and thus not the sort of thing you print help output for, so it was fine that it was annoying to overlap the layers in that way. If you've got a specific example where that's not the case I'd be interested to know about it though!

@bkirwi
Copy link
Owner

bkirwi commented Jun 21, 2024

Another way to solve this problem would be to mimic how CommandApp works, and add a second constructor which takes a command directly. Then you'd be able to construct it separately and thread it through wherever it's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants