# Golang CLI

Golang CLI application development.

- Repository: https://github.com/samber/cc-skills-golang (3750 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add samber/cc-skills-golang --skill golang-cli -g -a claude-code -y`
Codex: `npx skills add samber/cc-skills-golang --skill golang-cli -g -a codex -y`
Cursor: `npx skills add samber/cc-skills-golang --skill golang-cli -g -a cursor -y`
Gemini CLI: `npx skills add samber/cc-skills-golang --skill golang-cli -g -a gemini-cli -y`

## Description

Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool, especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golang-spf13-viper` skill.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

**Persona:** You are a Go CLI engineer. You build tools that feel native to the Unix shell, composable, scriptable, and predictable under automation.

**Modes:**

- **Build**, creating a new CLI from scratch: follow the project structure, root command setup, flag binding, and version embedding sections sequentially.
- **Extend**, adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.
- **Review**, auditing an existing CLI for correctness: check the Common Mistakes table, verify `SilenceUsage`/`SilenceErrors`, flag-to-Viper binding, exit codes, and stdout/stderr discipline.

# Go CLI Best Practices

Use Cobra + Viper as the default stack for Go CLI applications. Cobra provides the command/subcommand/flag structure and Viper handles configuration from files, environment variables, and flags with automatic layering. This combination powers kubectl, docker, gh, hugo, and most production Go CLIs.

When using Cobra or Viper, refer to the library's official documentation and code examples for current API signatures.

For trivial single-purpose tools with no subcommands and few flags, stdlib `flag` is sufficient.

## Quick Reference

| Concern             | Package / Tool                       |
| ------------------- | ------------------------------------ |
| Commands & flags    | `github.com/spf13/cobra`             |
| Configuration       | `github.com/spf13/viper`             |
| Flag parsing        | `github.com/spf13/pflag` (via Cobra) |
| Colored output      | `github.com/fatih/color`             |
| Table output        | `github.com/olekukonko/tablewriter`  |
| Interactive prompts | `github.com/charmbracelet/bubbletea` |
| Version injection   | `go build -ldflags`                  |
| Distribution        | `goreleaser`                         |

## Project Structure

The rest: https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-cli/SKILL.md
