Command parsing
Cobra
Command/help/completion structure plus event-driven terminal UI.
Limits: Keep noninteractive and machine-readable modes; test TTY absence, cancellation and terminal restoration.
Command-line applications and terminal interfaces distributed as binaries.
Cobra · Bubble Tea when needed · GoReleaser
These recipes and dependency combinations need checking in your actual project before you rely on them.
Paste the guide address into your agent chat, together with what you want to build.
Use cases: Shipped command-line products; infrastructure administration tools; terminal dashboards.
Generator documentation reviewed: 2026-10-23. Evidence: documentation-reviewed; commands not executed.
Use when: A new command application selects Cobra; use the standard-library flag package for a deliberately smaller CLI without a Cobra scaffold.
Working directory: /path/to/workspace (existing local source parent)
Create a new CLI source directory.
mkdir projectWorking directory: /path/to/workspace/project
Initialize module metadata.
go mod init example.com/projectWorking directory: /path/to/workspace/project
Install the selected generator version.
go install github.com/spf13/cobra-cli@"${COBRA_CLI_VERSION:?Set the selected Cobra CLI version}"Working directory: /path/to/workspace/project
Generate main.go and cmd/root.go using Cobra.
cobra-cli initUse when: When adding commands to the generated Cobra application.
Working directory: /path/to/workspace/project (existing Cobra root)
Generate an example serve command for subsequent implementation.
cobra-cli add serveUse when: Only when the CLI needs an interactive terminal user interface; a conventional command interface can stay with Cobra or the standard library.
Working directory: /path/to/workspace/project (module root)
Add Bubble Tea v2 using its current vanity module path.
go get charm.land/bubbletea/v2@latestUse when: Only when GoReleaser is selected for this application and no release configuration exists.
Working directory: /path/to/workspace/project (module root; selected GoReleaser installed)
Generate .goreleaser.yaml.
goreleaser initWorking directory: /path/to/workspace/project
Validate the reviewed release configuration.
goreleaser checkChoose the tools your application needs. The brief includes your selections, their purpose and their limits; the complete guide keeps all recommendations and sources.
Cobra
Command/help/completion structure plus event-driven terminal UI.
Limits: Keep noninteractive and machine-readable modes; test TTY absence, cancellation and terminal restoration.
Bubble Tea only for interactive screens
Command/help/completion structure plus event-driven terminal UI.
Limits: Keep noninteractive and machine-readable modes; test TTY absence, cancellation and terminal restoration.
net/http Client
Standard client with contexts and transport reuse.
Limits: Set timeouts, bound responses and close bodies; retry only when operation semantics allow.
None for stateless tools
Avoid introducing a database into a command wrapper.
Limits: Local durable state requires a separately selected storage/schema policy; never assume flat-file writes are atomic.
Typed settings loaded with os.LookupEnv
Explicit startup validation and standard structured logs.
Limits: Define precedence; reject malformed required values; redact secrets. Environment access alone is not validation or secret management.
log/slog
Explicit startup validation and standard structured logs.
Limits: Define precedence; reject malformed required values; redact secrets. Environment access alone is not validation or secret management.
testing; go vet; race detector; govulncheck
Standard toolchain feedback plus exercised concurrency and known-vulnerability checks.
Limits: Race detector requires supported target/toolchain and exercised code; no scanner proves absence of vulnerabilities.
Delegate long jobs to a service; persist its job ID
Work survives the terminal process only through an explicit durable owner.
Limits: A goroutine or TUI background command dies with the process; reconnection needs a stable job identity.
GoReleaser
Target builds and release artifact automation.
Limits: Review generated release actions, supported targets, signing and updater policy. cgo can complicate cross-building.
encoding/json/v2 on a supporting pinned Go toolchain
Stable JSON output lets scripts consume commands without parsing terminal text
Limits: Add an explicit --json/output mode and document schema/exit codes; reserve stdout for results, stderr for diagnostics, and disable interactive/color output for pipelines. Confirm API availability on the pinned Go version; v2 changes encoding/decoding defaults, so test schema/null/omission compatibility before migrating.
signal.NotifyContext
User interrupts should cancel outbound work and leave terminal/files usable
Limits: Propagate cancellation through work; bound cleanup time and test interrupts during writes. Avoid adding an async runtime to a synchronous Rust CLI solely for signals.
Build with the stack’s strengths
Recommendation: keep the command tree as an adapter over testable application functions. A noninteractive command is a versioned automation interface; a Bubble Tea view is an optional interactive client of the same functions. The executable owns stream, exit-status, cancellation and configuration contracts.
Version scope: Go 1.27 toolchain documentation, Cobra/pflag current guide, Bubble Tea upstream API and GoReleaser v2 documentation. Pin compatible module/tool versions; Bubble Tea major/module-path changes need explicit review. No release matrix was built. · Reviewed 2026-10-11 · Evidence: documentation-reviewed · Source: inputs/research/migrations-systems.json
For an existing application
These are documented options and proposed checks. Inspect the actual source application before adopting a transition.
Capture scripts consuming current flags, positional arguments, stdout/stderr, exit codes and completion output.
Recommendation: retain old subcommands/aliases as thin adapters while introducing an explicit JSON mode. Mark renamed flags deprecated through Cobra instead of silently changing their meaning.
Recommendation: Cobra RunE plus centralized result/error mapping; versioned JSON on stdout and diagnostics on stderr. Freeze documented application codes for success, usage and operational failure.
Recommendation: install the preceding binary and continue serving the old protocol. Keep newly introduced machine schemas behind explicit versions so callers can choose a compatible response.
A stable CLI protocol permits automation and humans to share one executable.
Requires: Consumer fixtures cover streams/status; formatting and error categories are explicit; deprecation schedule preserves callers.
Tradeoffs: Versioned output requires ongoing compatibility ownership; usage errors and remote failures may need different handling.
Inventory config paths, default values, flag/environment precedence, secret fields and old readers.
Recommendation: parse both old and versioned schemas through adapters; display migration diagnostics on stderr and offer an explicit migration command with backup. Keep the old file untouched until conversion passes.
Recommendation: a typed versioned config decoded deliberately, with unknown-field policy and semantic validation. Write a same-directory temporary file, validate it and replace only after success; qualify filesystem/OS behavior and cross-process ownership.
Recommendation: restore the backup and preceding executable together. Preserve old readable configuration throughout the downgrade window; do not roll back after newer-only values without an explicit mapping.
A versioned configuration contract makes upgrades and later rollback predictable.
Requires: Old fixtures exist; migration preserves semantics and backups; one writer and tested replacement behavior are defined.
Tradeoffs: Strict unknown-field rejection can hinder mixed-version use; atomic replacement does not establish crash durability or coordinate concurrent writers.
Preserve per-item effects, retry decisions, ordering and interrupt behavior for batch commands; a process-local queue has no restart history.
Recommendation: keep the sequential executor available and compare the new bounded executor on fixture inputs. Route one operation class at a time; reuse stable operation IDs across retries.
Recommendation: signal.NotifyContext plus errgroup limit or a fixed worker pool. Pass context through clients, close resources after workers finish, and persist a checkpoint/receipt when interrupted effects need later recovery.
Recommendation: return to sequential execution using the same checkpoint contract. Reconcile ambiguous outcomes first; restarting from item zero is not a safe general rollback.
Bounded fan-out can overlap independent I/O while maintaining a clear cancellation boundary.
Requires: Concurrency quota and total deadline are set; downstream calls honor cancellation; completed and ambiguous effects can be reconciled.
Tradeoffs: No throughput gain is measured; cancellation cannot undo effects; a retry can duplicate a write without provider or business idempotency.
Preserve command name, install path, OS/architecture support, update channel and downgrade compatibility.
Recommendation: produce snapshot artifacts beside the old release and smoke-test them without changing the default download. Review generated package-manager changes and publish channels only after target verification.
Recommendation: pinned GoReleaser v2 matrix with metadata/checksums, OS-specific install tests and an explicit signing path. CGO dependencies and macOS signing/notarization need separate toolchain/credential setup; the documented native package notarization flow is Pro; qualify the chosen binary or package flow separately.
Recommendation: repoint the owned download/package channel to the previous verified release and keep its artifacts available. Restore compatible configuration with the binary; do not silently overwrite unrelated install locations.
A repeatable artifact matrix reduces manual release assembly.
Requires: Build inputs/tool versions are pinned; each promised target is installed and exercised; signing credentials and package metadata are owned.
Tradeoffs: Cross-compilation is not execution evidence; CGO can require native toolchains; selected signing/notarization automation may require a paid tier.
Run these in the configured application. They are instructions, not recorded passes.
gofmt -l .
go test ./...
go test -race ./...
go vet ./...
govulncheck ./...
go build ./cmd/tool
goreleaser check
goreleaser build --snapshot --cleanOriginal source review: 2026-10-10. Core guidance rechecked: 2026-10-13. Check scope.