Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip interactive survey if devbox is not executed in a terminal #867

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

LucilleH
Copy link
Collaborator

@LucilleH LucilleH commented Apr 5, 2023

Summary

Skip interactive survey if devbox is not executed in a terminal. When devbox init or devbox generate direnv is called in a dockerfile for example, we do not want to prompt for user input.

I tried echo 'y' | devbox generate direnv or yes | devbox generate direnv or devbox generate direnv <<< "y". None of them worked.

Bug in the survey package: AlecAivazis/survey#394

How was it tested?

devbox run build
./dist/devbox init (interactive mode)

docker build -t devbox-cli .
docker run --entrypoint=/bin/sh -ti devbox-cli (non interactive mode)

Copy link
Collaborator

@mohsenari mohsenari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this

if err != nil {
return errors.WithStack(err)

if isatty.IsTerminal(os.Stdin.Fd()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the result a bool outside of the if so we only need to do isatty once? Something like:

enableDirEnv := true
if isatty.IsTerminal(os.Stdin.Fd()) {
	// ...
	enableDirEnv := strings.ToLower(result) == "y"
}

if enableDirEnv {
	// ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants