Skip to content

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

cli: make --help print usage successfully

jnohclee-rgb0bfea22e1ba9
diff --git a/apps/filmcraft-cli/src/main.rs b/apps/filmcraft-cli/src/main.rs
index 13bebb85d..5597c9bb2 100644
--- a/apps/filmcraft-cli/src/main.rs
+++ b/apps/filmcraft-cli/src/main.rs
@@ -162,6 +162,10 @@ fn register_hardware_decoders() -> filmcraft_platform::Availability {
#[tokio::main]
async fn main() {
+ if matches!(std::env::args().nth(1).as_deref(), Some("--help")) {
+ print!("{HELP}");
+ return;
+ }
if matches!(std::env::args().nth(1).as_deref(), Some("--version" | "-V")) {
println!("filmcraft-cli {}", env!("CARGO_PKG_VERSION"));
return;
diff --git a/apps/filmcraft-cli/tests/cli.rs b/apps/filmcraft-cli/tests/cli.rs
index b7fedfc2c..2ff45e20b 100644
--- a/apps/filmcraft-cli/tests/cli.rs
+++ b/apps/filmcraft-cli/tests/cli.rs
@@ -24,6 +24,19 @@ 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);
+}
+
#[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 --git a/docs/agents.md b/docs/agents.md
index 2f02bc91f..3cc793912 100644
--- a/docs/agents.md
+++ b/docs/agents.md
@@ -165,7 +165,8 @@ 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.
```sh
filmcraft-cli commands razor # find ids (add --json for machine output)