add a 'ta undo' subcommand

This commit is contained in:
Dustin J. Mitchell
2021-12-21 01:05:52 +00:00
parent 9d93928996
commit caa62ba9a0
4 changed files with 70 additions and 0 deletions

View File

@@ -8,4 +8,5 @@ pub(crate) mod info;
pub(crate) mod modify;
pub(crate) mod report;
pub(crate) mod sync;
pub(crate) mod undo;
pub(crate) mod version;

View File

@@ -0,0 +1,28 @@
use taskchampion::Replica;
use termcolor::WriteColor;
pub(crate) fn execute<W: WriteColor>(w: &mut W, replica: &mut Replica) -> Result<(), crate::Error> {
if replica.undo()? {
writeln!(w, "Undo successful.")?;
} else {
writeln!(w, "Nothing to undo.")?;
}
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::invocation::test::*;
use pretty_assertions::assert_eq;
#[test]
fn test_undo() {
let mut w = test_writer();
let mut replica = test_replica();
// Note that the details of the actual undo operation are tested thoroughly in the taskchampion crate
execute(&mut w, &mut replica).unwrap();
assert_eq!(&w.into_string(), "Nothing to undo.\n")
}
}

View File

@@ -90,6 +90,13 @@ pub(crate) fn invoke(command: Command, settings: Settings) -> Result<(), crate::
return cmd::sync::execute(&mut w, &mut replica, &settings, &mut server);
}
Command {
subcommand: Subcommand::Undo,
..
} => {
return cmd::undo::execute(&mut w, &mut replica);
}
// handled in the first match, but here to ensure this match is exhaustive
Command {
subcommand: Subcommand::Help { .. },