open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

refactor(config): extract supported config keys into a single source of truth

Open lizhengfeng101 opened this issue 4 months ago • 2 comments

Description

In config_cmd.go, the list of supported configuration keys is maintained in two places that must be kept in sync:

  1. The switch/case branches in setConfigValue() (line 361–482) define the actual key handling logic.
  2. The error message in the default case (line 480) hardcodes a human-readable list of all supported keys.

When a new config key is added, both locations must be updated. If the error message is forgotten, users see an incomplete list of supported keys on typos.

Current code (line 480):

default:
    return fmt.Errorf("unknown config key: %s\nSupported keys: provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, mcp_servers.<name>.<field>, llm.url, llm.auth_token, ...", key)

Scope

  • File: cmd/opencodereview/config_cmd.go
  • Function: setConfigValue
  • Extract a var supportedConfigKeys (or similar) as the single source of truth, and derive the error message from it.

Acceptance Criteria

  • [ ] Supported config keys are defined in one place
  • [ ] The error message for unknown keys is generated from that definition
  • [ ] No change in user-facing behavior (same error message content)
  • [ ] Tests pass (make test)
  • [ ] Code check passes (make check)

Context

Discovered during code review of the Cobra CLI migration PR. The switch/case logic itself is correct; this is a maintainability improvement to prevent future drift between the key handling and the help text.

lizhengfeng101 avatar Jul 31 '26 09:07 lizhengfeng101

Would love to take this up

amh1k avatar Jul 31 '26 09:07 amh1k

I'd like to take this. I've got a patch that pulls the supported keys into a supportedConfigKeys slice and builds the error message from it, keeping the text identical. Opening a PR shortly.

DoTuanAnh2k1 avatar Jul 31 '26 15:07 DoTuanAnh2k1