Skip to content

Commit

Permalink
Add prompt config setting and support in CanPrompt
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Sep 10, 2020
1 parent 5119d21 commit ecd1b34
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/config/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import (
"gopkg.in/yaml.v3"
)

const defaultGitProtocol = "https"
const (
defaultGitProtocol = "https"
NeverPrompt = "never"
AutoPrompt = "auto"
)

// This interface describes interacting with some persistent configuration for gh.
type Config interface {
Expand Down Expand Up @@ -167,6 +171,15 @@ func NewBlankRoot() *yaml.Node {
Kind: yaml.ScalarNode,
Value: "",
},
{
HeadComment: "When to interactively prompt. This is a global config that cannot be overriden by hostname. Supported values: auto, never",
Kind: yaml.ScalarNode,
Value: "prompt",
},
{
Kind: yaml.ScalarNode,
Value: AutoPrompt,
},
{
HeadComment: "Aliases allow you to create nicknames for gh commands",
Kind: yaml.ScalarNode,
Expand Down Expand Up @@ -476,6 +489,8 @@ func defaultFor(key string) string {
switch key {
case "git_protocol":
return defaultGitProtocol
case "prompt":
return AutoPrompt
default:
return ""
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/iostreams/iostreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func (s *IOStreams) IsStderrTTY() bool {
}

func (s *IOStreams) CanPrompt() bool {
cfg, err := s.Config()
if err == nil {
// TODO prompt is a global setting. Is this inconsistency ok? There's not a super strong case to
// set prompting by host, but it means we need to be clear about what can and can't be set per
// host.
prompt, _ := cfg.Get("", "prompt")
if prompt == config.NeverPrompt {
return false
}
}

return s.IsStdinTTY() && s.IsStdoutTTY()
}

Expand Down

0 comments on commit ecd1b34

Please sign in to comment.