AGENT SKILL

go-cli-command-design

Design and review predictable Go command-line interfaces with canonical names and flags; explicit inputs and precedence; human, plain, and structured output; safe prompting; stdout and stderr contracts; help; errors; exit codes; cancellation; dependency injection; and platform behavior. Use when creating a Go CLI, changing its public command contract, making command code testable, or reviewing compatibility for people, scripts, AI agents, and CI.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 1.6k
Forks
491

01 前言 Front Matter

name
go-cli-command-design
license
MIT
metadata
{ "tags": "go,golang,cli,command-design,flags,streams,portability", "version": "0.4.0", "category": "Go", "displayName": "Go CLI Command Design" }
description
Design and review predictable Go command-line interfaces with canonical names and flags; explicit inputs and precedence; human, plain, and structured output; safe prompting; stdout and stderr contracts; help; errors; exit codes; cancellation; dependency injection; and platform behavior. Use when creating a Go CLI, changing its public command contract, making command code testable, or reviewing compatibility for people, scripts, AI agents, and CI.
compatibility
Codex, Claude Code, and other Agent Skills-compatible clients.

02 资源文件 7

03 SKILL.md 正文

Go CLI Command Design

Design the command as a public interface before treating it as an implementation. Keep results pipeable, failures diagnosable, and process-global state at the edge.

Core Workflow

  1. State the command purpose, invocation syntax, callers, and compatibility promises.
  2. Assign each input to a flag, operand, stdin, environment, or config source.
  3. Define precedence, validation, conflicts, defaults, and blocking behavior.
  4. Reserve stdout for results and requested help; use stderr for diagnostics, invalid-usage help, and progress.
  5. Return errors from command logic and map exit codes at the process boundary.
  6. Inject streams, configuration, and effects behind a small testable runner.
  7. Verify help, invalid usage, operational failures, and supported target behavior.
  8. Verify noninteractive, color-disabled, canceled, and short-reading pipe behavior.

Read Next

Task Load
Design or change a complete command contract guidelines.md, workflows/design-command-interface.md
Implement flags, streams, environment, or errors references/command-interface/rules.md, references/command-interface/examples.md
Understand the design rationale references/command-interface/knowledge.md
Review an existing command references/command-interface/checklist.md

Guardrails

  • Prefer a dedicated flag.FlagSet over package-global flags in reusable code.
  • Do not read stdin unless the documented invocation requires it.
  • Do not call os.Exit below the outer process boundary.
  • Treat structured output, exact text, and exit codes as APIs when automation relies on them.
  • Never prompt, animate, or emit ANSI sequences in structured or noninteractive mode.
  • Treat closed downstream pipes as normal pipeline termination when appropriate.
  • Cross-compilation does not replace target-level smoke testing.

Source Notes

Guidance is transformed and paraphrased from Ricardo Gerardi, Powerful Command-Line Applications in Go (Pragmatic Bookshelf, 2021), especially Chapters 1-2. Examples are original adaptations.

Modern interaction, cancellation, and output-mode guidance also incorporates transformed material from Marian Montagnino, Building Modern CLI Applications in Go (Packt, 2023), especially Chapters 1, 5, 8, and 10.

Book: https://pragprog.com/titles/rggo/powerful-command-line-applications-in-go/

Modern API details should be verified against https://pkg.go.dev/flag and the current Go documentation before implementation.

Parser grammar and validation guidance also incorporates transformed material from Inanc Gumus, Go by Example: Programmer's Guide to Idiomatic and Testable Programs (Manning, 2025), Chapter 4.

04 同仓库更多 Skills

hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-review-with-annotations

Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-find-and-synthesize-context

Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-update-docs

Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-manage-records

Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-create-or-manage-interactive-html

Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.

★ 1.6k
hashgraph-online
hashgraph-online/awesome-codex-plugins

worktable-collaborate-threads

Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.

★ 1.6k