Navigate a directory full of directories, identifying repos and worktrees
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

short-circuit directory-only all scans

Refs: is-tree-scan-priority

rektide c8301b59 d28fa9b0

+68
+68
src/main.rs
··· 25 25 26 26 let paths = resolve_paths(&matches)?; 27 27 let explicit_format = matches.get_one::<String>("format").map(String::as_str); 28 + 29 + if should_short_circuit_directory_only(explicit_format) { 30 + return render_directory_only( 31 + &paths, 32 + matches.get_flag("json"), 33 + matches.get_flag("header"), 34 + ); 35 + } 36 + 28 37 let mut requested_mask = 29 38 resolve_requested_mask(explicit_format, registry.columns(), &registry)?; 30 39 registry.augment_requested_column_mask_from_args(&matches, &mut requested_mask)?; ··· 256 265 } 257 266 } 258 267 268 + fn should_short_circuit_directory_only(explicit_format: Option<&str>) -> bool { 269 + matches!( 270 + explicit_format.map(str::trim), 271 + Some("directory") | Some("{directory}") 272 + ) 273 + } 274 + 275 + fn render_directory_only(paths: &[PathBuf], as_json: bool, header: bool) -> PluginResult<()> { 276 + if as_json { 277 + let items: Vec<Value> = paths 278 + .iter() 279 + .map(|path| { 280 + let mut obj = serde_json::Map::new(); 281 + obj.insert( 282 + "directory".to_string(), 283 + Value::String(path.display().to_string()), 284 + ); 285 + Value::Object(obj) 286 + }) 287 + .collect(); 288 + 289 + let output = serde_json::to_string_pretty(&items).map_err(|err| err.to_string())?; 290 + println!("{output}"); 291 + return Ok(()); 292 + } 293 + 294 + if header { 295 + println!("directory"); 296 + } 297 + 298 + for path in paths { 299 + println!("{}", path.display()); 300 + } 301 + 302 + Ok(()) 303 + } 304 + 259 305 fn format_header(template: &str, separator: &str, columns: &ColumnCatalog) -> String { 260 306 let mut output = template.to_string(); 261 307 for column in &columns.columns { ··· 364 410 dirs.sort(); 365 411 dirs 366 412 } 413 + 414 + #[cfg(test)] 415 + mod tests { 416 + use super::should_short_circuit_directory_only; 417 + 418 + #[test] 419 + fn short_circuit_matches_directory_shorthand() { 420 + assert!(should_short_circuit_directory_only(Some("directory"))); 421 + } 422 + 423 + #[test] 424 + fn short_circuit_matches_directory_placeholder() { 425 + assert!(should_short_circuit_directory_only(Some("{directory}"))); 426 + } 427 + 428 + #[test] 429 + fn short_circuit_ignores_non_directory_formats() { 430 + assert!(!should_short_circuit_directory_only(Some("all"))); 431 + assert!(!should_short_circuit_directory_only(Some("{status} {directory}"))); 432 + assert!(!should_short_circuit_directory_only(None)); 433 + } 434 + }