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

Mechanism to detect Clikt's default input/output streams #272

Closed
mataha opened this issue Feb 7, 2021 · 0 comments
Closed

Mechanism to detect Clikt's default input/output streams #272

mataha opened this issue Feb 7, 2021 · 0 comments

Comments

@mataha
Copy link
Contributor

mataha commented Feb 7, 2021

I have an app that, by default, reads its input from stdin and writes its output to stdout. When it does that, I would like it to send a message to the user so that he doesn't sit mindlessly in front of a terminal, waiting for my app/gradle to finish initialization.

The way I used to solve this, while using option(...).inputStream().defaultStdin(), was absolutely disgusting and less than ideal:

private fun InputStream.isDefault(): Boolean =
    this::class.qualifiedName == "com.github.ajalt.clikt.parameters.types.UnclosableInputStream"

An alternative is to override every extension, create my own, identical stream proxy and compare it directly with an option (which is what I'm doing right now, but on a larger scale):

private fun InputStream.isDefault(): Boolean =
    this is UnclosableInputStream

Can such a mechanism be provided and exposed directly in Clikt?

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

No branches or pull requests

2 participants