-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Make --stdio
the default for non-tty stdin
#84
Conversation
In the case where an incompatible flag is not set, `--stdio` will now be implied when standard input is not a terminal. This enables uses like ```bash smlfmt < IN > OUT ``` without needing an additional flag. The flag is currently left in, but I don't think it is necessary since users can simply do `cat | smlfmt` or similar if they'd really like to type over stdin at the terminal. This isn't currently a breaking change since `--stdio` hasn't been included in a release yet, either any option (e.g., the one implemented here, or removing the explicit `--stdio` flag entirely) maintains backwards compatibility. Another option would be to let `-` have specific meaning as an input file, designating stdin, which is common in Unix utilities, although this would presumably be a breaking change (currently this results in the usage text, so it might not be a big deal, but I'm not sure if it is cumbersome to implement with the current args parser).
Nice! One strange behavior is if we try to use stdin and a file input at the same time (the following output happens without any user interaction):
Can we add an error mode for asserting Desired output would be something like this:
|
Hmm. The described behaviour is what I would expect, otherwise you wouldn't be able to do e.g., Beyond that, I think there are implementation issues with a warning here. Since we detect if stdin is to be used as input on the basis of it not being a tty, it would seem to me that users running I can make the requested changes, but does it not simply reintroduce a new problem? |
Oh, I see the problem. Hmm. This makes me think that trying to detect non-terminal input doesn't work in general. Maybe the Unix-style placeholder Are there any examples of existing tools that detect non-terminal input like we're trying to do here? |
I think it makes sense for smlfmt to read stdin if no files are given. This is common for Unix tools (e.g. wc, cat, grep). |
The strange behavior IMO is that the interactive confirmation is being clobbered by the piped input. |
I've thought about it some more and I think I'm coming around haha. I was worried about getting an unintentional yes-confirmation through stdin, for overwriting a file. But this seems very unlikely... so it's probably fine. So, moving forward, perhaps we should just get rid of |
I don't see an issue with removing the flag. |
Sounds good. I'll go ahead and merge, and then make a note to remove the |
Standard input and output are used if no files are given and standard input is not connected to the terminal. Closes shwestrick#84
In the case where an incompatible flag is not set,
--stdio
will now be implied when standard input is not a terminal. This enables uses likewithout needing an additional flag.
The flag is currently left in, but I don't think it is necessary since users can simply do
cat | smlfmt
or similar if they'd really like to type over stdin at the terminal.This isn't currently a breaking change since
--stdio
hasn't been included in a release yet, either any option (e.g., the one implemented here, or removing the explicit--stdio
flag entirely) maintains backwards compatibility.Another option would be to let
-
have specific meaning as an input file, designating stdin, which is common in Unix utilities, although this would presumably be a breaking change (currently this results in the usage text, so it might not be a big deal, but I'm not sure if it is cumbersome to implement with the current args parser).I wasn't sure where changelog entries (if they do exist) should be put, so just let me know if there's a specific place/format and I can make one.
Closes #83.