Skip to content

Commit 6e8e91c

Browse files
authored
fix(cli): fix help message starting with Error: (#116)
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.
1 parent 27fe4c5 commit 6e8e91c

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

fact/src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl FactConfig {
5353
)?;
5454

5555
// Once file configuration is handled, apply CLI arguments
56-
let args = FactCli::try_parse()?;
56+
let args = FactCli::parse();
5757
config.update(&args.to_config());
5858

5959
info!("{config:#?}");

fact/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub fn log_system_information() {
6363
}
6464

6565
pub async fn run(config: FactConfig) -> anyhow::Result<()> {
66+
// Log system information as early as possible so we have it
67+
// available in case of a crash
68+
log_system_information();
6669
let (run_tx, run_rx) = watch::channel(true);
6770
let (tx, rx) = broadcast::channel(100);
6871

fact/src/main.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ use fact::config::FactConfig;
33
#[tokio::main]
44
async fn main() -> anyhow::Result<()> {
55
fact::init_log()?;
6-
7-
// Log system information as early as possible so we have it
8-
// available in case of a crash
9-
fact::log_system_information();
10-
116
let config = FactConfig::new(&[
127
"/etc/stackrox/fact.yml",
138
"/etc/stackrox/fact.yaml",

0 commit comments

Comments
 (0)