about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-16 11:09:46 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-16 11:09:46 +0200
commit56011be94c09828b104008cb7bf3a19177bc1631 (patch)
treec24c6276e512e7d779432da4e99bbe7f9b254c8e
parenttest(yt/cli): Test the CLI (diff)
downloadyt-56011be94c09828b104008cb7bf3a19177bc1631.zip
refactor(yt/select/selection_file): Migrate from `trinitry` to `shlex`
shlex is better maintained, and _actually_ meant for this purpose .
-rw-r--r--crates/yt/Cargo.toml2
-rw-r--r--crates/yt/src/select/selection_file/mod.rs24
2 files changed, 18 insertions, 8 deletions
diff --git a/crates/yt/Cargo.toml b/crates/yt/Cargo.toml
index 7289a4c..c6d8c30 100644
--- a/crates/yt/Cargo.toml
+++ b/crates/yt/Cargo.toml
@@ -37,8 +37,8 @@ sqlx = { version = "0.8.6", features = ["runtime-tokio", "sqlite"] }
 stderrlog = "0.6.0"
 tempfile = "3.20.0"
 toml = "0.8.23"
-trinitry = { version = "0.2.2" }
 xdg = "3.0.0"
+shlex = "1.3.0"
 bytes.workspace = true
 libmpv2.workspace = true
 log.workspace = true
diff --git a/crates/yt/src/select/selection_file/mod.rs b/crates/yt/src/select/selection_file/mod.rs
index abd26c4..f5e0531 100644
--- a/crates/yt/src/select/selection_file/mod.rs
+++ b/crates/yt/src/select/selection_file/mod.rs
@@ -11,22 +11,32 @@
 
 //! The data structures needed to express the file, which the user edits
 
-use anyhow::{Context, Result};
-use trinitry::Trinitry;
+use anyhow::{Result, bail};
+use shlex::Shlex;
 
 pub mod duration;
 
+/// # Panics
+/// If internal assertions fail.
 pub fn process_line(line: &str) -> Result<Option<Vec<String>>> {
     // Filter out comments and empty lines
     if line.starts_with('#') || line.trim().is_empty() {
         Ok(None)
     } else {
-        let tri = Trinitry::new(line).with_context(|| format!("Failed to parse line '{line}'"))?;
+        let split: Vec<_> = {
+            let mut shl = Shlex::new(line);
+            let res = shl.by_ref().collect();
 
-        let mut vec = Vec::with_capacity(tri.arguments().len() + 1);
-        vec.push(tri.command().to_owned());
-        vec.extend(tri.arguments().to_vec());
+            if shl.had_error {
+                bail!("Failed to parse line '{line}'")
+            }
 
-        Ok(Some(vec))
+            assert_eq!(shl.line_no, 1, "A unexpected newline appeared");
+            res
+        };
+
+        assert!(!split.is_empty());
+
+        Ok(Some(split))
     }
 }