Skip to content

Commit c95f30a

Browse files
committed
add browser option to config
Allows setting the path to the browser using the config. Closes cli#858
1 parent 161de77 commit c95f30a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

internal/config/config_type.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88

99
// This interface describes interacting with some persistent configuration for gh.
1010
type Config interface {
11-
Get(string, string) (string, error)
12-
GetWithSource(string, string) (string, string, error)
11+
Get(hostname string, key string) (string, error)
12+
GetWithSource(hostname string, key string) (string, string, error)
1313
Set(string, string, string) error
1414
UnsetHost(string)
1515
Hosts() ([]string, error)
@@ -55,6 +55,11 @@ var configOptions = []ConfigOption{
5555
Description: "the path to a unix socket through which to make HTTP connection",
5656
DefaultValue: "",
5757
},
58+
{
59+
Key: "browser",
60+
Description: "the path to the browser to use when opening URLs",
61+
DefaultValue: "",
62+
},
5863
}
5964

6065
func ConfigOptions() []ConfigOption {

pkg/cmd/factory/default.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,21 @@ func httpClientFunc(f *cmdutil.Factory, appVersion string) func() (*http.Client,
8989
}
9090
}
9191

92+
// browser returns the path to the browser. Attempts to read a path from Config,
93+
// and falls back to the $BROWSER env var if Config value is blank.
9294
func browser(f *cmdutil.Factory) cmdutil.Browser {
9395
io := f.IOStreams
96+
97+
cfg, err := f.Config()
98+
if err != nil {
99+
fmt.Fprintf(io.ErrOut, "problem loading config %s", err)
100+
}
101+
102+
fromConfig, err := cfg.Get("", "browser")
103+
if err == nil && fromConfig != "" {
104+
return cmdutil.NewBrowser(fromConfig, io.Out, io.ErrOut)
105+
}
106+
94107
return cmdutil.NewBrowser(os.Getenv("BROWSER"), io.Out, io.ErrOut)
95108
}
96109

0 commit comments

Comments
 (0)