From d8d3874778038fb5de581b7ed93b4e9bbaa4f185 Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Tue, 8 Apr 2025 11:38:54 -0600 Subject: [PATCH] fix(prompter): use os.lookupenv for accessible prompter --- internal/prompter/prompter.go | 24 ++++++++++--------- ...eech_synthesizer_friendly_prompter_test.go | 1 - 2 files changed, 13 insertions(+), 12 deletions(-) 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())