Merge pull request #73 from djmitche/issue72
Add done and delete subcommands
This commit is contained in:
51
cli/src/cmd/delete.rs
Normal file
51
cli/src/cmd/delete.rs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
51
cli/src/cmd/done.rs
Normal file
51
cli/src/cmd/done.rs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
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("done")
|
||||||
|
.about("finish the given task (status Completed)")
|
||||||
|
.arg(shared::task_arg()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn arg_match<'a>(&self, matches: &ArgMatches<'a>) -> ArgMatchResult {
|
||||||
|
match matches.subcommand() {
|
||||||
|
("done", 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::Completed)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_command() {
|
||||||
|
with_subcommand_invocation!(vec!["task", "done", "1"], |inv: &Invocation| {
|
||||||
|
assert_eq!(inv.task, "1".to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ use crate::table;
|
|||||||
use clap::{App, ArgMatches, SubCommand as ClapSubCommand};
|
use clap::{App, ArgMatches, SubCommand as ClapSubCommand};
|
||||||
use failure::Fallible;
|
use failure::Fallible;
|
||||||
use prettytable::{cell, row, Table};
|
use prettytable::{cell, row, Table};
|
||||||
|
use taskchampion::Status;
|
||||||
|
|
||||||
use crate::cmd::{ArgMatchResult, CommandInvocation};
|
use crate::cmd::{ArgMatchResult, CommandInvocation};
|
||||||
|
|
||||||
@@ -28,6 +29,9 @@ subcommand_invocation! {
|
|||||||
t.set_format(table::format());
|
t.set_format(table::format());
|
||||||
t.set_titles(row![b->"id", b->"act", b->"description"]);
|
t.set_titles(row![b->"id", b->"act", b->"description"]);
|
||||||
for (uuid, task) in replica.all_tasks().unwrap() {
|
for (uuid, task) in replica.all_tasks().unwrap() {
|
||||||
|
if task.get_status() != Status::Pending {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let mut id = uuid.to_string();
|
let mut id = uuid.to_string();
|
||||||
if let Some(i) = replica.get_working_set_index(&uuid)? {
|
if let Some(i) = replica.get_working_set_index(&uuid)? {
|
||||||
id = i.to_string();
|
id = i.to_string();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ mod shared;
|
|||||||
|
|
||||||
mod add;
|
mod add;
|
||||||
mod debug;
|
mod debug;
|
||||||
|
mod delete;
|
||||||
|
mod done;
|
||||||
mod gc;
|
mod gc;
|
||||||
mod info;
|
mod info;
|
||||||
mod list;
|
mod list;
|
||||||
@@ -21,6 +23,8 @@ pub(crate) fn subcommands() -> Vec<Box<dyn SubCommand>> {
|
|||||||
vec![
|
vec![
|
||||||
add::cmd(),
|
add::cmd(),
|
||||||
debug::cmd(),
|
debug::cmd(),
|
||||||
|
delete::cmd(),
|
||||||
|
done::cmd(),
|
||||||
gc::cmd(),
|
gc::cmd(),
|
||||||
info::cmd(),
|
info::cmd(),
|
||||||
list::cmd(),
|
list::cmd(),
|
||||||
|
|||||||
@@ -135,8 +135,10 @@ impl Replica {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a task. The task must exist. Note that this is different from setting status to
|
/// Delete a task. The task must exist. Note that this is different from setting status to
|
||||||
/// Deleted; this is the final purge of the task.
|
/// Deleted; this is the final purge of the task. This is not a public method as deletion
|
||||||
pub fn delete_task(&mut self, uuid: &Uuid) -> Fallible<()> {
|
/// should only occur through expiration.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn delete_task(&mut self, uuid: &Uuid) -> Fallible<()> {
|
||||||
// check that it already exists; this is a convenience check, as the task may already exist
|
// check that it already exists; this is a convenience check, as the task may already exist
|
||||||
// when this Create operation is finally sync'd with operations from other replicas
|
// when this Create operation is finally sync'd with operations from other replicas
|
||||||
if self.taskdb.get_task(&uuid)?.is_none() {
|
if self.taskdb.get_task(&uuid)?.is_none() {
|
||||||
|
|||||||
Reference in New Issue
Block a user