diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index e5be3dd0c..e348bf5e0 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -183,7 +183,9 @@ func ioStreams(f *cmdutil.Factory) *iostreams.IOStreams { return io } - if prompt, _ := cfg.GetOrDefault("", "prompt"); prompt == "disabled" { + if _, ghPromptDisabled := os.LookupEnv("GH_PROMPT_DISABLED"); ghPromptDisabled { + io.SetNeverPrompt(true) + } else if prompt, _ := cfg.GetOrDefault("", "prompt"); prompt == "disabled" { io.SetNeverPrompt(true) } diff --git a/pkg/cmd/factory/default_test.go b/pkg/cmd/factory/default_test.go index 7863ce933..4569e2e70 100644 --- a/pkg/cmd/factory/default_test.go +++ b/pkg/cmd/factory/default_test.go @@ -352,6 +352,7 @@ func Test_ioStreams_prompt(t *testing.T) { name string config config.Config promptDisabled bool + env map[string]string }{ { name: "default config", @@ -362,9 +363,19 @@ func Test_ioStreams_prompt(t *testing.T) { config: disablePromptConfig(), promptDisabled: true, }, + { + name: "prompt disabled via GH_PROMPT_DISABLED env var", + env: map[string]string{"GH_PROMPT_DISABLED": "1"}, + promptDisabled: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + if tt.env != nil { + for k, v := range tt.env { + t.Setenv(k, v) + } + } f := New("1") f.Config = func() (config.Config, error) { if tt.config == nil { diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index 231b102f3..361d73223 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -81,6 +81,8 @@ var HelpTopics = map[string]map[string]string{ GH_CONFIG_DIR: the directory where gh will store configuration files. Default: "$XDG_CONFIG_HOME/gh" or "$HOME/.config/gh". + + GH_PROMPT_DISABLED: set to any value to disable interactive prompting in the terminal. `), }, "reference": {