fix(prompter): use os.lookupenv for accessible prompter

This commit is contained in:
Kynan Ware 2025-04-08 11:38:54 -06:00
parent fb80b5bd86
commit d8d3874778
2 changed files with 13 additions and 12 deletions

View file

@ -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 {

View file

@ -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())