Switch to a command-line API closer to TaskWarrior
* Use a parser (rather than clap) to process the command line * Outline some generic support for filtering, reporting, modifying, etc. * Break argument parsing strictly from invocation, to allow independent testing
This commit is contained in:
33
cli/src/invocation/modify.rs
Normal file
33
cli/src/invocation/modify.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::argparse::{DescriptionMod, Modification};
|
||||
use failure::Fallible;
|
||||
use taskchampion::TaskMut;
|
||||
|
||||
/// Apply the given modification
|
||||
pub(super) fn apply_modification(task: &mut TaskMut, modification: &Modification) -> Fallible<()> {
|
||||
match modification.description {
|
||||
DescriptionMod::Set(ref description) => task.set_description(description.clone())?,
|
||||
DescriptionMod::Prepend(ref description) => {
|
||||
task.set_description(format!("{} {}", description, task.get_description()))?
|
||||
}
|
||||
DescriptionMod::Append(ref description) => {
|
||||
task.set_description(format!("{} {}", task.get_description(), description))?
|
||||
}
|
||||
DescriptionMod::None => {}
|
||||
}
|
||||
|
||||
if let Some(ref status) = modification.status {
|
||||
task.set_status(status.clone())?;
|
||||
}
|
||||
|
||||
if let Some(true) = modification.active {
|
||||
task.start()?;
|
||||
}
|
||||
|
||||
if let Some(false) = modification.active {
|
||||
task.stop()?;
|
||||
}
|
||||
|
||||
println!("modified task {}", task.get_uuid());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user