Parse reports from config, with defaults
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::argparse::Filter;
|
||||
use crate::invocation::display_report;
|
||||
use config::Config;
|
||||
use failure::Fallible;
|
||||
use taskchampion::Replica;
|
||||
use termcolor::WriteColor;
|
||||
@@ -7,10 +8,11 @@ use termcolor::WriteColor;
|
||||
pub(crate) fn execute<W: WriteColor>(
|
||||
w: &mut W,
|
||||
replica: &mut Replica,
|
||||
settings: &Config,
|
||||
report_name: String,
|
||||
filter: Filter,
|
||||
) -> Fallible<()> {
|
||||
display_report(w, replica, report_name, filter)
|
||||
display_report(w, replica, settings, report_name, filter)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -29,11 +31,13 @@ mod test {
|
||||
// The function being tested is only one line long, so this is sort of an integration test
|
||||
// for display_report.
|
||||
|
||||
let settings = crate::settings::default_settings().unwrap();
|
||||
let report_name = "next".to_owned();
|
||||
let filter = Filter {
|
||||
..Default::default()
|
||||
};
|
||||
execute(&mut w, &mut replica, report_name, filter).unwrap();
|
||||
|
||||
execute(&mut w, &mut replica, &settings, report_name, filter).unwrap();
|
||||
assert!(w.into_string().contains("my task"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> {
|
||||
filter,
|
||||
},
|
||||
..
|
||||
} => return cmd::report::execute(&mut w, &mut replica, report_name, filter),
|
||||
} => return cmd::report::execute(&mut w, &mut replica, &settings, report_name, filter),
|
||||
|
||||
Command {
|
||||
subcommand: Subcommand::Info { filter, debug },
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use crate::argparse::{Condition, Filter};
|
||||
use crate::argparse::Filter;
|
||||
use crate::invocation::filtered_tasks;
|
||||
use crate::report::{Column, Property, Report, Sort, SortBy};
|
||||
use crate::report::{Column, Property, Report, SortBy};
|
||||
use crate::table;
|
||||
use failure::{bail, Fallible};
|
||||
use config::Config;
|
||||
use failure::{format_err, Fallible};
|
||||
use prettytable::{Row, Table};
|
||||
use std::cmp::Ordering;
|
||||
use taskchampion::{Replica, Status, Task, Uuid};
|
||||
use taskchampion::{Replica, Task, Uuid};
|
||||
use termcolor::WriteColor;
|
||||
|
||||
// pending #123, this is a non-fallible way of looking up a task's working set index
|
||||
@@ -102,61 +103,23 @@ fn task_column(task: &Task, column: &Column, working_set: &WorkingSet) -> String
|
||||
}
|
||||
}
|
||||
|
||||
fn get_report(report_name: String, filter: Filter) -> Fallible<Report> {
|
||||
let columns = vec![
|
||||
Column {
|
||||
label: "Id".to_owned(),
|
||||
property: Property::Id,
|
||||
},
|
||||
Column {
|
||||
label: "Description".to_owned(),
|
||||
property: Property::Description,
|
||||
},
|
||||
Column {
|
||||
label: "Active".to_owned(),
|
||||
property: Property::Active,
|
||||
},
|
||||
Column {
|
||||
label: "Tags".to_owned(),
|
||||
property: Property::Tags,
|
||||
},
|
||||
];
|
||||
let sort = vec![Sort {
|
||||
ascending: false,
|
||||
sort_by: SortBy::Uuid,
|
||||
}];
|
||||
let mut report = match report_name.as_ref() {
|
||||
"list" => Report {
|
||||
columns,
|
||||
sort,
|
||||
filter: Default::default(),
|
||||
},
|
||||
"next" => Report {
|
||||
columns,
|
||||
sort,
|
||||
filter: Filter {
|
||||
conditions: vec![Condition::Status(Status::Pending)],
|
||||
},
|
||||
},
|
||||
_ => bail!("Unknown report {:?}", report_name),
|
||||
};
|
||||
|
||||
// intersect the report's filter with the user-supplied filter
|
||||
report.filter = report.filter.intersect(filter);
|
||||
|
||||
Ok(report)
|
||||
}
|
||||
|
||||
pub(super) fn display_report<W: WriteColor>(
|
||||
w: &mut W,
|
||||
replica: &mut Replica,
|
||||
settings: &Config,
|
||||
report_name: String,
|
||||
filter: Filter,
|
||||
) -> Fallible<()> {
|
||||
let mut t = Table::new();
|
||||
let report = get_report(report_name, filter)?;
|
||||
let working_set = WorkingSet::new(replica)?;
|
||||
|
||||
// Get the report from settings
|
||||
let mut report = Report::from_config(settings.get(&format!("reports.{}", report_name))?)
|
||||
.map_err(|e| format_err!("report.{}{}", report_name, e))?;
|
||||
|
||||
// include any user-supplied filter conditions
|
||||
report.filter = report.filter.intersect(filter);
|
||||
|
||||
// Get the tasks from the filter
|
||||
let mut tasks: Vec<_> = filtered_tasks(replica, &report.filter)?.collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user