mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-27 03:56:50 -06:00
fix(cli): render refuses an unknown option instead of writing it as a file (#235)
`deckcraft-cli render` took any argument it didn't recognise as the output path, so `render deck.pptx --help` rendered the slide into a file named `--help`, and a mistyped option was silently ignored. An argument starting with `-` that render doesn't know is now an error naming it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
688c7ef592
commit
30a5ee202d
@@ -127,6 +127,7 @@ fn render(args: &[String]) -> Result<(), String> {
|
||||
"--all" => all = true,
|
||||
"--edit" => edit = true,
|
||||
"--scale" => scale = it.next().and_then(|v| v.parse().ok()).ok_or("--scale needs a number")?,
|
||||
other if other.len() > 1 && other.starts_with('-') => return Err(format!("unknown render option `{other}`")),
|
||||
other
|
||||
if input.is_none()
|
||||
&& !sample
|
||||
@@ -278,3 +279,20 @@ fn mcp(args: &[String]) -> Result<(), String> {
|
||||
let stdin = std::io::stdin();
|
||||
server.serve(stdin.lock(), std::io::stdout()).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn render_refuses_an_unknown_option_instead_of_writing_it_as_a_file() {
|
||||
let out = std::env::temp_dir().join("deckcraft-cli-unknown-option.png");
|
||||
let _ = std::fs::remove_file(&out);
|
||||
for flag in ["--bogus", "-x", "--help"] {
|
||||
let args: Vec<String> = ["--sample", flag, &out.to_string_lossy()].iter().map(|a| a.to_string()).collect();
|
||||
let e = render(&args).unwrap_err();
|
||||
assert!(e.contains(&format!("unknown render option `{flag}`")), "{flag}: {e}");
|
||||
assert!(!out.exists(), "{flag}: rendered anyway");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user