CLI

Referenz

Warum CLI

  • Flexibel
  • Transparent

Principles

  • Benutzerfreundlichkeit
    • Human readable
    • Verwendung nicht nur von anderen Programmen
  • Einfache Bausteine
    • Kombinieren von kleinen, einfachen Programmen zu groesserem System
    • Pipes und Filterarchitektur
    • Kombinierbar durch stdin/stdout/stderr, signals, exit-codes
  • Konsistenz über Programme hinweg
    • Bereits bestehenden Mustern folgen
    • Intuitiv
  • Robustheit
    • Falscher input muss korrekt behandelt werden

Guidelines

  • Use a command-line argument parsing library where you can
  • Return zero exit code on success, non-zero on failure.
  • Send output to stdout
  • Send messaging to stderr
  • Display help text when passed no options, the -h flag, or the --help flag
  • Display a concise help text by default
    • A description of what your program does
    • One or two example invocations.
    • Descriptions of flags
  • Display help for Subcommands (like git commit --help)
  • In help text, link to the web version of the documentation
  • Lead with examples

Output

  • Human-readable output is paramount
  • Have machine-readable output where it does not impact usability
  • If human-readable output breaks machine-readable output, use --plain to display output in plain, tabular text format for integration with tools like grep or awk
  • If you change state, tell the user.
  • Make it easy to see the current state of the system
  • Use color with intention
  • Disable color if your program is not in a terminal or the user requested it

Errors

Arguments and Flags

Subcommands

Configuration and Environment Variables