diff --git a/internal/prompter/prompter.go b/internal/prompter/prompter.go index 913b1a5e7..2c027c184 100644 --- a/internal/prompter/prompter.go +++ b/internal/prompter/prompter.go @@ -3,6 +3,7 @@ package prompter import ( "fmt" "os" + "slices" "strings" "github.com/AlecAivazis/survey/v2" @@ -43,17 +44,10 @@ type Prompter interface { } func New(editorCmd string, stdin ghPrompter.FileReader, stdout ghPrompter.FileWriter, stderr ghPrompter.FileWriter) Prompter { - accessiblePrompterValue := os.Getenv("GH_SPEECH_SYNTHESIZER_FRIENDLY_PROMPTER") - switch accessiblePrompterValue { - case "", "false", "0", "no": - return &surveyPrompter{ - prompter: ghPrompter.New(stdin, stdout, stderr), - stdin: stdin, - stdout: stdout, - stderr: stderr, - editorCmd: editorCmd, - } - default: + accessiblePrompterValue, accessiblePrompterIsSet := os.LookupEnv("GH_SPEECH_SYNTHESIZER_FRIENDLY_PROMPTER") + falseyValues := []string{"false", "0", "no", ""} + + if accessiblePrompterIsSet && !slices.Contains(falseyValues, accessiblePrompterValue) { return &speechSynthesizerFriendlyPrompter{ stdin: stdin, stdout: stdout, @@ -61,6 +55,14 @@ func New(editorCmd string, stdin ghPrompter.FileReader, stdout ghPrompter.FileWr editorCmd: editorCmd, } } + + return &surveyPrompter{ + prompter: ghPrompter.New(stdin, stdout, stderr), + stdin: stdin, + stdout: stdout, + stderr: stderr, + editorCmd: editorCmd, + } } type speechSynthesizerFriendlyPrompter struct { diff --git a/internal/prompter/speech_synthesizer_friendly_prompter_test.go b/internal/prompter/speech_synthesizer_friendly_prompter_test.go index 74b053072..64e9ac2fe 100644 --- a/internal/prompter/speech_synthesizer_friendly_prompter_test.go +++ b/internal/prompter/speech_synthesizer_friendly_prompter_test.go @@ -432,7 +432,6 @@ func TestSurveyPrompter(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { testCloser(t, console) }) - t.Setenv("GH_SPEECH_SYNTHESIZER_FRIENDLY_PROMPTER", "") // Using echo as the editor command here because it will immediately exit // and return no input. p := prompter.New("echo", console.Tty(), console.Tty(), console.Tty())