A file-based task manager

edit's tsk id arg is now optional

+14 -9
+11 -6
src/main.rs
··· 60 60 61 61 Edit { 62 62 #[arg(short = 't')] 63 - task_id: u32, 63 + task_id: Option<u32>, 64 64 }, 65 65 66 66 Completion { 67 67 #[arg(short = 's')] 68 68 shell: Shell, 69 69 }, 70 - 71 70 /* 72 71 Drop { 73 72 #[arg(short = 't')] ··· 161 160 workspace.swap_top().expect("swap to work"); 162 161 } 163 162 164 - fn command_edit(dir: PathBuf, id: u32) { 163 + fn command_edit(dir: PathBuf, id: Option<u32>) { 165 164 let workspace = Workspace::from_path(dir).expect("Unable to find .tsk dir"); 166 - let mut task = workspace.task(id.into()).expect("To read task from disk"); 167 - let new_content = 168 - open_editor(format!("{}\n\n{}", task.title.trim(), task.body.trim())).expect("Failed to edit file"); 165 + let mut task = if let Some(id) = id { 166 + workspace.task(id.into()).expect("To read task from disk") 167 + } else { 168 + let mut stack = workspace.read_stack(Some(1)).expect("to read stack"); 169 + let stack_item = stack.pop().expect("No tasks on stack."); 170 + workspace.task(stack_item.id).expect("couldn't read task") 171 + }; 172 + let new_content = open_editor(format!("{}\n\n{}", task.title.trim(), task.body.trim())) 173 + .expect("Failed to edit file"); 169 174 if let Some((title, body)) = new_content.split_once("\n") { 170 175 task.title = title.to_string(); 171 176 task.body = body.to_string();
+3 -3
src/stack.rs
··· 18 18 const INDEXFILE: &str = "index"; 19 19 20 20 pub(crate) struct StackItem { 21 - id: Id, 22 - title: String, 23 - modify_time: SystemTime, 21 + pub id: Id, 22 + pub title: String, 23 + pub modify_time: SystemTime, 24 24 } 25 25 26 26 impl Display for StackItem {