mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
add 'task modify' (that can only modify description right now)
This commit is contained in:
parent
b34ef34b2a
commit
a665ff83de
2 changed files with 67 additions and 2 deletions
|
@ -9,6 +9,7 @@ mod add;
|
|||
mod gc;
|
||||
mod info;
|
||||
mod list;
|
||||
mod modify;
|
||||
mod pending;
|
||||
mod sync;
|
||||
|
||||
|
@ -17,9 +18,10 @@ pub(crate) fn subcommands() -> Vec<Box<dyn SubCommand>> {
|
|||
vec![
|
||||
add::cmd(),
|
||||
gc::cmd(),
|
||||
list::cmd(),
|
||||
pending::cmd(),
|
||||
info::cmd(),
|
||||
list::cmd(),
|
||||
modify::cmd(),
|
||||
pending::cmd(),
|
||||
sync::cmd(),
|
||||
]
|
||||
}
|
||||
|
|
63
cli/src/cmd/modify.rs
Normal file
63
cli/src/cmd/modify.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use crate::cmd::shared;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand as ClapSubCommand};
|
||||
use failure::Fallible;
|
||||
|
||||
use crate::cmd::{ArgMatchResult, CommandInvocation};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Invocation {
|
||||
task: String,
|
||||
description: String,
|
||||
}
|
||||
|
||||
define_subcommand! {
|
||||
fn decorate_app<'a>(&self, app: App<'a, 'a>) -> App<'a, 'a> {
|
||||
app.subcommand(
|
||||
ClapSubCommand::with_name("modify").about("modifies a task")
|
||||
.arg(shared::task_arg())
|
||||
.arg(
|
||||
Arg::with_name("description")
|
||||
.help("task description")
|
||||
.required(true),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn arg_match<'a>(&self, matches: &ArgMatches<'a>) -> ArgMatchResult {
|
||||
match matches.subcommand() {
|
||||
("modify", Some(matches)) => ArgMatchResult::Ok(Box::new(Invocation {
|
||||
task: matches.value_of("task").unwrap().into(),
|
||||
description: matches.value_of("description").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.set_description(self.description.clone())?;
|
||||
println!("modified task {}", task.get_uuid());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_command() {
|
||||
with_subcommand_invocation!(
|
||||
vec!["task", "modify", "2", "foo bar"],
|
||||
|inv: &Invocation| {
|
||||
assert_eq!(inv.task, "2".to_string());
|
||||
assert_eq!(inv.description, "foo bar".to_string());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue