golang-spf13-cobra

Design and manage Go CLI command trees with spf13/cobra.

Updated May 19, 2026
One-click install
npx skills add https://github.com/monforje/.opencode --skill golang-spf13-cobra-monforje
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-spf13-cobra
Source: https://github.com/monforje/.opencode/tree/main/skills/cc-skills-golang/skills/golang-spf13-cobra
Command: npx skills add https://github.com/monforje/.opencode --skill golang-spf13-cobra-monforje

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/spf13/cobra, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill simplifies the creation and management of Go CLI command trees, allowing developers to focus on the user experience and functionality without worrying about the underlying complexities of the spf13/cobra library.

Core Features & Use Cases

  • CLI Command Tree Design: Offers comprehensive guidance on structuring and organizing CLI commands and subcommands.
  • Flag and Argument Validation: Detailed instructions on implementing robust argument and flag validation using Cobra's built-in functions.
  • Shell Completions: Guidance on implementing shell completions for improved user experience.
  • Testing: Best practices for testing CLI commands, including handling output and error redirection.
  • Use Case: A Go developer wants to create a CLI tool with a robust command structure, including multiple subcommands and flags. This Skill provides the necessary steps and code examples to achieve that.

Quick Start

Use the golang-spf13-cobra skill to add a 'list-resources' subcommand to your CLI that displays all available resources. Command: use golang-spf13-cobra list-resources

Frequently Asked Questions about golang-spf13-cobra

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Go CLI command trees with subcommands and flags?

To build Go CLI command trees, use the spf13/cobra library to organize commands and subcommands hierarchically. This approach lets developers focus on functionality while avoiding the complexities of manual command routing and flag parsing.

What is the best way to validate arguments and flags in a Go CLI application?

The best way to validate arguments and flags in a Go CLI is by using Cobra's built-in functions. This skill provides detailed instructions for implementing robust argument and flag validation directly within your command structures.

How do I implement shell completions for my Go command line tool?

Implement shell completions for your Go command line tool using spf13/cobra's completion capabilities. This skill offers specific guidance on enabling completions to significantly improve the end-user experience of your CLI.

What are the best practices for testing Go CLI commands built with cobra?

Best practices for testing Go CLI commands built with cobra include properly handling output and error redirection. This skill provides testing guidelines to ensure your command tree functions reliably across different execution scenarios.

Do I need prior Go experience to use cobra for command line interface development?

Yes, you need prior knowledge of Go and the Cobra library to use this skill effectively. It is designed for Go developers who want to create CLI tools with robust command structures, multiple subcommands, and flags.