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,34 @@
use crate::argparse::{DescriptionMod, Modification};
use failure::Fallible;
use taskchampion::{Replica, Status};
pub(crate) fn execute(replica: &mut Replica, modification: Modification) -> Fallible<()> {
let description = match modification.description {
DescriptionMod::Set(ref s) => s.clone(),
_ => "(no description)".to_owned(),
};
let t = replica.new_task(Status::Pending, description).unwrap();
println!("added task {}", t.get_uuid());
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::invocation::cmd::test::test_replica;
#[test]
fn test_add() {
let mut replica = test_replica();
let modification = Modification {
description: DescriptionMod::Set("my description".to_owned()),
..Default::default()
};
execute(&mut replica, modification).unwrap();
// check that the task appeared..
let task = replica.get_working_set_task(1).unwrap().unwrap();
assert_eq!(task.get_description(), "my description");
assert_eq!(task.get_status(), Status::Pending);
}
}