Add error message support to task done

This commit is contained in:
Dheepak Krishnamurthy 2020-07-30 15:56:47 -06:00
parent ed3180ef2d
commit b706f34b53
2 changed files with 14 additions and 10 deletions

View file

@ -656,22 +656,20 @@ impl App {
}
}
pub fn task_done(&mut self) {
pub fn task_done(&mut self) -> Result<(), String> {
if self.tasks.len() == 0 {
return
return Ok(());
}
let selected = self.state.selected().unwrap_or_default();
let task_id = self.tasks[selected].id().unwrap_or_default();
let output = Command::new("task")
.arg("done")
.arg(format!("{}", task_id))
.output()
.expect(
&format!(
"Cannot run `task done` for task `{}`. Check documentation for more information",
task_id
)[..],
);
.output();
match output {
Ok(_) => Ok(()),
Err(_) => Err(format!("Cannot run `task done` for task `{}`. Check documentation for more information", task_id))
}
}
pub fn task_undo(&self) -> Result<(), String> {

View file

@ -54,7 +54,13 @@ fn main() -> Result<(), Box<dyn Error>> {
Key::Char('r') => app.update(),
Key::Down | Key::Char('j') => app.next(),
Key::Up | Key::Char('k') => app.previous(),
Key::Char('d') => app.task_done(),
Key::Char('d') => match app.task_done() {
Ok(_) => (),
Err(e) => {
app.mode = AppMode::TaskError;
app.error = e;
}
},
Key::Char('x') => match app.task_delete() {
Ok(_) => (),
Err(e) => {