open-code-review/cmd/opencodereview
kite 80a5794667
Some checks are pending
CI / test (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
Deploy Pages / build (push) Waiting to run
Deploy Pages / deploy (push) Blocked by required conditions
refactor(cli): migrate to Cobra framework for shell completion support (#625)
* refactor(cli): migrate to Cobra framework for shell completion support

Replace the hand-rolled ocrFlagSet + switch dispatch with spf13/cobra,
enabling native bash/zsh/fish/powershell completion via `ocr completion`.

Key changes:
- Add root.go (rootCmd definition, version flag with -V shorthand)
- Add completion.go (ocr completion [bash|zsh|fish|powershell])
- Add shared_flags.go (reusable flag registration helpers + validation)
- Rewrite all *_cmd.go to use cobra.Command with RunE
- Delete flags.go (ocrFlagSet, expandShortFlags, parseXxxFlags)
- Add compat_test.go (test compatibility wrappers for existing tests)
- Promote github.com/spf13/cobra from indirect to direct dependency

Behavioral improvements over the previous implementation:
- Shell completion for all commands, flags, and enum values
- "Did you mean?" suggestions for misspelled commands
- cobra.NoArgs on review/scan prevents silent positional arg ignoring
- Cleaner error messages on unknown flags (no full flag dump)
- Consistent help output format across all subcommands

Closes #576

* fix(cli): add Args: cobra.NoArgs to viewerCmd

Prevents `ocr viewer localhost:3000` from silently ignoring the
positional argument and starting on the default address.
Consistent with reviewCmd and scanCmd.

* feat(cli): add "Did you mean?" suggestions for misspelled flags

Cobra only suggests corrections for unknown subcommands, not flags.
Add a levenshtein-distance based suggestion that fires when cobra
returns an "unknown flag" error, matching the same UX pattern.

Examples:
  --hel     → Did you mean this? --help
  --audienc → Did you mean this? --audience
  --comit   → Did you mean this? --commit

* fix(deps): promote spf13/pflag to direct dependency

After the Cobra migration, pflag is directly imported but was still
marked as indirect in go.mod, causing CI's go-mod-tidy check to fail.

* refactor(cli): use idiomatic cobra patterns for args validation and flag errors

Replace hand-rolled argument validation in configSetCmd/configUnsetCmd
with cobra.ExactArgs, and move flag typo suggestions from post-hoc error
string parsing into SetFlagErrorFunc where cobra provides the command
context directly.
2026-07-31 16:56:07 +08:00
..
background_file.go fix(background-file) Manage path at git repository root directory Refs:#324 (#327) 2026-07-13 11:27:54 +08:00
background_file_test.go fix(background-file) Manage path at git repository root directory Refs:#324 (#327) 2026-07-13 11:27:54 +08:00
budget_output_test.go feat(agent): add token-cost budget guardrails to the review path (#508) 2026-07-30 10:49:13 +08:00
compat_test.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
completion.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
config_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
config_cmd_test.go fix(config): warn when active provider shadows llm settings (#588) 2026-07-30 17:10:05 +08:00
config_dispatch_test.go test: improve coverage for cmd/opencodereview package from 42% to 70% 2026-06-27 01:47:48 +08:00
delegate_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
emit_run_result_test.go feat(agent): add token-cost budget guardrails to the review path (#508) 2026-07-30 10:49:13 +08:00
flag_suggest.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
flags_test.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
git.go fix(tool): resolve file_read paths against git top-level in monorepos (#309) 2026-07-07 20:06:28 +08:00
git_test.go test: fix golangci-lint errcheck/staticcheck issues in test code (#323) 2026-07-08 22:46:18 +08:00
llm_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
main.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
output.go fix: honor per-file review terminal states (#582) 2026-07-31 14:32:30 +08:00
output_helpers_test.go fix: honor per-file review terminal states (#582) 2026-07-31 14:32:30 +08:00
output_test.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
procattr_unix.go feat: add standard MCP tool support (#212) 2026-07-01 19:10:16 +08:00
procattr_windows.go feat: add standard MCP tool support (#212) 2026-07-01 19:10:16 +08:00
provider_cmd.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
provider_cmd_test.go test: fix golangci-lint errcheck/staticcheck issues in test code (#323) 2026-07-08 22:46:18 +08:00
provider_tui.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
provider_tui_funcs_test.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
provider_tui_test.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
review_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
review_cmd_test.go fix(cli): reject --to without --from in review flags (#151) 2026-06-16 20:26:22 +08:00
root.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
rules_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
scan_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
scan_cmd_test.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
session_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
session_cmd_test.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
shared.go feat(agent): add token-cost budget guardrails to the review path (#508) 2026-07-30 10:49:13 +08:00
shared_flags.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
shared_test.go fix: align Go module path with actual GitHub repository (#526) 2026-07-27 19:52:35 +08:00
shell_unix.go feat: add standard MCP tool support (#212) 2026-07-01 19:10:16 +08:00
shell_windows.go feat: add standard MCP tool support (#212) 2026-07-01 19:10:16 +08:00
smallfiles_test.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
version.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00
viewer_cmd.go refactor(cli): migrate to Cobra framework for shell completion support (#625) 2026-07-31 16:56:07 +08:00