Skip to content

Conversation

@Molter73
Copy link
Collaborator

@Molter73 Molter73 commented Oct 17, 2025

Description

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.

Checklist

  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

Manually run cargo run -- -h before the change:

   Compiling fact v0.2.0-dev (/home/mmoltras/go/src/github.com/molter73/fact/fact)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.07s
     Running `target/debug/fact -h`
[INFO  2025-10-17T08:40:46Z] fact version: 0.1.x-69-g27fe4c5074
[INFO  2025-10-17T08:40:46Z] OS: Fedora Linux 42 (Workstation Edition)
[INFO  2025-10-17T08:40:46Z] Kernel version: 6.16.10-200.fc42.x86_64
[INFO  2025-10-17T08:40:46Z] Architecture: x86_64
[INFO  2025-10-17T08:40:46Z] Hostname: mmoltras-thinkpadp1gen5.remote.csb
Error: Usage: fact [OPTIONS] [URL]

Arguments:
  [URL]  URL to forward the packages to [env: FACT_URL=]

Options:
  -p, --paths [<PATHS>...]           List of paths to be monitored [env: FACT_PATHS=]
  -c, --certs <CERTS>                Directory holding the mTLS certificates and keys [env: FACT_CERTS=]
  -e, --endpoint <ENDPOINT>          The port to bind for all exposed endpoints [env: FACT_ENDPOINT=]
      --expose-metrics               Whether prometheus metrics should be collected and exposed [env: FACT_EXPOSE_METRICS=]
      --health-check                 Whether a small health_check probe should be run [env: FACT_HEALTH_CHECK=]
      --skip-pre-flight              Whether to perform a pre flight check [env: FACT_SKIP_PRE_FLIGHT=]
  -j, --json                         Force events to be output as JSON to stdout [env: FACT_JSON=]
  -r, --ringbuf-size <RINGBUF_SIZE>  Sets the size of the ringbuffer to be used in kilobytes [env: FACT_RINGBUF_SIZE=]
  -h, --help                         Print help (see more with '--help')
  -V, --version                      Print version

After the change:

   Compiling fact v0.2.0-dev (/home/mmoltras/go/src/github.com/molter73/fact/fact)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.35s
     Running `target/debug/fact -h`
Usage: fact [OPTIONS] [URL]

Arguments:
  [URL]  URL to forward the packages to [env: FACT_URL=]

Options:
  -p, --paths [<PATHS>...]           List of paths to be monitored [env: FACT_PATHS=]
  -c, --certs <CERTS>                Directory holding the mTLS certificates and keys [env: FACT_CERTS=]
  -e, --endpoint <ENDPOINT>          The port to bind for all exposed endpoints [env: FACT_ENDPOINT=]
      --expose-metrics               Whether prometheus metrics should be collected and exposed [env: FACT_EXPOSE_METRICS=]
      --health-check                 Whether a small health_check probe should be run [env: FACT_HEALTH_CHECK=]
      --skip-pre-flight              Whether to perform a pre flight check [env: FACT_SKIP_PRE_FLIGHT=]
  -j, --json                         Force events to be output as JSON to stdout [env: FACT_JSON=]
  -r, --ringbuf-size <RINGBUF_SIZE>  Sets the size of the ringbuffer to be used in kilobytes [env: FACT_RINGBUF_SIZE=]
  -h, --help                         Print help (see more with '--help')
  -V, --version                      Print version

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.
@Molter73 Molter73 merged commit 6e8e91c into main Oct 17, 2025
18 of 19 checks passed
@Molter73 Molter73 deleted the mauro/fix/help-message branch October 17, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants