add browser option to config

Allows setting the path to the browser using the config.

Closes #858
This commit is contained in:
Des Preston 2021-07-13 15:06:40 -04:00
parent 161de77fd7
commit c95f30af80
2 changed files with 20 additions and 2 deletions

View file

@ -8,8 +8,8 @@ import (
// This interface describes interacting with some persistent configuration for gh.
type Config interface {
Get(string, string) (string, error)
GetWithSource(string, string) (string, string, error)
Get(hostname string, key string) (string, error)
GetWithSource(hostname string, key string) (string, string, error)
Set(string, string, string) error
UnsetHost(string)
Hosts() ([]string, error)
@ -55,6 +55,11 @@ var configOptions = []ConfigOption{
Description: "the path to a unix socket through which to make HTTP connection",
DefaultValue: "",
},
{
Key: "browser",
Description: "the path to the browser to use when opening URLs",
DefaultValue: "",
},
}
func ConfigOptions() []ConfigOption {

View file

@ -89,8 +89,21 @@ func httpClientFunc(f *cmdutil.Factory, appVersion string) func() (*http.Client,
}
}
// browser returns the path to the browser. Attempts to read a path from Config,
// and falls back to the $BROWSER env var if Config value is blank.
func browser(f *cmdutil.Factory) cmdutil.Browser {
io := f.IOStreams
cfg, err := f.Config()
if err != nil {
fmt.Fprintf(io.ErrOut, "problem loading config %s", err)
}
fromConfig, err := cfg.Get("", "browser")
if err == nil && fromConfig != "" {
return cmdutil.NewBrowser(fromConfig, io.Out, io.ErrOut)
}
return cmdutil.NewBrowser(os.Getenv("BROWSER"), io.Out, io.ErrOut)
}