A file-based task manager

Allow find args in other commands

+44 -27
+37 -25
src/main.rs
··· 79 79 80 80 /// Use fuzzy finding with `fzf` to search for a task 81 81 Find { 82 - /// Include the contents of tasks in the search criteria. 83 - #[arg(short = 'b', default_value_t = false)] 84 - search_body: bool, 85 - /// Include archived tasks in the search criteria. Combine with `-b` to include archived 86 - /// bodies in the search criteria. 87 - #[arg(short = 'a', default_value_t = false)] 88 - search_archived: bool, 89 - 90 - #[arg(short = 't', default_value_t = true)] 82 + #[command(flatten)] 83 + args: FindArgs, 84 + /// Whether to print the full TSK-ID (instead of just an integer) 85 + #[arg(short = 'F', default_value_t = true)] 91 86 full_id: bool, 92 87 }, 93 88 ··· 137 132 #[arg(short = 'r', value_name = "RELATIVE", default_value_t = 0)] 138 133 relative_id: u32, 139 134 140 - /// Use fuzzy finding to search for and select a task. 141 - /// Does not support searching task bodies or archived tasks. 135 + #[command(flatten)] 136 + find: Find, 137 + } 138 + 139 + /// Use fuzzy finding to search for and select a task. 140 + /// Does not support searching task bodies or archived tasks. 141 + #[derive(Args)] 142 + #[group(required = false, multiple = true)] 143 + struct Find { 142 144 #[arg(short = 'f', value_name = "FIND", default_value_t = false)] 143 145 find: bool, 146 + #[command(flatten)] 147 + args: FindArgs, 148 + } 149 + 150 + #[derive(Args)] 151 + #[group(required = false, multiple = false)] 152 + struct FindArgs { 153 + /// Include the contents of tasks in the search criteria. 154 + #[arg(short = 'b', default_value_t = false)] 155 + search_body: bool, 156 + /* TODO: implement this 157 + /// Include archived tasks in the search criteria. Combine with `-b` to include archived 158 + /// bodies in the search criteria. 159 + #[arg(short = 'a', default_value_t = false)] 160 + search_archived: bool, 161 + */ 144 162 } 145 163 146 164 impl From<TaskId> for TaskIdentifier { ··· 148 166 if let Some(id) = value.id.map(Id::from).or(value.tsk_id) { 149 167 TaskIdentifier::Id(id) 150 168 } else { 151 - if value.find { 152 - TaskIdentifier::Find 169 + if value.find.find { 170 + TaskIdentifier::Find { 171 + search_body: value.find.args.search_body, 172 + archived: false, 173 + } 153 174 } else { 154 175 TaskIdentifier::Relative(value.relative_id) 155 176 } ··· 168 189 Commands::Edit { task_id } => command_edit(dir, task_id), 169 190 Commands::Completion { shell } => command_completion(shell), 170 191 Commands::Drop => command_drop(dir), 171 - Commands::Find { 172 - full_id, 173 - search_body, 174 - search_archived, 175 - } => command_find(dir, full_id, search_body, search_archived), 192 + Commands::Find { args, full_id } => command_find(dir, full_id, args), 176 193 Commands::Rot => Workspace::from_path(dir).unwrap().rot(), 177 194 Commands::Tor => Workspace::from_path(dir).unwrap().tor(), 178 195 Commands::Reprioritize { task_id } => command_reprioritize(dir, task_id), ··· 277 294 Ok(()) 278 295 } 279 296 280 - fn command_find( 281 - dir: PathBuf, 282 - full_id: bool, 283 - search_body: bool, 284 - search_archived: bool, 285 - ) -> Result<()> { 286 - let id = Workspace::from_path(dir)?.search(None, search_body, search_archived)?; 297 + fn command_find(dir: PathBuf, full_id: bool, find_args: FindArgs) -> Result<()> { 298 + let id = Workspace::from_path(dir)?.search(None, find_args.search_body, false)?; 287 299 if let Some(id) = id { 288 300 if full_id { 289 301 println!("{id}");
+7 -2
src/workspace.rs
··· 50 50 pub enum TaskIdentifier { 51 51 Id(Id), 52 52 Relative(u32), 53 - Find, 53 + Find { search_body: bool, archived: bool }, 54 54 } 55 55 56 56 impl From<Id> for TaskIdentifier { ··· 99 99 let stack_item = stack.get(r as usize).ok_or(Error::NoTasks)?; 100 100 Ok(stack_item.id) 101 101 } 102 - TaskIdentifier::Find => self.search(None, false, false)?.ok_or(Error::NotSelected), 102 + TaskIdentifier::Find { 103 + search_body, 104 + archived, 105 + } => self 106 + .search(None, search_body, archived)? 107 + .ok_or(Error::NotSelected), 103 108 } 104 109 } 105 110