implement generic report generation

This commit is contained in:
Dustin J. Mitchell
2020-12-26 04:07:36 +00:00
parent f264e74288
commit 00f548c713
7 changed files with 484 additions and 50 deletions

View File

@@ -1,8 +1,6 @@
use crate::argparse::Report;
use crate::invocation::filtered_tasks;
use crate::table;
use crate::invocation::display_report;
use failure::Fallible;
use prettytable::{cell, row, Table};
use taskchampion::Replica;
use termcolor::WriteColor;
@@ -11,29 +9,13 @@ pub(crate) fn execute<W: WriteColor>(
replica: &mut Replica,
report: Report,
) -> Fallible<()> {
let mut t = Table::new();
t.set_format(table::format());
t.set_titles(row![b->"id", b->"act", b->"description"]);
for task in filtered_tasks(replica, &report.filter)? {
let uuid = task.get_uuid();
let mut id = uuid.to_string();
if let Some(i) = replica.get_working_set_index(&uuid)? {
id = i.to_string();
}
let active = match task.is_active() {
true => "*",
false => "",
};
t.add_row(row![id, active, task.get_description()]);
}
t.print(w)?;
Ok(())
display_report(w, replica, &report)
}
#[cfg(test)]
mod test {
use super::*;
use crate::argparse::Filter;
use crate::argparse::{Column, Filter, Property};
use crate::invocation::test::*;
use taskchampion::Status;
@@ -47,6 +29,11 @@ mod test {
filter: Filter {
..Default::default()
},
columns: vec![Column {
label: "Description".to_owned(),
property: Property::Description,
}],
..Default::default()
};
execute(&mut w, &mut replica, report).unwrap();
assert!(w.into_string().contains("my task"));