cobra-dev

Document spf13/cobra internals for command resolution, execution flow, and shell completion.

1.4k|36|Updated Mar 17, 2020
One-click install
npx skills add https://github.com/carapace-sh/carapace --skill cobra-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cobra-dev
Source: https://github.com/carapace-sh/carapace/tree/main/skills/cobra-dev
Command: npx skills add https://github.com/carapace-sh/carapace --skill cobra-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Developers need a centralized, actionable guide to understand and debug Cobra's internal mechanics, including command resolution, execution flow, and the completion engine, to build robust CLI applications with spf13/cobra.

Core Features & Use Cases

  • Detailed references covering the Command struct, ExecuteC flow, Find vs Traverse, flag set hierarchy, and global state.
  • Insight into shell script generation and shell completion internals across Bash, Zsh, Fish, and PowerShell.
  • Practical guidance for troubleshooting, performance considerations, and extending Cobra internals.

Quick Start

Open this guide and follow the sections on ExecuteC, Find vs Traverse, and the completion engine to quickly understand Cobra's internal flow.

Frequently Asked Questions about cobra-dev

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

FAQPage Schema
How does Cobra's ExecuteC dispatch work internally?

Cobra's ExecuteC dispatch handles root command execution by traversing the command tree to find the target command, binding flags, and invoking the appropriate Run function. This skill documents the complete ExecuteC execution flow for debugging.

What is the difference between Find and Traverse resolution in spf13/cobra?

Find resolution matches arguments against child commands sequentially, while Traverse resolves commands recursively through nested trees without requiring exact prefix matches. This skill explains Find vs Traverse resolution for debugging command routing.

How do I debug Cobra flag set hierarchy and global state in Golang CLI applications?

Debugging Cobra flag set hierarchy requires understanding how persistent flags inherit down the command tree and how global state propagates during execution. This skill provides references for troubleshooting flag set hierarchy and global state management.

How does Cobra's shell completion engine work across Bash, Zsh, Fish, and PowerShell?

Cobra's shell completion engine generates dynamic completion scripts for Bash, Zsh, Fish, and PowerShell by hooking into shell native completion systems. This skill documents shell script generation and dynamic completion behavior across V1 and V2 scripts.

Can I use this guide to extend spf13/cobra internals for custom command resolution?

Yes, this skill provides structured references for extending Cobra internals, including modifying command resolution and execution flow. It covers the Command struct and internal mechanics needed to build and extend custom CLI behaviors.

Why are my Cobra subcommands not resolving correctly during execution?

Subcommand resolution failures often stem from mismatched Find versus Traverse logic or improper flag set hierarchy binding during ExecuteC dispatch. This skill helps troubleshoot command resolution and execution flow issues within spf13/cobra internals.