diff --git a/cli/src/cmd/delete.rs b/cli/src/cmd/delete.rs new file mode 100644 index 000000000..1d36833ec --- /dev/null +++ b/cli/src/cmd/delete.rs @@ -0,0 +1,52 @@ +use clap::{App, ArgMatches, SubCommand as ClapSubCommand}; +use failure::Fallible; +use taskchampion::Status; + +use crate::cmd::{shared, ArgMatchResult, CommandInvocation}; + +#[derive(Debug)] +struct Invocation { + task: String, +} + +define_subcommand! { + fn decorate_app<'a>(&self, app: App<'a, 'a>) -> App<'a, 'a> { + app.subcommand( + ClapSubCommand::with_name("delete") + .about("mark the given task as deleted") + .arg(shared::task_arg())) + } + + fn arg_match<'a>(&self, matches: &ArgMatches<'a>) -> ArgMatchResult { + match matches.subcommand() { + ("delete", Some(matches)) => ArgMatchResult::Ok(Box::new(Invocation { + task: matches.value_of("task").unwrap().into(), + })), + _ => ArgMatchResult::None, + } + } +} + +subcommand_invocation! { + fn run(&self, command: &CommandInvocation) -> Fallible<()> { + let mut replica = command.get_replica()?; + let task = shared::get_task(&mut replica, &self.task)?; + let mut task = task.into_mut(&mut replica); + task.stop()?; + task.set_status(Status::Deleted)?; + Ok(()) + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn parse_command() { + with_subcommand_invocation!(vec!["task", "delete", "1"], |inv: &Invocation| { + assert_eq!(inv.task, "1".to_string()); + }); + } +} + diff --git a/cli/src/cmd/mod.rs b/cli/src/cmd/mod.rs index c7b992b5c..17275c52e 100644 --- a/cli/src/cmd/mod.rs +++ b/cli/src/cmd/mod.rs @@ -7,6 +7,7 @@ mod shared; mod add; mod debug; +mod delete; mod done; mod gc; mod info; @@ -22,6 +23,7 @@ pub(crate) fn subcommands() -> Vec> { vec![ add::cmd(), debug::cmd(), + delete::cmd(), done::cmd(), gc::cmd(), info::cmd(),