refactor(cli): adopt cobra + lipgloss for the command tree#5
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the hand-rolled
os.Argsdispatch incmd/vectorwith a cobra command tree and addscli/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:
--jsonis byte-identicalThe
--jsoncontract consumed by the/vector:*project commands is unchanged, byte-for-byte. Verified two ways:cli/cmd/vector/golden_test.go+testdata/golden/) captures 15 deterministic--jsoncommands and gates on drift.mainbinary vs the new binary on identically-seeded repos — all identical.pflaginterleaves flags and positionals, so invocations likevector spec apply --json <id>(flag before id) now work too — a strict superset; every previously valid invocation stays valid.Details
cmd/vector: eachrunXxx→newXxxCmd()factory (flags 1:1, body inRunE);newRootCmd()builds a fresh tree per call; hand-rolled-v/--versionfires 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 againstui.*inside anyif jsonOutbranch).summarize commitkeeps both orderings (summarize commit <id>andsummarize <id> commit) via manual two-order detection — documented exception to the cobra-child pattern.Gate
gofmtclean ·go vet ./...clean ·go build ./...·go test ./...green ·go mod tidyno diff.Merge note — coordinate with
emit-sketch-attached-eventcmd/vector/sketch.gohere calls the 3-argStore.AttachSketch(matchingmain). The separate in-progress emit-sketch-attached-event change adds a 4thactorarg toAttachSketch. When both land, resolve thesketch.goconflict by keepingnewSpecAttachSketchCmd(cobra) and using the 4-arg call.🤖 Generated with Claude Code