mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use crate::argparse::{DescriptionMod, Modification};
|
|
use failure::Fallible;
|
|
use taskchampion::{Replica, Status};
|
|
use termcolor::WriteColor;
|
|
|
|
pub(crate) fn execute<W: WriteColor>(
|
|
w: &mut W,
|
|
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();
|
|
writeln!(w, "added task {}", t.get_uuid())?;
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
use crate::invocation::test::*;
|
|
|
|
#[test]
|
|
fn test_add() {
|
|
let mut w = test_writer();
|
|
let mut replica = test_replica();
|
|
let modification = Modification {
|
|
description: DescriptionMod::Set(s!("my description")),
|
|
..Default::default()
|
|
};
|
|
execute(&mut w, &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);
|
|
|
|
assert_eq!(w.into_string(), format!("added task {}\n", task.get_uuid()));
|
|
}
|
|
}
|