golang-spf13-cobra
CommunityBuild native-feeling Go CLI command trees
Authorvanstinator
Version1.0.0
Installs0
System Documentation
What problem does it solve?
It helps you design and implement correct, maintainable Go CLI command trees using spf13/cobra, including reliable error propagation, argument validation, flag behavior, and shell completions.
Core Features & Use Cases
- Command lifecycle correctness: Use the proper Run* hooks (especially RunE) and place initialization in PersistentPreRunE.
- Robust argument validation: Validate positional args with cobra’s Args validators instead of manual checks inside RunE.
- Predictable, testable output: Write to cmd.OutOrStdout() / cmd.ErrOrStderr() so command behavior is unit-test friendly.
- Ergonomic flags and constraints: Apply required/optional flag rules with MarkFlagRequired, MarkFlagsMutuallyExclusive, MarkFlagsOneRequired, MarkFlagsRequiredTogether, and Changed().
- Shell completions & docs: Add static/dynamic completions (ValidArgs, ValidArgsFunction, RegisterFlagCompletionFunc) and generate documentation/man pages from the command tree.
- Testing patterns that avoid state leaks: Recreate a fresh command tree per test and verify behavior through captured output.
Quick Start
Use the skill to implement a cobra root command with subcommands, set SilenceUsage and SilenceErrors, validate args via the Args field, return errors from RunE, and write all output through cmd.OutOrStdout() / cmd.ErrOrStderr().
Dependency Matrix
Required Modules
None requiredComponents
references
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: golang-spf13-cobra Download link: https://github.com/vanstinator/semantic-search/archive/main.zip#golang-spf13-cobra Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.