tenseleyflow/gump / 88af94b

Browse files

allow gi with no args to show all entries

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
88af94bd457701d291a24ef09b10248b999cd247
Parents
4fc1adc
Tree
1ba1919

3 changed files

StatusFile+-
M Cargo.lock 1 1
M src/cli.rs 1 2
M src/cmd/query.rs 25 0
Cargo.lockmodified
@@ -290,7 +290,7 @@ dependencies = [
290290
 
291291
 [[package]]
292292
 name = "gump"
293
-version = "0.1.0"
293
+version = "0.2.0"
294294
 dependencies = [
295295
  "bincode",
296296
  "chrono",
src/cli.rsmodified
@@ -21,8 +21,7 @@ pub enum Commands {
2121
 
2222
     /// Query the database for matching directories
2323
     Query {
24
-        /// Search terms
25
-        #[arg(required = true)]
24
+        /// Search terms (optional with --all)
2625
         terms: Vec<String>,
2726
 
2827
         /// Show frecency scores
src/cmd/query.rsmodified
@@ -12,12 +12,37 @@ use super::Result;
1212
 pub fn run(terms: Vec<String>, show_score: bool, show_all: bool, cwd_mode: bool) -> Result<()> {
1313
     let mut matcher = Matcher::new();
1414
 
15
+    // Require terms unless --all is specified
16
+    if terms.is_empty() && !show_all {
17
+        eprintln!("gump: no search terms provided");
18
+        std::process::exit(1);
19
+    }
20
+
1521
     if cwd_mode {
1622
         return run_cwd_mode(&mut matcher, &terms, show_all);
1723
     }
1824
 
1925
     let db = Database::open()?;
2026
 
27
+    // If no terms, just list all entries sorted by frecency
28
+    if terms.is_empty() {
29
+        let mut entries: Vec<_> = db.entries().collect();
30
+        entries.sort_by(|a, b| b.1.frecency().partial_cmp(&a.1.frecency()).unwrap_or(std::cmp::Ordering::Equal));
31
+
32
+        if entries.is_empty() {
33
+            std::process::exit(1);
34
+        }
35
+
36
+        for (path, entry) in entries {
37
+            if show_score {
38
+                println!("{:>8.2}  {}", entry.frecency(), path.display());
39
+            } else {
40
+                println!("{}", path.display());
41
+            }
42
+        }
43
+        return Ok(());
44
+    }
45
+
2146
     // Collect paths with their frecency scores
2247
     let paths = db.entries().map(|(path, entry)| (path.as_path(), entry.frecency()));
2348