golang-cli

Build and review Go CLI applications with Cobra and Viper patterns.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-cli-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-cli
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-cli
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-cli-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve?

This Skill helps you build, extend, and review Go command-line applications without missing the production details that make tools reliable under automation.

Core Features & Use Cases

  • Command Architecture: Organize root commands and subcommands with clean separation of concerns.
  • Configuration Layering: Set up flags, environment variables, and config files with predictable precedence.
  • Operational Correctness: Handle stdout versus stderr, exit codes, version injection, shell completion, signal handling, and argument validation.
  • Testing and Review: Write command tests that execute programs in-process and catch common Cobra and Viper mistakes.
  • Use Case: If you are adding a deploy or serve command to a Go tool, this Skill guides the command structure, config initialization, output discipline, and graceful shutdown behavior.

Quick Start

Ask the assistant to scaffold or review a Go Cobra CLI with proper Viper setup, stdout and stderr separation, version injection, signal handling, and command tests.

Frequently Asked Questions about golang-cli

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

FAQPage Schema
How do I structure a Go CLI with Cobra subcommands and Viper configuration?

Signal handling in a Go CLI manages graceful shutdown behavior during termination. It pairs with proper exit codes and stdout versus stderr separation to ensure your tool runs reliably under automation without losing output or hanging.

How do I test Cobra commands and Viper configuration in-process?

Testing Cobra commands in-process requires executing the program directly within your test suite rather than spawning subprocesses. This approach catches common Cobra and Viper mistakes early, validating argument validators and flag binding without external overhead.

What is the best way to inject version information into a Go CLI binary?

The best way to inject version information into a Go CLI is using ldflags version injection during the build process. This embeds version data directly into the binary, allowing your version command to report accurate build details at runtime.

Why does my Go CLI tool mix stdout and stderr during automated execution?

Go CLI tools mix stdout and stderr when output discipline is not enforced. Strict stdout and stderr separation ensures standard output contains only data while errors and diagnostics route to stderr, preventing parsing failures in automated pipelines.

Does Cobra support shell completion and argument validation for Go CLIs?

Cobra supports shell completion and argument validation for Go CLIs natively. Built-in completion commands generate scripts for supported shells, while argument validators restrict inputs before execution, ensuring operational correctness for automated and interactive use.