Switch to a command-line API closer to TaskWarrior

* Use a parser (rather than clap) to process the command line
* Outline some generic support for filtering, reporting, modifying, etc.
* Break argument parsing strictly from invocation, to allow independent testing
This commit is contained in:
Dustin J. Mitchell
2020-12-03 06:58:10 +00:00
parent 87bb829634
commit 2c579b9f01
45 changed files with 1720 additions and 1072 deletions

View File

@@ -0,0 +1,45 @@
use crate::argparse::Report;
use crate::invocation::filtered_tasks;
use crate::table;
use failure::Fallible;
use prettytable::{cell, row, Table};
use taskchampion::Replica;
pub(crate) fn execute(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.printstd();
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::argparse::Filter;
use crate::invocation::cmd::test::test_replica;
#[test]
fn test_list() {
let mut replica = test_replica();
let report = Report {
filter: Filter {
..Default::default()
},
};
execute(&mut replica, report).unwrap();
// output is to stdout, so this is as much as we can check
}
}