mirror of https://github.com/databricks/cli.git
Error out if question prompts are used in json mode (#340)
## Changes This PR disallows questions in json mode ## Tests Manually and unit test ``` shreyas.goenka@THW32HFW6T job-output % bricks bundle destroy --progress-format=json The following resources will be removed: { "resource_type": "databricks_job", "action": "delete", "resource_name": "foo" } Error: question prompts are not supported in json mode ```
This commit is contained in:
parent
598ad62688
commit
ddc0237468
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
@ -72,6 +73,10 @@ func Ask(ctx context.Context, question string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Ask(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))
|
l.Writer.Write([]byte(question))
|
||||||
ans, err := l.Reader.ReadString('\n')
|
ans, err := l.Reader.ReadString('\n')
|
||||||
|
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue