Research: can the cobra bootstrap boilerplate be reduced without losing cobra API power? #6
Labels
No labels
needs-info
needs-triage
ready-for-agent
ready-for-human
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ginjiruu/toolbelt#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Question
Can the cobra bootstrap boilerplate be reduced without losing power access to the underlying cobra API?
cmd/totals ~1,048 lines (go-template), ~959 (ttrpg), ~381 (example):root.go,serve.go,config.go,dev.go,pager.go— near-identical across consumers. This passes the "example proves it" boundary (the example hand-wrote it; consumers duplicate it). The boilerplate includes the-v/-vvverbosity ladder, theconfig list/describe/setcommand, the embedded-OIDCdevcommand, and a pager.Research this: what would a shared
toolbelt/cmd(or config-driven) bootstrap look like that still exposes the raw cobra API (*cobra.Command, persistent flags, custom hooks) to apps? Survey cobra's extensibility surface and how much of the three repos'cmd/is genuinely common vs per-app divergence (verbosity model, KCL vs YAML config save).The decision: absorb a shared bootstrap, or rule "keep per-app" because the divergence is structural? The answer graduates into a fresh absorption ticket or a keep-per-app ruling — resolve with a
/researchsubagent on a throwawayresearch/<name>branch, then write the plan todocs/plans/.RESOLVED — research complete.
Answer: absorb — and the divergence is not structural. A shared
toolbelt/cmdbootstrap is feasible while preserving full raw cobra API access.Key findings:
pager.go(54 lines),dev_build.go,dev_nobuild.goare byte-identical across go-template ↔ ttrpg;serve.godiffers in exactly 2 lines;config.go's generic core (~357 lines) is 100% reusable against theFields()registry.package cmd(≈611/711 lines in go-template) is absorbable via a parent-command factoryNewRootCommand(...) *cobra.Command— cobra is data-driven, so raw*cobra.Commandis preserved (AddCommand, persistent flags, hooks, groups, completions).NewRootCommand(RootOptions),AddConfigCommand(root, SaveOptions)(injectable KCL/YAML save),Pager(),Serve(...)scaffold,DevSetup(prefix)inembeddedoidc, and one sharedBuildLogger.-v/-vv/-vvvladder is already toolbelt-owned (config.VerboseToLevel).go.moddeclares the go-template module path, imports go-template internals, pins an old toolbelt, and itsFieldFlagVerboserefs already can't build against the current toolbelt). Treat it as a migration target, NOT a compat constraint.Full findings:
docs/research/cobra-bootstrap.mdon branchresearch/cobra-bootstrap(commit742c60e).Decision recorded. The design of the
toolbelt/cmdsurface graduates into a new absorption ticket.Research resolved: absorb is viable — graduates into a cobra absorption ticket. Full findings on research/cobra-bootstrap branch.