* 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
34 lines
1.0 KiB
Rust
34 lines
1.0 KiB
Rust
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(())
|
|
}
|