Skip to content

Commit f51e61a

Browse files
committed
Restore formatting from standard input
1 parent 2e552d8 commit f51e61a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/main.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
env, fs,
3-
io::{self, IsTerminal, Write},
3+
io::{self, IsTerminal, Read, Write},
44
path::PathBuf,
55
};
66

@@ -86,6 +86,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8686
safe: args.safe,
8787
};
8888

89+
if args.input.is_empty() {
90+
let mut input_content = String::new();
91+
io::stdin()
92+
.read_to_string(&mut input_content)
93+
.map_err(|error| format!("Failed to read from stdin: {}", error))?;
94+
95+
let formatted_content = format_gdscript_with_config(&input_content, &config)?;
96+
97+
if args.check {
98+
if input_content != formatted_content {
99+
eprintln!("The input passed via stdin is not formatted");
100+
std::process::exit(1);
101+
} else {
102+
println!("The input passed via stdin is already formatted");
103+
}
104+
} else {
105+
print!("{}", formatted_content);
106+
}
107+
108+
return Ok(());
109+
}
110+
89111
let input_gdscript_files: Vec<&PathBuf> = args
90112
.input
91113
.iter()

0 commit comments

Comments
 (0)