Skip to content

refactor(cli): adopt cobra + lipgloss for the command tree#5

Merged
mcampbellr merged 1 commit into
mainfrom
feat/adopt-cobra-lipgloss-cli
Jul 1, 2026
Merged

refactor(cli): adopt cobra + lipgloss for the command tree#5
mcampbellr merged 1 commit into
mainfrom
feat/adopt-cobra-lipgloss-cli

Conversation

@mcampbellr

Copy link
Copy Markdown
Owner

What

Replaces the hand-rolled os.Args dispatch in cmd/vector with a cobra command tree and adds cli/internal/ui (lipgloss) for the styled human surface. The CLI gains auto-generated --help, vector completion <bash|zsh|fish|powershell>, and clear styled output.

The hard guarantee: --json is byte-identical

The --json contract consumed by the /vector:* project commands is unchanged, byte-for-byte. Verified two ways:

  • A golden suite (cli/cmd/vector/golden_test.go + testdata/golden/) captures 15 deterministic --json commands and gates on drift.
  • Direct diff of the pre-cobra main binary vs the new binary on identically-seeded repos — all identical.

pflag interleaves flags and positionals, so invocations like vector spec apply --json <id> (flag before id) now work too — a strict superset; every previously valid invocation stays valid.

Details

  • cmd/vector: each runXxxnewXxxCmd() factory (flags 1:1, body in RunE); newRootCmd() builds a fresh tree per call; hand-rolled -v/--version fires in any position; exit-code contract preserved (no-args / unknown-command → 2; unknown subverb / unknown flag / business error → 1; version → 0).
  • internal/ui: lipgloss wrappers + ApplyCustomHelp, applied only in the human branch (a test guards against ui.* inside any if jsonOut branch).
  • summarize commit keeps both orderings (summarize commit <id> and summarize <id> commit) via manual two-order detection — documented exception to the cobra-child pattern.
  • Deps (first external deps of the module): cobra v1.10.2 (Apache-2.0), lipgloss v1.1.0 (MIT); no huh/bubbletea. Release-equivalent binary: 6.60 → 8.04 MiB (+1.43 MiB, +21.7%) — no hard threshold.

Gate

gofmt clean · go vet ./... clean · go build ./... · go test ./... green · go mod tidy no diff.

Merge note — coordinate with emit-sketch-attached-event

cmd/vector/sketch.go here calls the 3-arg Store.AttachSketch (matching main). The separate in-progress emit-sketch-attached-event change adds a 4th actor arg to AttachSketch. When both land, resolve the sketch.go conflict by keeping newSpecAttachSketchCmd (cobra) and using the 4-arg call.

🤖 Generated with Claude Code

Replace the hand-rolled os.Args dispatch in cmd/vector with a cobra command
tree, and add cli/internal/ui (lipgloss) for the styled human surface. The CLI
gains auto-generated `--help`, `vector completion <shell>`, and clear styled
output — without touching the `--json` contract consumed by the /vector:*
project commands, which stays byte-identical.

- cmd/vector: each runXxx -> newXxxCmd() factory (flags 1:1, body in RunE);
  newRootCmd builds a fresh tree per call; hand-rolled -v/--version in any
  position; exit-code mapping preserved (no-args/unknown-cmd -> 2, others -> 1).
- internal/ui: Bold/Green/Red/Dim/Cyan, Success/Info/Warning/Error, Table,
  KeyValue, ApplyCustomHelp — applied only in the human branch, never inside an
  `if jsonOut` branch.
- Golden suite (golden_test.go + testdata/golden) locks the --json output
  byte-identical; verified against the pre-cobra binary at migration time.
- First external deps of the module: cobra v1.10.2 (Apache-2.0), lipgloss
  v1.1.0 (MIT); no huh/bubbletea. Release binary +~1.4 MiB (+~22%).

Note: cmd/vector/sketch.go here calls the 3-arg Store.AttachSketch (matching
main). The in-progress emit-sketch-attached-event change adds a 4th `actor`
arg; when both land, resolve sketch.go by keeping newSpecAttachSketchCmd and
using the 4-arg call.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mcampbellr mcampbellr merged commit d5ff4f1 into main Jul 1, 2026
2 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.

1 participant