← ClaudeAtlas

golang-spf13-cobralisted

Build, extend, or test Go command trees when `github.com/spf13/cobra` is already used or explicitly selected. Covers command hooks, argument validators, local and persistent flags, completions, injected I/O, and isolated command tests; use a general CLI skill for framework-independent behavior.
reagin/agent-skills · ★ 0 · Code & Development · score 63
Install: claude install-skill reagin/agent-skills
# Cobra command trees Preserve the CLI's public contract: command paths, flags, arguments, output streams, help, completion, exit behavior, and compatibility. ## Inspect before editing Check `go.mod`, root-command construction, `Execute`/`ExecuteContext`, parent and child hooks, flags, argument validators, I/O, exit-code mapping, completions, generated docs, and tests. Prefer local command factories and helpers over introducing a parallel structure. ## Command execution - Use `RunE` and `*E` hooks when the handler can fail and the caller should receive the error. `Run` remains valid for genuinely infallible behavior. - Keep parsing and structural argument checks in Cobra's validation facilities when that improves help and diagnostics. Domain validation that requires loaded state can remain in the handler. - Return errors from command code instead of calling `os.Exit`; let the outermost executable choose rendering and exit status. Preserve any established typed-error or silence policy. - Pass `cmd.Context()` into cancellable work. Do not replace it with `context.Background()` inside a command. Do not assume every ancestor persistent hook runs. Child hooks and the selected traversal behavior affect inheritance. Inspect the pinned version and test the actual order before moving initialization into a parent hook. ## Flags and configuration Distinguish local and persistent flags and check for inherited-name collisions. Preserve shorthand, defaults, deprecation, requirednes