Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge origin/main into #357; check --help after Args::parse in cli()

Brandon Thomase3a00c3a2594
diff --cc apps/filmcraft-cli/src/main.rs
index 5597c9bb2,be104b30c..a363d40fb
--- a/apps/filmcraft-cli/src/main.rs
+++ b/apps/filmcraft-cli/src/main.rs
@@@ -172,10 -233,10 +233,16 @@@ async fn cli()
}
register_hardware_decoders();
let a = Args::parse(std::env::args().skip(1));
++ // `--help` anywhere (`filmcraft-cli --help`, `filmcraft-cli export --help`) prints the reference:
++ // the parser takes it as a flag option, so it never reaches the subcommand match.
++ if a.flag("--help") {
++ out!("{HELP}");
++ return;
++ }
let Some(cmd) = a.pos(0) else { usage("missing subcommand") };
match cmd {
- "help" | "--help" | "-h" => print!("{HELP}"),
- "version" => println!("filmcraft-cli {}", env!("CARGO_PKG_VERSION")),
- "help" | "--help" | "-h" => out!("{HELP}"),
++ "help" | "-h" => out!("{HELP}"),
+ "version" => outln!("filmcraft-cli {}", env!("CARGO_PKG_VERSION")),
"probe" => {
let path = a.pos(1).unwrap_or_else(|| usage("probe <media> [--image-sequence]"));
match probe::probe(path, a.flag("--image-sequence")) {
diff --cc apps/filmcraft-cli/tests/cli.rs
index 2ff45e20b,c3d3c979f..2736806e5
--- a/apps/filmcraft-cli/tests/cli.rs
+++ b/apps/filmcraft-cli/tests/cli.rs
@@@ -24,19 -24,6 +24,22 @@@ fn help_and_usage_errors()
assert_eq!(cli(&["exec", "file.newBin", "notkv"]).status.code(), Some(2));
}
+#[test]
+fn long_help_matches_help_command() {
+ let reference = cli(&["help"]);
+ assert!(reference.status.success());
+ let long_help = cli(&["--help"]);
+ assert!(long_help.status.success(), "--help failed: {}", String::from_utf8_lossy(&long_help.stderr));
+ assert_eq!(long_help.stdout, reference.stdout);
+ assert!(long_help.stderr.is_empty());
+ let short_help = cli(&["-h"]);
+ assert!(short_help.status.success());
+ assert_eq!(short_help.stdout, reference.stdout);
++ let sub_help = cli(&["export", "--help"]);
++ assert!(sub_help.status.success(), "export --help failed: {}", String::from_utf8_lossy(&sub_help.stderr));
++ assert_eq!(sub_help.stdout, reference.stdout);
+}
+
#[test]
fn probe_reports_mpeg_transport_and_program_streams() {
let Some(ffmpeg) = ["/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg", "/usr/bin/ffmpeg"].into_iter().find(|p| std::path::Path::new(p).exists()) else {
diff --cc docs/agents.md
index 3cc793912,39d53f770..07bb98798
--- a/docs/agents.md
+++ b/docs/agents.md
@@@ -165,8 -182,10 +182,11 @@@ Notes
## 2b. Command-line interface
Every command is also one shell call away. Options go anywhere; output is JSON; exit status is 0 on
-success, 1 when a command fails and 2 on a usage error. `filmcraft-cli help` prints the reference.
+success, 1 when a command fails and 2 on a usage error. `filmcraft-cli help`, `filmcraft-cli --help`
+and `filmcraft-cli -h` print the reference and exit successfully.
+ If the reader of stdout closes the pipe early (`filmcraft-cli commands | head`), the CLI drops the rest
+ of its output but still finishes the work, saves included, and the exit status still reports
+ failures; any other stdout write error is reported and makes the status 1.
```sh
filmcraft-cli commands razor # find ids (add --json for machine output)