A file-based task manager

ADD: rot/tor

+56 -14
+20 -14
src/main.rs
··· 87 88 /// Drops the task on the top of the stack and archives it. 89 Drop, 90 } 91 92 #[derive(Args)] ··· 113 114 fn main() { 115 let cli = Cli::parse(); 116 match cli.command { 117 - Commands::Init => command_init(cli.dir.unwrap_or(default_dir())), 118 - Commands::Push { edit, body, title } => { 119 - command_push(cli.dir.unwrap_or(default_dir()), edit, body, title) 120 - } 121 - Commands::List { all, count } => command_list(cli.dir.unwrap_or(default_dir()), all, count), 122 - Commands::Swap => command_swap(cli.dir.unwrap_or(default_dir())), 123 - Commands::Edit { task_id } => command_edit(cli.dir.unwrap_or(default_dir()), task_id), 124 Commands::Completion { shell } => command_completion(shell), 125 - Commands::Drop => command_drop(cli.dir.unwrap_or(default_dir())), 126 - Commands::Find { 127 - search_body, 128 - search_archived, 129 - } => command_search(cli.dir.unwrap_or(default_dir())), 130 } 131 } 132 ··· 222 if let Some(id) = Workspace::from_path(dir) 223 .expect("Unable to find .tsk dir") 224 .drop() 225 - .expect("Unable to drop task.") { 226 - println!("Dropped {id}") 227 } 228 } 229 ··· 236 eprintln!("No task to drop.") 237 } 238 }
··· 87 88 /// Drops the task on the top of the stack and archives it. 89 Drop, 90 + 91 + Rot, 92 + Tor, 93 } 94 95 #[derive(Args)] ··· 116 117 fn main() { 118 let cli = Cli::parse(); 119 + let dir = cli.dir.unwrap_or(default_dir()); 120 match cli.command { 121 + Commands::Init => command_init(dir), 122 + Commands::Push { edit, body, title } => command_push(dir, edit, body, title), 123 + Commands::List { all, count } => command_list(dir, all, count), 124 + Commands::Swap => command_swap(dir), 125 + Commands::Edit { task_id } => command_edit(dir, task_id), 126 Commands::Completion { shell } => command_completion(shell), 127 + Commands::Drop => command_drop(dir), 128 + Commands::Find { .. } => command_search(dir), 129 + Commands::Rot => Workspace::from_path(dir).unwrap().rot().unwrap(), 130 + Commands::Tor => Workspace::from_path(dir).unwrap().tor().unwrap(), 131 } 132 } 133 ··· 223 if let Some(id) = Workspace::from_path(dir) 224 .expect("Unable to find .tsk dir") 225 .drop() 226 + .expect("Unable to drop task.") 227 + { 228 + println!("Dropped {id}") 229 } 230 } 231 ··· 238 eprintln!("No task to drop.") 239 } 240 } 241 + 242 + fn command_rot(dir: PathBuf) { 243 + Workspace::from_path(dir).unwrap().rot().unwrap(); 244 + }
+36
src/workspace.rs
··· 147 Ok(()) 148 } 149 150 pub fn drop(&self) -> Result<Option<Id>> { 151 let mut stack = self.read_stack()?; 152 if let Some(stack_item) = stack.pop() {
··· 147 Ok(()) 148 } 149 150 + pub fn rot(&self) -> Result<()> { 151 + let mut stack = TaskStack::from_tskdir(&self.path)?; 152 + let top = stack.pop(); 153 + let second = stack.pop(); 154 + let third = stack.pop(); 155 + 156 + if top.is_none() || second.is_none() || third.is_none() { 157 + return Ok(()) 158 + } 159 + 160 + stack.push(second.unwrap()); 161 + stack.push(top.unwrap()); 162 + stack.push(third.unwrap()); 163 + stack.save()?; 164 + Ok(()) 165 + } 166 + 167 + /// The inverse of tor. Pushes the top item behind the second item, shifting #2 and #3 to #1 168 + /// and #2 respectively. 169 + pub fn tor(&self) -> Result<()> { 170 + let mut stack = TaskStack::from_tskdir(&self.path)?; 171 + let top = stack.pop(); 172 + let second = stack.pop(); 173 + let third = stack.pop(); 174 + 175 + if top.is_none() || second.is_none() || third.is_none() { 176 + return Ok(()) 177 + } 178 + 179 + stack.push(top.unwrap()); 180 + stack.push(third.unwrap()); 181 + stack.push(second.unwrap()); 182 + stack.save()?; 183 + Ok(()) 184 + } 185 + 186 pub fn drop(&self) -> Result<Option<Id>> { 187 let mut stack = self.read_stack()?; 188 if let Some(stack_item) = stack.pop() {