| 1 | use crate::db::Database; |
| 2 | |
| 3 | use super::Result; |
| 4 | |
| 5 | /// List all directories in the database. |
| 6 | pub fn run(show_score: bool) -> Result<()> { |
| 7 | let db = Database::open()?; |
| 8 | |
| 9 | // Collect and sort by frecency (descending) |
| 10 | let mut entries: Vec<_> = db.entries().collect(); |
| 11 | entries.sort_by(|a, b| { |
| 12 | b.1.frecency() |
| 13 | .partial_cmp(&a.1.frecency()) |
| 14 | .unwrap_or(std::cmp::Ordering::Equal) |
| 15 | }); |
| 16 | |
| 17 | for (path, entry) in entries { |
| 18 | if show_score { |
| 19 | println!("{:>8.2} {}", entry.frecency(), path.display()); |
| 20 | } else { |
| 21 | println!("{}", path.display()); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | Ok(()) |
| 26 | } |
| 27 |