|
| 1 | +--- |
| 2 | +id: CLI handbook |
| 3 | +title: Command-line interface handbook |
| 4 | +source: overview |
| 5 | +section: developer-resources |
| 6 | +--- |
| 7 | + |
| 8 | +# Designing for command-line interfaces |
| 9 | + |
| 10 | +Our CLI handbook offers best practices for designing consistent, usable, and developer-friendly command-line interfaces (CLIs). It supports developers building CLI tools and designers collaborating on technical products. These guidelines are particularly helpful for environments where CLI tools are the primary or critical part of the user experience, emphasizing clarity, structure, and user-centered design across command syntax, help documentation, error messaging, and interactive behaviors. |
| 11 | + |
| 12 | +## Accessibility considerations |
| 13 | + |
| 14 | +While CLIs don't have visual UI elements, many [accessibility principles](/accessibility/about-accessibility/) still apply. |
| 15 | + |
| 16 | +Accessibility matters in CLI design just as much as it does in graphical interfaces. Clear, inclusive output ensures all users can successfully interact with the tool—including those using screen readers or alternative input devices. |
| 17 | + |
| 18 | +To ensure a CLI's accessibility, adhere to the following additional color, content, and testing practices. |
| 19 | + |
| 20 | +### Color |
| 21 | + |
| 22 | +<div class="ws-content-table"> |
| 23 | + |
| 24 | +| **Don't** | **Do** | |
| 25 | +| --- | --- | |
| 26 | +| Don’t convey meaning through color alone. | Do use text alongside color-based cues. For example, “Success” and “Error” labels. | |
| 27 | +| | Do use text alongside red/green indicators, to make the information accessible to colorblind users. | |
| 28 | + |
| 29 | +</div> |
| 30 | + |
| 31 | +### Content |
| 32 | + |
| 33 | +<div class="ws-content-table"> |
| 34 | + |
| 35 | +| **Don't** | **Do** | |
| 36 | +| --- | --- | |
| 37 | +| Don't use vague terms like “it failed”.| Do be direct and transparent with descriptive, specific language. | |
| 38 | +| Don’t assume users can infer meaning from context alone.| Do use descriptive text for prompts and feedback. | |
| 39 | +| Don't use prompt flows that require visual scanning without clear text guidance. | Do ensure all commands and prompts are keyboard-accessible and non-interactive-safe. <br/><br/> Do use flags like `--non-interactive` for scripting or assistive tech users. | |
| 40 | +| Don't use overly styled ASCII tables, long walls of text, or dynamic animations. | Do use plain, structured output that screen readers can parse. <br/><br/> Do use clean, labeled output with headings, bullet points, or clear separators. | |
| 41 | +</div> |
| 42 | + |
| 43 | +### Testing |
| 44 | + |
| 45 | +<div class="ws-content-table"> |
| 46 | + |
| 47 | +| **Don't** | **Do** | |
| 48 | +| --- | --- | |
| 49 | +| Don't assume that your design is accessible. | Do test with screen readers and colorblind simulators to reveal subtle issues in contrast, clarity, and verbosity. | |
| 50 | +</div> |
| 51 | + |
| 52 | +### Example |
| 53 | + |
| 54 | +Accessible: |
| 55 | + |
| 56 | +```plaintext |
| 57 | +✅ Deployment successful. |
| 58 | +Run `tool status` to check environment health. |
| 59 | +``` |
| 60 | + |
| 61 | +Less accessible: |
| 62 | + |
| 63 | +```plaintext |
| 64 | +✅ You did it! |
| 65 | +``` |
| 66 | + |
| 67 | +## CLI inputs |
| 68 | + |
| 69 | +To write effectively for CLIs, it is important to understand the different elements of CLI inputs: |
| 70 | +1. **[Command name:](#command-names)** Identifies the action a command will perform and the subject that the action applies to. |
| 71 | +1. **[Arguments:](#arguments)** Additional details used alongside the command name, which users select to specify the way that a command is applied. |
| 72 | +1. **[Flags:](#flags)** Named parameters that modify the behavior of the command. |
| 73 | + |
| 74 | +### Commands |
| 75 | + |
| 76 | +A command describes the action triggered by the CLI. |
| 77 | + |
| 78 | +Command names should consistently use a verb-noun structure: |
| 79 | +- **Verb:** The action performed. |
| 80 | +- **Noun:** The resource or object affected. |
| 81 | + |
| 82 | +This structure mirrors how people think about tasks, making commands more intuitive and discoverable. The verb-noun format also aligns with widely-used CLIs like `git`, `kubectl`, and `docker`. In contrast, noun-verb structures can be harder to parse and don't scale well. |
| 83 | + |
| 84 | +#### Example |
| 85 | + |
| 86 | +In the following code block, `create project`, `delete environment`, and `scale deployment` are all commands. |
| 87 | + |
| 88 | +```bash |
| 89 | +tool create project |
| 90 | +tool delete environment |
| 91 | +tool scale deployment |
| 92 | +``` |
| 93 | + |
| 94 | +### Arguments |
| 95 | + |
| 96 | +Arguments are non-flag values following a command, typically unique identifiers like file paths or project names. |
| 97 | + |
| 98 | +A command requires an argument in order to execute. While multiple arguments can be used, their order matters. Fewer arguments are preferable to support easier recall and avoid confusion. |
| 99 | + |
| 100 | +#### Example |
| 101 | + |
| 102 | +In the following code block, `delete project` and `deploy environment` are commands, while `my-app` and `production` are arguments that represent the object being acted on. |
| 103 | + |
| 104 | +```bash |
| 105 | +tool delete project my-app |
| 106 | +tool deploy environment production |
| 107 | +``` |
| 108 | + |
| 109 | +### Flags |
| 110 | + |
| 111 | +Flags are named parameters, prefixed with 2 hyphens (--), that modify the behavior of a command. They allow users to specify command modifiers, options, or other non-essential configuration. Flags can be added in any order. |
| 112 | + |
| 113 | +#### Example |
| 114 | + |
| 115 | +In the following code block, `--env`, `--force`, `--role`, and `--email` are flags. |
| 116 | + |
| 117 | +```bash |
| 118 | +tool deploy --env staging --force |
| 119 | +tool create user --role admin --email user@Examples:.com |
| 120 | +``` |
| 121 | + |
| 122 | +#### Long-form and short-form |
| 123 | + |
| 124 | +There are 2 forms for flags: |
| 125 | + |
| 126 | +1. **Long-form flags:** More descriptive and clear. |
| 127 | + |
| 128 | + ```bash |
| 129 | + tool deploy app --enable-autoscaling |
| 130 | + tool configure user --assign-admin-privileges |
| 131 | + tool update cluster --set-min-replicas 3 |
| 132 | + ``` |
| 133 | +1. **Short-form flags:** More concise, with 1-2 letters. |
| 134 | + |
| 135 | + - Reserve for frequently-used options. This benefits experienced users who prefer speed and situations with limited space. |
| 136 | + - When possible, pair with long-form equivalents for better clarity and discoverability. |
| 137 | + |
| 138 | + ```bash |
| 139 | + tool --help # Long-form |
| 140 | + tool -h # Short-form (Help) |
| 141 | + |
| 142 | + tool --verbose # Long-form |
| 143 | + tool -v # Short-form (Verbose) |
| 144 | + |
| 145 | + tool --config path/to/file |
| 146 | + tool -c path/to/file # Short-form (Config file path) |
| 147 | + ``` |
| 148 | + |
| 149 | +#### Types of flags |
| 150 | + |
| 151 | +1. **Boolean flags:** Represent on/off or true/false options. |
| 152 | + |
| 153 | + - Set a sensible default. |
| 154 | + - Don’t require explicit values unless necessary. For example, allow `--force` rather than `--force=true`. |
| 155 | + |
| 156 | + ```bash |
| 157 | + tool deploy --dry-run # Runs without executing |
| 158 | + tool delete --force # Skips confirmation prompt |
| 159 | + ``` |
| 160 | + |
| 161 | +2. **Help flags:** Provide help documentation that explains a command's purpose, its arguments/flags, and usage examples. |
| 162 | +
|
| 163 | + - Offer both long `--help` and short `-h` options. |
0 commit comments