CL

Interactive CLI

Interactive prompts, confirmation dialogs, and wizard-style flows for CLI applications

Details

Language / Topic
_UUniversal
Category
Architecture

Rules

balanced
- Only prompt interactively when stdin is a TTY. When piped or in CI, use flags/env vars for all input or fail with a clear message.
- Require explicit confirmation for destructive operations: "This will delete 47 files. Continue? [y/N]". Default to the safe option (No).
- Provide a --yes/-y flag to skip all confirmation prompts for scripting and automation. Document this in --help.
- Show sensible defaults in prompts: "Enter port [3000]:" — pressing Enter accepts the default.
- Detect CI environments (CI=true, GITHUB_ACTIONS, JENKINS_URL) and disable all interactive prompts automatically. Fail with instructions to pass the required flags.
- Implement wizard-style flows for complex setup: guide users through steps sequentially, show progress (Step 2 of 5), allow going back to previous steps.
- Validate interactive input immediately and re-prompt on invalid input with the reason: "Invalid email format. Enter email: ".
- Use arrow-key selection for multiple-choice prompts instead of asking users to type option numbers. Fall back to numbered input on non-TTY.
- Preview the result of a destructive operation before confirming: show a diff, a list of affected items, or a summary of what will change.
- Support --dry-run for all operations that modify state. Show exactly what would happen without making changes.