use itertools to group entries by sheet
This commit is contained in:
parent
79afcaed89
commit
06ed433e15
|
@ -130,6 +130,12 @@ version = "0.4.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fallible-iterator"
|
name = "fallible-iterator"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -180,6 +186,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.81"
|
version = "0.2.81"
|
||||||
|
@ -404,6 +419,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"itertools",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -15,6 +15,7 @@ dirs = "*"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
|
itertools = "0.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "0.7.2"
|
pretty_assertions = "0.7.2"
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::str::FromStr;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::models::Entry;
|
use crate::models::Entry;
|
||||||
|
@ -16,17 +17,25 @@ pub enum Formatter {
|
||||||
impl Formatter {
|
impl Formatter {
|
||||||
pub fn print_formatted<W: Write>(&self, entries: Vec<Entry>, out: &mut W) -> error::Result<()> {
|
pub fn print_formatted<W: Write>(&self, entries: Vec<Entry>, out: &mut W) -> error::Result<()> {
|
||||||
match &self {
|
match &self {
|
||||||
Formatter::Text => {
|
Formatter::Text => self.print_formatted_text(entries, out)?,
|
||||||
for entry in entries {
|
|
||||||
writeln!(out, "{:?}", entry)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Formatter::Custom(name) => {
|
Formatter::Custom(name) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print in the default text format. Assume entries are sorted by sheet and
|
||||||
|
/// then by start
|
||||||
|
fn print_formatted_text<W: Write>(&self, entries: Vec<Entry>, out: &mut W) -> error::Result<()> {
|
||||||
|
let grouped_entries = entries.into_iter().group_by(|e| e.sheet.to_string());
|
||||||
|
|
||||||
|
for (key, group) in grouped_entries.into_iter() {
|
||||||
|
writeln!(out, "Timesheet: {}", key)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Formatter {
|
impl FromStr for Formatter {
|
||||||
|
|
Loading…
Reference in New Issue