go-cobra-applications
Build, refactor, test, and review Cobra-based Go applications with intentional command trees, fresh constructors, suggestions, typed boundaries, scoped flags, local or remote configuration, explicit precedence, safe live reload, context propagation, stable streams, shell completion, and generated documentation. Use for Cobra or Viper CLI architecture and implementation.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- go-cobra-applications
- license
- MIT
- metadata
- { "tags": "go,golang,cli,cobra,viper,command-tree,configuration", "version": "0.4.0", "category": "Go", "displayName": "Go Cobra Applications" }
- description
- Build, refactor, test, and review Cobra-based Go applications with intentional command trees, fresh constructors, suggestions, typed boundaries, scoped flags, local or remote configuration, explicit precedence, safe live reload, context propagation, stable streams, shell completion, and generated documentation. Use for Cobra or Viper CLI architecture and implementation.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 8
- 参考文档agents/openai.yaml217 B
- 参考文档guidelines.md3.1 KB
- 参考文档references/cobra-applications/checklist.md6.4 KB
- 参考文档references/cobra-applications/examples.md4.4 KB
- 参考文档references/cobra-applications/knowledge.md5.4 KB
- 参考文档references/cobra-applications/patterns.md5.3 KB
- 参考文档references/cobra-applications/rules.md6.2 KB
- 参考文档workflows/build-cobra-command-tree.md4.4 KB
03 SKILL.md 正文
Go Cobra Applications
Keep Cobra and Viper at the application edge. Construct a fresh command tree per execution and translate CLI state into typed application calls.
Core Workflow
- Model the tree around user resources, workflows, and operations.
- Define invocation contracts, argument validation, examples, and flag scope.
- Construct fresh root and subcommands with explicit dependencies and streams.
- Keep handlers thin, propagate context, and return errors.
- Resolve defaults, config, environment, and flags into a validated typed config.
- Test parsing, inheritance, precedence, help, errors, and repeated execution.
- Generate completion and documentation from the same runtime tree.
Read Next
| Task | Load |
|---|---|
| Build or restructure a Cobra application | guidelines.md, workflows/build-cobra-command-tree.md |
| Apply command-tree, flag, config, and testing rules | references/cobra-applications/rules.md |
| Use constructors and focused implementation examples | references/cobra-applications/examples.md |
| Inject services or resolve configuration | references/cobra-applications/patterns.md |
| Review a Cobra/Viper application | references/cobra-applications/checklist.md |
| Understand architecture, completion, and docs | references/cobra-applications/knowledge.md |
Guardrails
- Avoid mutable package-global commands and
init-driven application wiring. - Domain packages must not import Cobra or Viper.
- Use persistent flags only when descendants genuinely share the option.
- Treat configuration as validated runtime policy, not mutable application storage.
- Validate reload candidates and atomically publish only last-known-good state.
- Show usage for syntax errors, not routine operational failures.
- Verify generator, completion, docs, and configuration APIs against pinned versions.
Source Notes
Guidance is transformed and paraphrased from Ricardo Gerardi, Powerful Command-Line Applications in Go (Pragmatic Bookshelf, 2021), especially Chapter 7. Examples are original adaptations.
Book: https://pragprog.com/titles/rggo/powerful-command-line-applications-in-go/
The book's 2021 generator flow is historical. Verify current APIs and tooling against https://cobra.dev/ and https://github.com/spf13/viper before use.
Suggestion, remote configuration, and live-reload guidance also incorporates transformed material from Marian Montagnino, Building Modern CLI Applications in Go (Packt, 2023), especially Chapter 4.
Parser-boundary guidance also incorporates transformed material from Inanc Gumus, Go by Example: Programmer's Guide to Idiomatic and Testable Programs (Manning, 2025), Chapter 4.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.