diff --git a/libs/cmdio/logger.go b/libs/cmdio/logger.go index 00755b78..8904ddd7 100644 --- a/libs/cmdio/logger.go +++ b/libs/cmdio/logger.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "encoding/json" + "fmt" "io" "os" @@ -72,6 +73,10 @@ func Ask(ctx context.Context, question string) (bool, error) { } func (l *Logger) Ask(question string) (bool, error) { + if l.Mode == flags.ModeJson { + return false, fmt.Errorf("question prompts are not supported in json mode") + } + l.Writer.Write([]byte(question)) ans, err := l.Reader.ReadString('\n') diff --git a/libs/cmdio/logger_test.go b/libs/cmdio/logger_test.go new file mode 100644 index 00000000..cdf8087d --- /dev/null +++ b/libs/cmdio/logger_test.go @@ -0,0 +1,14 @@ +package cmdio + +import ( + "testing" + + "github.com/databricks/bricks/libs/flags" + "github.com/stretchr/testify/assert" +) + +func TestAskFailedInJsonMode(t *testing.T) { + l := NewLogger(flags.ModeJson) + _, err := l.Ask("What is your spirit animal?") + assert.ErrorContains(t, err, "question prompts are not supported in json mode") +}