aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvsyukov Denis Anatolyevich <[email protected]>2020-03-10 09:11:02 +0300
committerEvsyukov Denis Anatolyevich <[email protected]>2020-03-10 09:11:02 +0300
commitc0a2b5b4762f8e2693dfd97cb680d9f41ad81d5e (patch)
treeffe048b6207d934e78e1a57e3aca796c63d47038
parent[~] write_files (diff)
downloadt-c0a2b5b4762f8e2693dfd97cb680d9f41ad81d5e.tar.xz
t-c0a2b5b4762f8e2693dfd97cb680d9f41ad81d5e.zip
[+] check directory exist
-rw-r--r--src/main.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 7de513a..d2dc7e9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -57,10 +57,14 @@ Usage: t [-t DIR] [-l LIST] [options] [TEXT]";
.opt_str("t")
.unwrap_or_else(|| path.to_str().unwrap().to_string());
+ if !Path::new(&taskdir).exists() {
+ eprintln!("Directory does not exist: {}", taskdir);
+ return;
+ }
+ // read files
let mut taskpath = PathBuf::from(&taskdir);
taskpath.push(&taskfile);
- // read files
let mut donepath = taskpath.as_path().parent().unwrap().to_path_buf();
donepath.push(donefile);
@@ -94,6 +98,13 @@ Usage: t [-t DIR] [-l LIST] [options] [TEXT]";
write_files(tasks, done, taskpath, donepath, delete_empty);
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);
+ return;
+ }
// add new task
if !matches.free.is_empty() {