-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(cli): Skip empty stdin in non tty environments #6714
Conversation
Alternative implementation. Please clarify which one you prefer. fn collect_stdin_input() -> Option<String> {
if atty::is(atty::Stream::Stdin) {
return None;
}
let mut lines = io::stdin()
.lock()
.lines()
.map(|line| line.expect("Not able to read stdin"));
if lines.next().is_some() {
Some(lines.collect::<Vec<String>>().join("\n"))
} else {
None
}
} |
I'm actually thinking if we should be explicit for tty like |
@kwonoj This is currently blocking aspect-build/rules_swc#88. Please let me know how to proceed. |
I would like to offer my own opinion. I find the way the cli works at the moment more intuitive and user-friendly. Reading from stdin is the default mode and a user does not need to set an option to enable stdin. This is the case for most unix command line programs. Why complicate things. The proposed change only verifies that the stdin buffer is not empty. |
@kwonoj Thoughts? |
I'm still intrigued to have an explicit option, however it doesn't have to be in this PR and probably think later. PR as-is probably ok to go for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reset ci
Thank you!
swc-bump:
- dbg-swc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated review comment generated by auto-rebase script
Fixes an issue where an error is thrown when using the compile command with a file input and a stdin of length zero.
The
atty::is
function only validates whether a stream source is connected to a tty. If no tty is connected, the function returns true and the stdin gets processed.swc/bindings/swc_cli/src/commands/compile.rs
Lines 244 to 246 in d8d9965
Example (in a non tty environment)
Actual behavior
Related