OpenParable
Skip to content
← Back to skills

Cobra Dev

Development
cobra-dev

Cobra Dev is an Agent Skill for development published in the carapace-sh/carapace repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Use when developing or debugging spf13/cobra internals — Command struct internals, ExecuteC dispatch, Find vs Traverse, flag set hierarchy, completion engine (__complete, getCompletions, ShellCompDirective), shell script generation (bash V1/V2, zsh, fish, powershell), flag group validation, global state, Levenshtein suggestions, or understanding the internal execution model. Triggers on: "cobra internals", "cobra ExecuteC", "cobra Find", "cobra Traverse", "cobra findNext", "cobra mergePersistentFlags", "cobra ParseFlags", "cobra getCompletions", "cobra __complete", "cobra completion engine", "cobra bash V2", "cobra flag resolution", "cobra flag groups internals", "cobra global state", "cobra EnablePrefixMatching", "cobra EnableCaseInsensitive", "cobra Levenshtein", "cobra stripFlags", "cobra legacyArgs", "cobra execute", "cobra preRun", "cobra postRun", "cobra mousetrap", "cobra templateFuncs".

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/carapace-sh/carapace/blob/HEAD/skills/cobra-dev/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/cobra-dev, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Cobra Development Reference

Reference for developing and debugging cobra internals. Covers the Command struct, execution flow, flag resolution, completion engine, and shell script generation.

Data Flow

os.Args[1:]
  → ExecuteC()
    → Root().ExecuteC() (always starts at root)
    → InitDefaultHelpCmd, initCompleteCmd, InitDefaultCompletionCmd
    → Find(args) or Traverse(args) (based on TraverseChildren)
      → findNext() (exact match → alias → prefix match)
    → execute(flags)
      → ParseFlags
      → ValidateArgs
      → PersistentPreRun chain (parent → child)
      → PreRun
      → ValidateRequiredFlags, ValidateFlagGroups
      → Run / RunE
      → PostRun
      → PersistentPostRun chain (child → parent)

Sub-Resources

Load the reference that matches your task. When in doubt, load multiple references.

KeywordsReference
Command struct, all fields, internal state, commands slice, parent, flags, pflags, lflags, iflags, parentsPflags, FParseErrWhitelist, CompletionOptions, commandCalledAs, ctxreferences/command-struct.md
ExecuteC, execute, Find, Traverse, findNext, stripFlags, argsMinusFirstX, legacyArgs, command resolution, flag stripping, prefix matching, TraverseChildrenreferences/execute-flow.md
Flags, PersistentFlags, LocalFlags, InheritedFlags, LocalNonPersistentFlags, NonInheritedFlags, mergePersistentFlags, ParseFlags, flag set hierarchy, parentsPflags, globNormFunc, Flag lookup, persistentFlag lookupreferences/flag-resolution.md
__complete, __completeNoDesc, getCompletions, checkIfFlagCompletion, ShellCompDirective, CompletionFunc, RegisterFlagCompletionFunc, flagCompletionFunctions, completion output format, directive handling, ValidArgsFunction, completion flowreferences/completion-engine.md
bash V1, bash V2, zsh, fish, powershell, GenBashCompletion, GenBashCompletionV2, GenZshCompletion, GenFishCompletion, GenPowerShellCompletion, script architecture, V1 vs V2 comparison, completion script internalsreferences/shell-completions.md
flag groups, MarkFlagsRequiredTogether, MarkFlagsMutuallyExclusive, MarkFlagsOneRequired, ValidateFlagGroups, processFlagForGroupAnnotation, annotation storage, requiredAsGroupAnnotation, oneRequiredAnnotation, mutuallyExclusiveAnnotation, enforceFlagGroupsForCompletionreferences/flag-groups-internals.md
global state, OnInitialize, OnFinalize, initializers, finalizers, EnablePrefixMatching, EnableCaseInsensitive, EnableCommandSorting, EnableTraverseRunHooks, templateFuncs, AddTemplateFunc, MousetrapHelpText, MousetrapDisplayDuration, CheckErr, Gt, Eqreferences/global-state.md
suggestions, Levenshtein, findNext, prefix matching, case-insensitive, SuggestFor, SuggestionsMinimumDistance, DisableSuggestions, ld function, hasNameOrAliasPrefix, commandNameMatchesreferences/suggestions.md

Quick Guide

Cross-Project References

  • For user-facing cobra topics (creating commands, defining flags, argument validation, lifecycle hooks, help/usage, completions API, Viper integration), use the cobra skill.
  • For pflag internals (non-POSIX modes, carapace-pflag extensions), use the carapace-dev skill → references/pflag.md.