Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea media: one argument holding several file names is those files, so a shell that does not split a variable gets its sheet instead of "File name too long" (#218)

shinyobjectzc1eaaa37f1ac
diff --git a/apps/media/src/lib.rs b/apps/media/src/lib.rs
index 768627ae..c2aad340 100644
--- a/apps/media/src/lib.rs
+++ b/apps/media/src/lib.rs
@@ -80,6 +80,17 @@ fn ext(p: &Path) -> String {
p.extension().map(|e| e.to_string_lossy().to_lowercase()).unwrap_or_default()
}
+/// One argument as the files it names. A shell that doesn't split a variable (zsh's `$FILES`) hands every name over as
+/// one argument, which read as a single path fails as "No such file", or past 255 bytes as "File name too long" (#218):
+/// an argument that isn't a file, but whose words each are, is those files.
+fn names(a: &str) -> Vec<String> {
+ let words: Vec<&str> = a.split_whitespace().collect();
+ if words.len() > 1 && !Path::new(a).exists() && words.iter().all(|w| Path::new(w).exists()) {
+ return words.into_iter().map(String::from).collect();
+ }
+ vec![a.to_string()]
+}
+
/// `--name value` flags (and `-o`), switches, and positional arguments.
fn parse(args: &[String]) -> (Vec<String>, BTreeMap<String, String>) {
let (mut pos, mut fl) = (Vec::new(), BTreeMap::new());
@@ -95,7 +106,7 @@ fn parse(args: &[String]) -> (Vec<String>, BTreeMap<String, String>) {
i += 1;
}
} else {
- pos.push(a.clone());
+ pos.extend(names(a));
}
i += 1;
}