add ids formatter
This commit is contained in:
parent
36e1ad8786
commit
5dd87616f8
|
@ -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()),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
use std::io::Write;
|
||||
|
||||
use crate::models::Entry;
|
||||
use crate::error::Result;
|
||||
|
||||
pub fn print_formatted<W: Write>(entries: Vec<Entry>, out: &mut W) -> Result<()> {
|
||||
Ok(writeln!(out, "{}", entries.into_iter().map(|e| e.id.to_string()).collect::<Vec<_>>().join(" "))?)
|
||||
}
|
Loading…
Reference in New Issue