From c0e0e56900e3e707400b6964d5bb1b146e9e9edd Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Fri, 17 Oct 2025 10:30:45 +0200 Subject: [PATCH] fix(cli): fix help message starting with `Error: ` While testing #110, I realised when running fact with `--help` the usage message would start with the `Error: ` string, like this: ``` Error: Usage: fact [OPTIONS] [URL] ``` This is due to us incorrectly using the `try_parse` method on our CLI configuration and propagating the error up. Instead, we can call `parse` and the application will come to a full stop whenever a wrong argument is found or the `-h` or `--help` arguments are provided, showing the correct usage message. The change also makes it so configuration is parsed before dumping system information. This is more of a nitpick, having the system information dumped before the usage message is not a big deal, but I think this way makes more sense. Additionally, errors parsing configuration and CLI arguments _should not_ be caused by the actual system, so I don't think we are losing anything. --- fact/src/config/mod.rs | 2 +- fact/src/lib.rs | 3 +++ fact/src/main.rs | 5 ----- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fact/src/config/mod.rs b/fact/src/config/mod.rs index 61ed9886..9922584e 100644 --- a/fact/src/config/mod.rs +++ b/fact/src/config/mod.rs @@ -53,7 +53,7 @@ impl FactConfig { )?; // Once file configuration is handled, apply CLI arguments - let args = FactCli::try_parse()?; + let args = FactCli::parse(); config.update(&args.to_config()); info!("{config:#?}"); diff --git a/fact/src/lib.rs b/fact/src/lib.rs index 21781a8b..bcc1a08a 100644 --- a/fact/src/lib.rs +++ b/fact/src/lib.rs @@ -63,6 +63,9 @@ pub fn log_system_information() { } pub async fn run(config: FactConfig) -> anyhow::Result<()> { + // Log system information as early as possible so we have it + // available in case of a crash + log_system_information(); let (run_tx, run_rx) = watch::channel(true); let (tx, rx) = broadcast::channel(100); diff --git a/fact/src/main.rs b/fact/src/main.rs index 7f1efb81..8b5a1a1f 100644 --- a/fact/src/main.rs +++ b/fact/src/main.rs @@ -3,11 +3,6 @@ use fact::config::FactConfig; #[tokio::main] async fn main() -> anyhow::Result<()> { fact::init_log()?; - - // Log system information as early as possible so we have it - // available in case of a crash - fact::log_system_information(); - let config = FactConfig::new(&[ "/etc/stackrox/fact.yml", "/etc/stackrox/fact.yaml",