From 2456012ed6a63264f3d6810026e1958368848026 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Mon, 20 Dec 2021 16:16:25 +0000 Subject: [PATCH] Fix application of modifications during 'ta add' --- cli/src/invocation/cmd/add.rs | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/cli/src/invocation/cmd/add.rs b/cli/src/invocation/cmd/add.rs index 47df033bc..1957e6dfc 100644 --- a/cli/src/invocation/cmd/add.rs +++ b/cli/src/invocation/cmd/add.rs @@ -1,18 +1,24 @@ use crate::argparse::{DescriptionMod, Modification}; +use crate::invocation::apply_modification; use taskchampion::{Replica, Status}; use termcolor::WriteColor; pub(crate) fn execute( w: &mut W, replica: &mut Replica, - modification: Modification, + mut modification: Modification, ) -> Result<(), crate::Error> { + // extract the description from the modification to handle it specially let description = match modification.description { DescriptionMod::Set(ref s) => s.clone(), _ => "(no description)".to_owned(), }; - let t = replica.new_task(Status::Pending, description).unwrap(); - writeln!(w, "added task {}", t.get_uuid())?; + modification.description = DescriptionMod::None; + + let task = replica.new_task(Status::Pending, description).unwrap(); + let mut task = task.into_mut(replica); + apply_modification(&mut task, &modification)?; + writeln!(w, "added task {}", task.get_uuid())?; Ok(()) } @@ -43,4 +49,28 @@ mod test { assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid())); } + + #[test] + fn test_add_with_tags() { + let mut w = test_writer(); + let mut replica = test_replica(); + let modification = Modification { + description: DescriptionMod::Set(s!("my description")), + add_tags: vec![tag!("tag1")].drain(..).collect(), + ..Default::default() + }; + execute(&mut w, &mut replica, modification).unwrap(); + + // check that the task appeared.. + let working_set = replica.working_set().unwrap(); + let task = replica + .get_task(working_set.by_index(1).unwrap()) + .unwrap() + .unwrap(); + assert_eq!(task.get_description(), "my description"); + assert_eq!(task.get_status(), Status::Pending); + assert!(task.has_tag(&tag!("tag1"))); + + assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid())); + } }