mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
commit
cb1395ea32
22 changed files with 1312 additions and 469 deletions
|
@ -59,6 +59,7 @@ pub(crate) enum Subcommand {
|
|||
/// Basic operations without args
|
||||
Gc,
|
||||
Sync,
|
||||
Undo,
|
||||
}
|
||||
|
||||
impl Subcommand {
|
||||
|
@ -72,6 +73,7 @@ impl Subcommand {
|
|||
Info::parse,
|
||||
Gc::parse,
|
||||
Sync::parse,
|
||||
Undo::parse,
|
||||
// This must come last since it accepts arbitrary report names
|
||||
Report::parse,
|
||||
)))(input)
|
||||
|
@ -422,6 +424,29 @@ impl Sync {
|
|||
}
|
||||
}
|
||||
|
||||
struct Undo;
|
||||
|
||||
impl Undo {
|
||||
fn parse(input: ArgList) -> IResult<ArgList, Subcommand> {
|
||||
fn to_subcommand(_: &str) -> Result<Subcommand, ()> {
|
||||
Ok(Subcommand::Undo)
|
||||
}
|
||||
map_res(arg_matching(literal("undo")), to_subcommand)(input)
|
||||
}
|
||||
|
||||
fn get_usage(u: &mut usage::Usage) {
|
||||
u.subcommands.push(usage::Subcommand {
|
||||
name: "undo",
|
||||
syntax: "undo",
|
||||
summary: "Undo the latest change made on this replica",
|
||||
description: "
|
||||
Undo the latest change made on this replica.
|
||||
|
||||
Changes cannot be undone once they have been synchronized.",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
@ -814,4 +839,13 @@ mod test {
|
|||
(&EMPTY[..], subcommand)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_undo() {
|
||||
let subcommand = Subcommand::Undo;
|
||||
assert_eq!(
|
||||
Subcommand::parse(argv!["undo"]).unwrap(),
|
||||
(&EMPTY[..], subcommand)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
28
cli/src/invocation/cmd/undo.rs
Normal file
28
cli/src/invocation/cmd/undo.rs
Normal 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")
|
||||
}
|
||||
}
|
|
@ -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 { .. },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue