Skip to content

fix: do not require config file for --version and --help - #459

Open
ricardbejarano wants to merge 1 commit into
prometheus-community:masterfrom
bejaratommy:fix/version-flag-without-config
Open

fix: do not require config file for --version and --help#459
ricardbejarano wants to merge 1 commit into
prometheus-community:masterfrom
bejaratommy:fix/version-flag-without-config

Conversation

@ricardbejarano

Copy link
Copy Markdown

Summary

json_exporter --version (and --help) fail when no config file is present:

# ./json_exporter --version
json_exporter: error: path 'config.yml' does not exist, try --help

The --config.file flag is defined with .Default("config.yml").ExistingFile(), so kingpin validates that config.yml exists while parsing flags — before the --version/--help actions run. This diverges from other Prometheus exporters, where informational flags work without a config file.

Change

Replace .ExistingFile() with .String() for the config.file flag. A missing config file is still reported clearly at startup by LoadConfig (os.ReadFile), which already surfaces the error and exits non-zero, so no genuine configuration error is masked.

Fixes #292

Testing

  • No behavioral test added: the change only affects flag-parse-time validation of --version/--help, which requires exercising the process entry point (the exporter uses kingpin.Version/kingpin.HelpFlag that call os.Exit). Manual verification: with the fix, --version and --help succeed with no config.yml present, while starting the exporter without a config still fails at LoadConfig with open config.yml: no such file or directory.

The config.file flag used ExistingFile() on its default value, so
kingpin validated that config.yml existed while parsing flags. This
made `--version` and `--help` fail with "path 'config.yml' does not
exist" whenever no config file was present, contrary to how other
Prometheus exporters behave.

Use String() instead; a missing config file is still reported clearly
at startup by LoadConfig (os.ReadFile), so no real configuration error
is masked.

Fixes prometheus-community#292
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.

cli param --version not working without a config.yml file

2 participants