Skip to content

refactor: generate flag help via flag.PrintDefaults - #14

Merged
dobbi84 merged 1 commit into
mainfrom
fix/usage-printdefaults
Jun 4, 2026
Merged

refactor: generate flag help via flag.PrintDefaults#14
dobbi84 merged 1 commit into
mainfrom
fix/usage-printdefaults

Conversation

@dobbi84

@dobbi84 dobbi84 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

printUsage hard-coded the description and default for every flag (--web.listen-address, --web.telemetry-path, --collector.*, --no-collector.*, --collector.disable-defaults). This duplicated the real flag definitions and would silently drift whenever a flag changed.

Changes

  • Replace the hand-written flag blocks with flag.PrintDefaults(), which generates entries directly from the registered flags and their defaults — so they can't drift.
  • Write the usage message to flag.CommandLine.Output() (matching where PrintDefaults writes) instead of stdout via fmt.Println.
  • Keep the dynamic "Available collectors" summary and the examples unchanged.

Notes

  • flag.PrintDefaults() now lists each per-collector flag individually (more verbose than the old --collector.<name> placeholder), but it's accurate and self-maintaining.

Testing

  • go build ./...
  • go vet ./...

The usage output hard-coded descriptions for every flag, which drifted
from the actual flag definitions. Delegate the flag listing to
flag.PrintDefaults() so it stays in sync, and write usage to
flag.CommandLine.Output() to match.
@dobbi84
dobbi84 requested a review from LemonySnippet as a code owner June 4, 2026 08:38
@dobbi84 dobbi84 self-assigned this Jun 4, 2026
@dobbi84 dobbi84 added documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code labels Jun 4, 2026
@dobbi84
dobbi84 merged commit 0bddbb0 into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant