From 5dd87616f822f07bfb7d42ca3c1bb7c97cfa620e Mon Sep 17 00:00:00 2001 From: Abraham Toriz Date: Wed, 28 Jul 2021 21:16:03 -0500 Subject: [PATCH] add ids formatter --- src/formatters.rs | 4 ++++ src/formatters/ids.rs | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/formatters/ids.rs diff --git a/src/formatters.rs b/src/formatters.rs index cc95377..58d8af9 100644 --- a/src/formatters.rs +++ b/src/formatters.rs @@ -10,6 +10,7 @@ use crate::models::Entry; pub mod text; pub mod csv; pub mod json; +pub mod ids; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] @@ -17,6 +18,7 @@ pub enum Formatter { Text, Csv, Json, + Ids, Custom(String), } @@ -38,6 +40,7 @@ impl Formatter { Formatter::Text => text::print_formatted(entries, out, now, ids)?, Formatter::Csv => csv::print_formatted(entries, out, ids)?, Formatter::Json => json::print_formatted(entries, out)?, + Formatter::Ids => ids::print_formatted(entries, out)?, Formatter::Custom(name) => { panic!("attempted custom formatter with name {} which is not implemented", name); } @@ -57,6 +60,7 @@ impl FromStr for Formatter { "text" => Formatter::Text, "csv" => Formatter::Csv, "json" => Formatter::Json, + "ids" => Formatter::Ids, custom_format => Formatter::Custom(custom_format.into()), }) } diff --git a/src/formatters/ids.rs b/src/formatters/ids.rs new file mode 100644 index 0000000..9e9da00 --- /dev/null +++ b/src/formatters/ids.rs @@ -0,0 +1,8 @@ +use std::io::Write; + +use crate::models::Entry; +use crate::error::Result; + +pub fn print_formatted(entries: Vec, out: &mut W) -> Result<()> { + Ok(writeln!(out, "{}", entries.into_iter().map(|e| e.id.to_string()).collect::>().join(" "))?) +}