Add TTY detection for non-interactive environments#210
Open
Conversation
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 <[email protected]>
tashian
added a commit
to smallstep/cli
that referenced
this pull request
Jan 22, 2026
Add 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 <[email protected]>
4 tasks
hslatman
reviewed
Jan 26, 2026
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 <[email protected]>
- 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 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds TTY detection and contextual error messages for non-interactive environments (systemd services, GitHub Actions, Ansible, Docker containers).
Changes
New
CanPrompt()function (ui/ui.go)STEP_NON_INTERACTIVEenv var first (returns false if set to1ortrue)/dev/ttyis availableNew
WithField()option (ui/options.go)ui.Prompt("Enter name:", ui.WithField("PKI name", "name"))cannot prompt for PKI name: use --name to specify this value non-interactivelyNew
RequiredInputErrortype (errs/errs.go)Updated prompt functions (
ui/ui.go)Prompt(),PromptPassword(),PromptPasswordGenerate(),PromptYesNo(), andSelect()now checkCanPrompt()before attempting terminal interactionWithField()option for contextual error messagesOther
go-isattyfrom indirect to direct dependencyCanPrompt()behavior withSTEP_NON_INTERACTIVEenv varUsage
Test plan
Companion PR: smallstep/cli#1553
Fixes smallstep/cli#674
🤖 Generated with Claude Code