open-code-review/cmd/opencodereview
xujiejie 9d2800ffaf
feat: add ability to delete custom providers from configuration (#189)
* feat: add ability to delete custom providers from configuration

Implements GitHub issue #136.

CLI: add 'ocr config unset custom_providers.<name>' command to delete
a custom provider from config. If the deleted provider is the active
one, clears 'provider' and 'model' fields and prompts the user.

TUI: press 'd' on Custom tab to delete a provider with y/n confirmation.
Shows warning when deleting the active provider. Deletions are persisted
even if the user cancels provider selection afterward.

- Add runConfigUnset() with key validation and active-provider handling
- Add 'unset' case to parseConfigArgs() and printConfigUsage()
- Add delete confirmation state machine to providerTUIModel
- Add applyProviderDeletions() helper in provider_cmd.go
- Add 10 new tests covering CLI parsing, deletion logic, and TUI flows
- Update README with unset command documentation

* fix: address PR review feedback

- Add defensive bounds check for deleteTargetIdx before deletion
- Use explicit slice copy to avoid retaining references (memory leak)
- Update subCmd comment to reflect 'set' and 'unset' values

* refactor: extract shared deleteCustomProvider and improve test coverage

Address PR review feedback from lizhengfeng101:

- Extract deleteCustomProvider() as a pure function shared by both
  runConfigUnset (CLI) and applyProviderDeletions (TUI)
- Extract unsetCustomProvider() accepting configPath for testability
- Add existence check in applyProviderDeletions (skip non-existent providers)
- Rewrite 3 tests to call actual functions instead of inlining logic
- Remove unused strings import from config_cmd_test.go

* style: use [ocr] WARNING prefix for active provider deletion messages

Align with project convention (output.go, flags.go): warnings use
'[ocr] WARNING' prefix and write to stderr instead of stdout.

* fix: address second round of PR review feedback

- Fix test state pollution in TestUnsetInvalidKey: use t.Run sub-tests
  with independent config files per case (#7)
- Log warning instead of silently swallowing errors in
  applyProviderDeletions (#9)
- Add comment explaining existingCfg snapshot assumption in
  viewCustomTab (#10)
- Simplify runConfigUnset error message to single line for consistency
  with project style (#11)
2026-06-23 21:21:23 +08:00
..
config_cmd.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
config_cmd_test.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
flags.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
flags_test.go feat:add --model flag to override LLM model per review (#122) 2026-06-16 22:38:52 +08:00
git.go fix(security): block git ref option injection (#112) 2026-06-13 11:07:59 +08:00
llm_cmd.go fix: improve LLM test feedback for empty responses (#162) 2026-06-17 12:56:39 +08:00
main.go feat: add interactive provider setup with TUI and documentation 2026-06-14 10:49:33 +08:00
output.go fix: sanitize terminal control characters in text output to prevent escape-sequence injection (#143) 2026-06-16 14:48:56 +08:00
output_test.go fix: sanitize terminal control characters in text output to prevent escape-sequence injection (#143) 2026-06-16 14:48:56 +08:00
provider_cmd.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
provider_tui.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
provider_tui_test.go feat: add ability to delete custom providers from configuration (#189) 2026-06-23 21:21:23 +08:00
review_cmd.go fix: apply language directive even when config file is missing 2026-06-17 10:56:35 +08:00
review_cmd_test.go fix(cli): reject --to without --from in review flags (#151) 2026-06-16 20:26:22 +08:00
rules_cmd.go feat(rules): add ocr rules check command to preview effective rule for a file path 2026-05-26 22:11:39 +08:00
version.go feat(cli): display GitHub repository URL in version and help output 2026-06-02 22:50:36 +08:00
viewer_cmd.go feat: init 2026-05-20 22:03:52 +08:00