cli-standard

Scaffold interactive Go CLI tools using Cobra, survey, and color with progressive interaction patterns.

3|1|Updated Apr 14, 2026
One-click install
npx skills add https://github.com/ZHLX2005/sl --skill cli-standard-zhlx2005
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cli-standard
Source: https://github.com/ZHLX2005/sl/tree/main/skills/cli-standard
Command: npx skills add https://github.com/ZHLX2005/sl --skill cli-standard-zhlx2005

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/spf13/cobra, github.com/AlecAivazis/survey/v2, github.com/fatih/color, and includes references (resource) components.

What problem does it solve? Building interactive Go command-line tools from scratch involves repetitive decisions about project structure, flag handling, interactive prompts, colored output, and testing strategy. This Skill provides a complete, opinionated standard so every CLI you create follows the same proven architecture without re-deriving these decisions. ## Core Features & Use Cases - Standard Project Skeleton: Defines the canonical directory layout (cmd/, internal/color, internal/ui, internal/<domain>, docs/, test/scenario) with ready-to-use code templates for the five mandatory files. - Progressive 3-Mode Interaction: Every command supports full-interactive, hybrid (partial flags + prompts), and fully automated (--yes) execution modes, with flag-to-prompt fallback built in. - Transaction Safety & Scenario Testing: Enforces collect-confirm-execute patterns for risky operations and real end-to-end scenario tests using temporary directories instead of mocks. - Use Case: When asked to build a new CLI tool for git workflows, Docker management, or API operations, this Skill generates the full scaffold with an interactive command selector, colored step-by-step output, Chinese documentation conventions, and E2E tests. ## Quick Start Create a new Go CLI tool for managing Docker containers following the cli-standard structure with interactive prompts and scenario tests.

Frequently Asked Questions about cli-standard

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

FAQPage Schema
How do I create an interactive CLI tool in Go with Cobra?

Combine Cobra for command definitions with survey/v2 for interactive prompts and fatih/color for terminal output. Structure the project with cmd/ for commands, internal/ui for prompt wrappers, and internal/color for color helpers, then add a root command that shows an interactive selector when run without arguments.

How to make Cobra commands work both interactively and in scripts?

Use progressive three-mode execution: check if each flag is empty, and only prompt interactively for missing values. Add a --yes flag to skip confirmations, so the same command runs fully automated in CI/CD pipelines while remaining interactive in terminals.

What is the difference between survey/v2 and Cobra for Go CLIs?

Cobra handles command routing, flags, and help generation, while survey/v2 provides interactive prompts like input fields, confirmations, and select menus. They serve complementary roles and are typically used together in interactive CLI tools.

Why does my Cobra command print usage help after running successfully?

This happens when RunE returns without an explicit return nil at the end. Cobra interprets a missing or non-nil return as an error condition and displays the usage text, so always end RunE functions with return nil on success.

How should I test interactive CLI commands in Go?

Prefer scenario-level end-to-end tests over mocks: create a temporary directory, set up a real environment such as an actual git repository, execute the compiled command with --yes flags via os/exec, and assert on the resulting state and output.