Add confirmation prompts for modifications of lots of tasks

This commit is contained in:
Dustin J. Mitchell
2021-06-07 14:57:57 -04:00
parent 31ff46bee6
commit 0de4fc1dee
7 changed files with 170 additions and 24 deletions

View File

@@ -0,0 +1,22 @@
use dialoguer::Confirm;
use taskchampion::{Replica, Task};
/// Print the prompt and ask the user to answer yes or no. If input is not from a terminal, the
/// answer is assumed to be true.
pub(super) fn confirm<S: Into<String>>(prompt: S) -> anyhow::Result<bool> {
if !atty::is(atty::Stream::Stdin) {
return Ok(true);
}
Ok(Confirm::new().with_prompt(prompt).interact()?)
}
/// Summarize a task in a single line
pub(super) fn summarize_task(replica: &mut Replica, task: &Task) -> anyhow::Result<String> {
let ws = replica.working_set()?;
let uuid = task.get_uuid();
if let Some(id) = ws.by_uuid(uuid) {
Ok(format!("{} - {}", id, task.get_description()))
} else {
Ok(format!("{} - {}", uuid, task.get_description()))
}
}