LogoAwesome Skills
  • Search
  • Category
  • Tag
  • Blog
LogoAwesome Skills
LogoAwesome Skills

Discover Open-Source Agent Skills for AI Coding Assistants

Product

  • Search
  • Category
  • Tag
  • Blog

Resources

  • Claude Skill Docs
  • Antigravity Skills Docs

Tools

  • Claude Code
  • OpenCode
  • Cursor
  • Codex
  • Antigravity

Company

  • Privacy Policy
  • Terms of Service
  • Sitemap

©2026 Awesome Skills. All rights reserved.

Privacy PolicyTerms
Back to Skills

golang-spf13-cobra

Golang CLI command tree library using spf13/cobra — cobra.Command, RunE vs Run, PersistentPreRunE hook chain, Args validators (NoArgs, ExactArgs, MatchAll, custom), persistent vs local flags, command groups, ValidArgsFunction, RegisterFlagCompletionFunc, ShellCompDirective, usage/help template customization, man-page and markdown doc generation, and testing with SetArgs/SetOut/SetErr. Apply when using or adopting spf13/cobra, or when the codebase imports `github.com/spf13/cobra`. For configurati

2,201stars139forksUpdated 6/18/2026
Developer Tools#golang#cobra#cli#command-line#cli-tools#spf13

Security Assessment

Safe(100/100)
Security Score100/100

About golang-spf13-cobra

This skill provides comprehensive guidance for building command-line interfaces in Go using the spf13/cobra library, the de facto standard for CLI command trees in the Go ecosystem. Cobra handles the complete command/subcommand hierarchy, flag parsing through pflag, argument validation, shell completion generation, and documentation generation. It focuses on creating Unix-native CLI experiences with proper hook chains, error handling, and user-facing design patterns.

The skill covers essential cobra concepts including the distinction between RunE and Run handlers, the PersistentPreRunE hook chain for initialization logic, argument validators like NoArgs and ExactArgs, persistent versus local flags, command grouping, and shell completion customization through ValidArgsFunction and RegisterFlagCompletionFunc. It also addresses advanced features like usage template customization, man-page generation, and proper testing patterns using SetArgs, SetOut, and SetErr.

This skill is designed for Go developers building CLI tools, whether creating new command-line applications from scratch, extending existing cobra-based CLIs with additional subcommands and flags, or reviewing and auditing existing implementations for best practices. It complements the golang-spf13-viper skill for configuration management and the golang-cli skill for broader CLI architecture patterns like project layout and signal handling.

FAQ

When should I use cobra alone versus combining it with viper?

Use cobra alone when your CLI only needs flags and arguments without configuration file or environment variable resolution. Use both cobra and viper together when you need a layered configuration system that combines CLI flags, config files, and environment variables, with flags taking highest precedence.

What's the difference between RunE and Run in cobra commands?

RunE allows you to return errors that cobra will handle properly, while Run requires you to handle errors internally. RunE is the recommended approach as it enables cleaner error propagation and allows cobra's error handling mechanisms to work correctly with SilenceErrors and SilenceUsage settings.

What tools and dependencies are required to use this skill?

This skill requires Go installed in your environment and uses the github.com/spf13/cobra library. Optional tools include golangci-lint for linting and git for version control. The skill is compatible with Claude Code and similar AI coding agents working on Go projects.

How does cobra handle shell completions?

Cobra provides built-in shell completion generation through ValidArgsFunction and RegisterFlagCompletionFunc. You can customize completion behavior using ShellCompDirective flags to control what the shell suggests, filter results, and handle dynamic completion scenarios based on runtime context.

What are the main modes for working with cobra CLIs?

There are three primary modes: Build mode for creating new CLIs from scratch following command tree setup patterns, Extend mode for adding subcommands and flags to existing CLIs while maintaining consistency, and Review mode for auditing existing implementations against best practices like proper RunE usage and hook chain ordering.

All Files

7 files
references/flags.md3.8 KB
View
evals/evals.json19.1 KB
View
references/commands-and-args.md4.9 KB
View
references/completions.md3.9 KB
View
SKILL.md9.7 KB
View
references/generators.md2.2 KB
View
references/testing.md3.7 KB
View

Install golang-spf13-cobra

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill

Repository

samber/cc-skills-golang

Related Skills

short-form-video

14

multi-asset-morning-briefing

7,907

content-strategy

2,901

doherty-threshold

2,901