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:
Dustin J. Mitchell
2020-12-03 06:58:10 +00:00
parent 87bb829634
commit 2c579b9f01
45 changed files with 1720 additions and 1072 deletions

View 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(())
}