From bec7203240d920c81693657826cd23670290dab0 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Wed, 21 Feb 2024 13:18:22 +0100 Subject: [PATCH] it does not work actually --- src/main.rs | 11 +++++++---- tests/cli.rs | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/cli.rs diff --git a/src/main.rs b/src/main.rs index c694766..1f56fa6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,15 @@ use std::io::{self, prelude::*}; fn main() -> Result<(), io::Error> { + // TODO: check if stdin is empty and show usage let mut tty = std::fs::File::options() .write(true) .read(false) - .open("/dev/tty")?; - io::copy(&mut io::stdin(), &mut tty)?; - tty.flush()?; - io::copy(&mut io::stdin(), &mut io::stdout())?; + .open("/dev/tty") + .inspect_err(|err| eprintln!("{err}"))?; + // FIXME: only works with cargo run? + io::copy(&mut io::stdin(), &mut tty).inspect_err(|err| eprintln!("{err}"))?; + tty.flush().inspect_err(|err| eprintln!("{err}"))?; + io::copy(&mut io::stdin(), &mut io::stdout()).inspect_err(|err| eprintln!("{err}"))?; Ok(()) } diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..6671249 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,4 @@ +#[test] +fn pipe_echo_cat() { + todo!() +}