What problem does it solve?
This Skill helps you design and implement Go CLI command trees that behave correctly in the shell and in automated tests, using spf13/cobra’s lifecycle, validation, flags, completions, and documentation generation.
Core Features & Use Cases
- Command tree & hooks: Set up root/subcommand structure and apply the correct hook chain with error-returning
RunE for predictable exit behavior.
- Args validation: Use built-in and custom
Args validators (including MatchAll) to fail fast with standard cobra error messaging instead of manual len(args) checks.
- Flags & completions: Define persistent vs local flags, enforce constraints (required, mutually exclusive, required-together), and add shell completions via
ValidArgsFunction and RegisterFlagCompletionFunc.
- Docs & testing: Generate man/markdown/YAML docs from your command tree and test commands safely by using
cmd.OutOrStdout() / cmd.ErrOrStderr() with a fresh command tree per test.
Quick Start
Ask an AI to “show me how to create a cobra root command with subcommands, use RunE with Args validation, add a persistent config flag, and implement dynamic shell completion for a positional argument.”