Skip to content

Latest commit

Β 

History

History
118 lines (87 loc) Β· 2.73 KB

File metadata and controls

118 lines (87 loc) Β· 2.73 KB

CLI Design Cheat Sheet

One-page reference for CLI design. Print-friendly version of essential principles and patterns.

🎯 Core Principles

Obvious Over Clever β€’ Helpful Over Minimal β€’ Consistent Over Special β€’ Human-First, Machine-Friendly

βœ… Quick Checklist

β–‘ --help everywhere     β–‘ Examples in help      β–‘ Meaningful errors
β–‘ Exit codes work       β–‘ Progress >1 second    β–‘ No config required
β–‘ --json for machines   β–‘ --dry-run safety      β–‘ Piping works

πŸ“ Command Patterns

simple-tool [options] <args>              # curl, jq, grep
tool <command> [options] [args]           # git, docker, npm
tool <resource> <action> [options]        # kubectl, aws

🚨 Error Template

Error: What went wrong
  Why it happened
  How to fix it
Example: tool <correct-usage>

🎨 Output Design

# Default: Human readable
$ tool list
NAME    STATUS   TIME
app-1   running  2h ago

# Pipe: Auto plain text
$ tool list | grep running
app-1   running   2h

# Explicit: Machine format
$ tool list --json
[{"name":"app-1",...}]

πŸ—οΈ Standard Flags

-h, --help        Help text
-v, --version     Version info
-v, --verbose     More output
-q, --quiet       Less output
-y, --yes         No prompts
-n, --dry-run     Preview only
--json            JSON output
--no-color        Plain text

πŸ”„ Progress Patterns

# Spinner (unknown duration)
Loading... β Ό

# Bar (known duration)
[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘] 80% ETA: 2s

# Steps (multiple ops)
βœ“ Build complete
βœ“ Tests passed
β Ό Deploying...

πŸ’‘ Quick Wins

  1. Add examples to help text
  2. Show progress for operations >1s
  3. Suggest fixes in error messages
  4. Support --dry-run for safety
  5. Auto-detect TTY vs pipe

🚫 Top Anti-Patterns

❌ Mystery commands: mkcfg 3 p
❌ Useless errors: Error: ENOENT
❌ No feedback: deploying... (5 min)
❌ Required config for basics
❌ Breaking pipes and scripts

🎯 Decision Guide

Need subcommands? β†’ More than 5 operations
Interactive mode? β†’ Complex/dangerous operations
JSON output? β†’ Always offer via flag
Color output? β†’ Only in TTY, respect NO_COLOR
Config files? β†’ Optional with good defaults

πŸ” Testing Checklist

  • Works with no arguments
  • Pipes chain correctly
  • Errors are helpful
  • --help is comprehensive
  • Exit codes meaningful
  • Works on Win/Mac/Linux

πŸ“š Learn More

Principles β€’ Patterns β€’ Anti-Patterns β€’ Quick Start


Based on clig.dev, Atlassian, GNU, and Heroku guidelines. Keep this handy when designing CLIs!