Add TTY detection for non-interactive environments by tashian · Pull Request #210 · smallstep/cli-utils
Add CanPrompt() function to check if a terminal is available before attempting interactive prompts. This helps provide better error messages in non-interactive environments like systemd services, GitHub Actions, Ansible, or Docker containers. Changes: - Add CanPrompt() in ui/ui.go that checks stdin and /dev/tty - Add RequiredInputError type in errs/errs.go for descriptive errors - Improve error messages in preparePromptTerminal/prepareSelectTerminal - Add golang.org/x/term dependency for terminal detection Fixes smallstep/cli#674 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tashian added a commit to smallstep/cli that referenced this pull request
Jan 22, 2026Add support for non-interactive environments by: - Adding --non-interactive global flag (also STEP_NON_INTERACTIVE env var) - Checking for terminal availability before prompting for passwords - Returning helpful error messages when prompts fail in CI/systemd/Docker This change requires smallstep/cli-utils#210 which adds: - ui.CanPrompt() for TTY detection - errs.RequiredInputError for descriptive error messages Fixes #674 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address review feedback: - Replace golang.org/x/term with go-isatty (already an indirect dep) - Add Cygwin terminal detection for better Windows support - Improve generic error message to guide users to --help Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- CanPrompt() now checks STEP_NON_INTERACTIVE env var first, returning false when set to "1" or "true" - Prompt(), PromptPassword(), and Select() now check CanPrompt() before attempting to prepare the terminal, providing clearer error messages - Added tests for CanPrompt() non-interactive mode behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters