Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/ui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

// isInteractive returns true if prompts should be shown.
// Returns false in JSON mode or when stdin is not a terminal.
// Returns false in JSON mode, when not a TTY, or when OBOL_NONINTERACTIVE=true.
func (u *UI) isInteractive() bool {
return !u.IsJSON() && u.IsTTY()
return !u.IsJSON() && u.IsTTY() && os.Getenv("OBOL_NONINTERACTIVE") != "true"
}

// Confirm asks a yes/no question, returns true for "y"/"yes".
Expand Down
33 changes: 33 additions & 0 deletions internal/ui/prompt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ui

import (
"bytes"
"testing"
)

func TestIsInteractive_OBOLNonInteractive(t *testing.T) {
u := NewForTest(&bytes.Buffer{}, &bytes.Buffer{})
u.isTTY = true // force TTY so only the env guard can suppress interactivity

if !u.isInteractive() {
t.Fatal("isInteractive() = false with TTY, human output, and OBOL_NONINTERACTIVE unset; want true")
}

t.Setenv("OBOL_NONINTERACTIVE", "true")
if u.isInteractive() {
t.Fatal("isInteractive() = true with OBOL_NONINTERACTIVE=true; want false")
}
}

func TestConfirm_OBOLNonInteractiveReturnsDefault(t *testing.T) {
u := NewForTest(&bytes.Buffer{}, &bytes.Buffer{})
u.isTTY = true
t.Setenv("OBOL_NONINTERACTIVE", "true")

if got := u.Confirm("proceed?", true); !got {
t.Fatalf("Confirm(defaultYes=true) = %v; want true without reading stdin", got)
}
if got := u.Confirm("proceed?", false); got {
t.Fatalf("Confirm(defaultYes=false) = %v; want false without reading stdin", got)
}
}
Loading