diff options
| author | Evsyukov Denis Anatolyevich <[email protected]> | 2020-03-10 09:20:00 +0300 |
|---|---|---|
| committer | Evsyukov Denis Anatolyevich <[email protected]> | 2020-03-10 09:20:00 +0300 |
| commit | 4954473947928e2528c41530a359076f07e48781 (patch) | |
| tree | 66e7fb51bb98e6cae819e5002fe825e96bfdedbd /src | |
| parent | [+] check directory exist (diff) | |
| download | t-4954473947928e2528c41530a359076f07e48781.tar.xz t-4954473947928e2528c41530a359076f07e48781.zip | |
[+] remove and edit tasks
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index d2dc7e9..8ee376a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,16 +93,43 @@ Usage: t [-t DIR] [-l LIST] [options] [TEXT]"; if matches.opt_present("f") { let task = matches.opt_str("f").unwrap(); let key = matches.opt_str("f").unwrap(); - done.insert(task, tasks.get(&key).unwrap().to_string()); - tasks.remove(&key); - write_files(tasks, done, taskpath, donepath, delete_empty); + if tasks.contains_key(&task) { + done.insert(task, tasks.get(&key).unwrap().to_string()); + tasks.remove(&key); + write_files(tasks, done, taskpath, donepath, delete_empty); + } else { + println!("Task does not exist: {}", &task); + } return; } // remove task if matches.opt_present("r") { - let task = matches.opt_str("f").unwrap(); - tasks.remove(&task); - write_files(tasks, done, taskpath, donepath, delete_empty); + let task = matches.opt_str("r").unwrap(); + if tasks.contains_key(&task) { + tasks.remove(&task); + write_files(tasks, done, taskpath, donepath, delete_empty); + } else { + println!("Task does not exist: {}", &task); + } + return; + } + + // edit task + if matches.opt_present("e") { + let task = matches.opt_str("e").unwrap(); + if tasks.contains_key(&task) { + if !matches.free.is_empty() { + tasks.remove(&task); + let task = matches.free.join(" "); + tasks.insert(hash(&task), task); + write_files(tasks, done, taskpath, donepath, delete_empty); + } else { + println!("Please provide text for new task."); + return; + } + } else { + println!("Task does not exist: {}", &task); + } return; } |