LabscoMCP early access ↗

Building a command-line tool in Go that behaves the way a terminal expects: settings that can come from a flag, a file or the environment, the right exit code on failure, and a clean stop on Ctrl-C.

WHEN TO USE

SCOPE

USE FOR

  • Structure a new Go CLI with Cobra commands, subcommands, and layered Viper configuration.
  • Bind flags to environment variables and a config file so precedence stays predictable.
  • Map internal errors to the correct Unix exit code instead of a bare crash.
  • Handle SIGINT and SIGTERM gracefully with signal.NotifyContext during shutdown.
  • Generate shell completions for bash, zsh, fish, and PowerShell.
  • Test CLI commands by capturing their output instead of hitting a real terminal.

NOT FOR

  • Not for Cobra-specific API details covered by the dedicated Cobra skill.
  • Not for Viper configuration-layering internals covered by the dedicated Viper skill.