From bbf5c3b5292061eba039da3b5209b29ecc12fb04 Mon Sep 17 00:00:00 2001 From: liquidev Date: Sun, 29 Sep 2024 00:14:11 +0200 Subject: [PATCH] make fix cli accept a `-` argument to indicate reading from stdin I'm pretty sure we had this in the past... no? I have my helix set up to respect this argument, so it's weird it stopped working at some point. --- crates/treehouse/src/cli/fix.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/treehouse/src/cli/fix.rs b/crates/treehouse/src/cli/fix.rs index f0211ee..8a98967 100644 --- a/crates/treehouse/src/cli/fix.rs +++ b/crates/treehouse/src/cli/fix.rs @@ -134,7 +134,11 @@ pub fn fix_file( pub fn fix_file_cli(fix_args: FixArgs) -> anyhow::Result<()> { let utf8_filename = fix_args.file.to_string_lossy().into_owned(); - let file = std::fs::read_to_string(&fix_args.file).context("cannot read file to fix")?; + let file = if utf8_filename == "-" { + std::io::read_to_string(std::io::stdin().lock()).context("cannot read file from stdin")? + } else { + std::fs::read_to_string(&fix_args.file).context("cannot read file to fix")? + }; let mut treehouse = Treehouse::new(); let mut diagnostics = vec![];