Skip to content

fix: name flags after config keys and bind them to the keys; describe the logging flags - #22

Merged
patdowney merged 2 commits into
masterfrom
fix/flags-follow-config-keys
Nov 14, 2026
Merged

patdowney merged 2 commits into
masterfrom
fix/flags-follow-config-keys

Conversation

@patdowney

Copy link
Copy Markdown
Contributor

Summary

#18. sflags names a flag from the Go field path, but the config is decoded from the mapstructure keys. For a renamed field, a named ,squash struct, or a nested block the two differ, so the flag showed in --help while its value went to a viper key nothing decodes.

  • Each generated flag is named after its field's mapstructure key path (--log-level for log.level), and InitConfig binds it to that key.
  • A flag:"name" tag on a field, or an ancestor, still chooses the name.
  • A flag whose name changed stays accepted under its old name as a hidden, deprecated alias that sets the same value.
  • Environment overrides now follow the config key too.
  • Tests set each generated flag and check the decoded struct changed; they fail against the old wiring.

#16. Every logging.Config field gets a desc, mode is hidden, and the flags become --log-* (so --log-use-local-time), with the --logging-* names kept as deprecated aliases. cli.UndocumentedFlags(cmd) returns the visible flags with no usage, so a consumer can guard its CLI in a test.

Compatibility

Flag names change (old names still work, hidden and deprecated), environment variables now follow the config key, and generated CLI reference docs will differ.

Fixes #18
Fixes #16

Stacked: #20 and #19 PRs build on this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SS4MAwAn85D1gkEzLtjYaZ

patdowney and others added 2 commits November 14, 2026 20:30
sflags names a flag from the Go field path, but the config is decoded from
the fields' mapstructure keys. For a renamed field, a named struct squashed
into its parent, or a nested block the two differ, so the flag showed in
--help while its value went to a viper key nothing decodes.

Each flag is now named from its field's mapstructure key path, so the flag
for log.level is --log-level, and InitConfig binds it to that key. A flag
tag name on a field still wins. A flag whose name changed stays accepted
under its old name as a hidden, deprecated alias. Environment overrides now
follow the config key too.

Fixes #18

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SS4MAwAn85D1gkEzLtjYaZ
…onfig keys

Every logging.Config field gets a description, taken from its doc comment,
so --help no longer shows eight bare flags. Mode, reserved for future use,
is hidden. The flags are now --log-level, --log-use-local-time and so on,
matching the log.* config keys; the --logging-* names stay accepted as
hidden, deprecated aliases (see the previous commit).

UndocumentedFlags walks a command tree and returns the visible flags with no
usage text, so a consumer can fail its own tests if one appears.

Fixes #16

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SS4MAwAn85D1gkEzLtjYaZ
@patdowney
patdowney added this pull request to stack #25 November 14, 2026 23:37
@patdowney
patdowney merged commit fab8c05 into master Nov 14, 2026
4 checks passed
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.

Generated flags for squashed or renamed config fields are silently ignored logging flags: add descriptions, match YAML key names, hide reserved mode

1 participant