From 56011be94c09828b104008cb7bf3a19177bc1631 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 16 Jun 2025 11:09:46 +0200 Subject: refactor(yt/select/selection_file): Migrate from `trinitry` to `shlex` shlex is better maintained, and _actually_ meant for this purpose . --- crates/yt/Cargo.toml | 2 +- crates/yt/src/select/selection_file/mod.rs | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'crates') 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>> { // 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)) } } -- cgit 1.4.1