golang-cli

Design Cobra-based Go CLIs with Viper configuration and correct I/O discipline.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/dashkan/pivox --skill golang-cli-dashkan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-cli
Source: https://github.com/dashkan/pivox/tree/main/.agents/skills/golang-cli
Command: npx skills add https://github.com/dashkan/pivox --skill golang-cli-dashkan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve?

This Skill solves the recurring problem of Go CLI tools being inconsistent, hard to automate, and frustrating to debug because they mishandle flags, config, I/O streams, exit codes, and lifecycle behavior.

Core Features & Use Cases

  • Command structure & flags: Helps you design root commands, subcommands, persistent vs local flags, required/validated flags, and safe argument handling for Cobra-based CLIs.
  • Configuration layering: Guides correct Viper integration so flags, environment variables, and config files resolve with the intended precedence (and config remains optional).
  • Operational correctness: Ensures deterministic output on stdout, diagnostics on stderr, correct exit code conventions, graceful signal handling, version injection via ldflags, and practical shell completions.

Quick Start

Ask the skill to review a Cobra/Viper Go CLI design for correct Viper precedence, stdout/stderr separation, and Unix exit code behavior for the command you are implementing.

Frequently Asked Questions about golang-cli

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

FAQPage Schema
How do I set up correct configuration precedence with Viper and Cobra in a Go CLI?

Correct Viper configuration precedence in a Cobra CLI requires layering flags, environment variables, and config files so flags override env vars, which override config files. This ensures predictable resolution while keeping the config file optional.

Why should my Go CLI separate stdout and stderr streams?

Separating stdout and stderr in a Go CLI ensures deterministic I/O, keeping machine-readable output on stdout and diagnostics on stderr so automation scripts parse results cleanly without mixing errors.

How do I handle graceful signal shutdown in a Cobra-based Go CLI?

Graceful signal shutdown in a Cobra CLI uses signal.NotifyContext to propagate cancellation, allowing subcommands to clean up resources safely when receiving interrupt signals during execution.

Can I generate shell completion scripts for my Go CLI using Cobra?

Yes, Cobra supports shell completion generation for Go CLIs, providing automatic flag and subcommand completion for supported shells to improve interactive user experience.

What is the best way to propagate exit codes in a Go command-line tool?

Proper exit code propagation in a Go CLI requires mapping command execution errors to Unix exit code conventions, returning non-zero codes for failures so calling scripts detect success or failure accurately.