diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-02-18 14:07:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-18 14:07:51 -0500 |
commit | c32e1daefc51441ba1349e9ed9e64fe2b17d7c23 (patch) | |
tree | 1d6d56066a1cc1760b867b36cef94716a698ead5 | |
parent | 1e56f733275cdd1406a4d796d17dbcbf48432a66 (diff) | |
parent | 6ce3ea4234633631eee3a756b782042fc777e438 (diff) | |
download | rbw-c32e1daefc51441ba1349e9ed9e64fe2b17d7c23.tar.gz rbw-c32e1daefc51441ba1349e9ed9e64fe2b17d7c23.zip |
Merge pull request #82 from Witcher01/master
fix: don't panic when piping
-rw-r--r-- | src/bin/rbw/commands.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 0068efd..1e522a7 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -1,4 +1,6 @@ use anyhow::Context as _; +use std::io; +use std::io::prelude::Write; const MISSING_CONFIG_HELP: &str = "Before using rbw, you must configure the email address you would like to \ @@ -530,7 +532,13 @@ pub fn list(fields: &[String]) -> anyhow::Result<()> { ), }) .collect(); - println!("{}", values.join("\t")); + + // write to stdout but don't panic when pipe get's closed + // this happens when piping stdout in a shell + match writeln!(&mut io::stdout(), "{}", values.join("\t")) { + Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => Ok(()), + res => res, + }?; } Ok(()) |