mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
add a 'ta undo' subcommand
This commit is contained in:
parent
9d93928996
commit
caa62ba9a0
4 changed files with 70 additions and 0 deletions
|
@ -59,6 +59,7 @@ pub(crate) enum Subcommand {
|
||||||
/// Basic operations without args
|
/// Basic operations without args
|
||||||
Gc,
|
Gc,
|
||||||
Sync,
|
Sync,
|
||||||
|
Undo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subcommand {
|
impl Subcommand {
|
||||||
|
@ -72,6 +73,7 @@ impl Subcommand {
|
||||||
Info::parse,
|
Info::parse,
|
||||||
Gc::parse,
|
Gc::parse,
|
||||||
Sync::parse,
|
Sync::parse,
|
||||||
|
Undo::parse,
|
||||||
// This must come last since it accepts arbitrary report names
|
// This must come last since it accepts arbitrary report names
|
||||||
Report::parse,
|
Report::parse,
|
||||||
)))(input)
|
)))(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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -814,4 +839,13 @@ mod test {
|
||||||
(&EMPTY[..], subcommand)
|
(&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 modify;
|
||||||
pub(crate) mod report;
|
pub(crate) mod report;
|
||||||
pub(crate) mod sync;
|
pub(crate) mod sync;
|
||||||
|
pub(crate) mod undo;
|
||||||
pub(crate) mod version;
|
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);
|
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
|
// handled in the first match, but here to ensure this match is exhaustive
|
||||||
Command {
|
Command {
|
||||||
subcommand: Subcommand::Help { .. },
|
subcommand: Subcommand::Help { .. },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue