diff --git a/internal/config/config.go b/internal/config/config.go index 0b5adc3dd..3a6cdf4d7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -163,7 +163,7 @@ func (c *cfg) CacheDir() string { } func defaultFor(key string) o.Option[string] { - for _, co := range ConfigOptions() { + for _, co := range Options { if co.Key == key { return o.Some(co.DefaultValue) } @@ -516,59 +516,57 @@ type ConfigOption struct { CurrentValue func(c gh.Config, hostname string) string } -func ConfigOptions() []ConfigOption { - return []ConfigOption{ - { - Key: gitProtocolKey, - Description: "the protocol to use for git clone and push operations", - DefaultValue: "https", - AllowedValues: []string{"https", "ssh"}, - CurrentValue: func(c gh.Config, hostname string) string { - return c.GitProtocol(hostname) - }, +var Options = []ConfigOption{ + { + Key: gitProtocolKey, + Description: "the protocol to use for git clone and push operations", + DefaultValue: "https", + AllowedValues: []string{"https", "ssh"}, + CurrentValue: func(c gh.Config, hostname string) string { + return c.GitProtocol(hostname) }, - { - Key: editorKey, - Description: "the text editor program to use for authoring text", - DefaultValue: "", - CurrentValue: func(c gh.Config, hostname string) string { - return c.Editor(hostname) - }, + }, + { + Key: editorKey, + Description: "the text editor program to use for authoring text", + DefaultValue: "", + CurrentValue: func(c gh.Config, hostname string) string { + return c.Editor(hostname) }, - { - Key: promptKey, - Description: "toggle interactive prompting in the terminal", - DefaultValue: "enabled", - AllowedValues: []string{"enabled", "disabled"}, - CurrentValue: func(c gh.Config, hostname string) string { - return c.Prompt(hostname) - }, + }, + { + Key: promptKey, + Description: "toggle interactive prompting in the terminal", + DefaultValue: "enabled", + AllowedValues: []string{"enabled", "disabled"}, + CurrentValue: func(c gh.Config, hostname string) string { + return c.Prompt(hostname) }, - { - Key: pagerKey, - Description: "the terminal pager program to send standard output to", - DefaultValue: "", - CurrentValue: func(c gh.Config, hostname string) string { - return c.Pager(hostname) - }, + }, + { + Key: pagerKey, + Description: "the terminal pager program to send standard output to", + DefaultValue: "", + CurrentValue: func(c gh.Config, hostname string) string { + return c.Pager(hostname) }, - { - Key: httpUnixSocketKey, - Description: "the path to a Unix socket through which to make an HTTP connection", - DefaultValue: "", - CurrentValue: func(c gh.Config, hostname string) string { - return c.HTTPUnixSocket(hostname) - }, + }, + { + Key: httpUnixSocketKey, + Description: "the path to a Unix socket through which to make an HTTP connection", + DefaultValue: "", + CurrentValue: func(c gh.Config, hostname string) string { + return c.HTTPUnixSocket(hostname) }, - { - Key: browserKey, - Description: "the web browser to use for opening URLs", - DefaultValue: "", - CurrentValue: func(c gh.Config, hostname string) string { - return c.Browser(hostname) - }, + }, + { + Key: browserKey, + Description: "the web browser to use for opening URLs", + DefaultValue: "", + CurrentValue: func(c gh.Config, hostname string) string { + return c.Browser(hostname) }, - } + }, } func HomeDirPath(subdir string) (string, error) { diff --git a/pkg/cmd/config/config.go b/pkg/cmd/config/config.go index 20a660279..2661c3369 100644 --- a/pkg/cmd/config/config.go +++ b/pkg/cmd/config/config.go @@ -17,7 +17,7 @@ func NewCmdConfig(f *cmdutil.Factory) *cobra.Command { longDoc := strings.Builder{} longDoc.WriteString("Display or change configuration settings for gh.\n\n") longDoc.WriteString("Current respected settings:\n") - for _, co := range config.ConfigOptions() { + for _, co := range config.Options { longDoc.WriteString(fmt.Sprintf("- `%s`: %s", co.Key, co.Description)) if len(co.AllowedValues) > 0 { longDoc.WriteString(fmt.Sprintf(" {%s}", strings.Join(co.AllowedValues, "|"))) diff --git a/pkg/cmd/config/list/list.go b/pkg/cmd/config/list/list.go index d7e9751e0..6cac775fa 100644 --- a/pkg/cmd/config/list/list.go +++ b/pkg/cmd/config/list/list.go @@ -55,7 +55,7 @@ func listRun(opts *ListOptions) error { host, _ = cfg.Authentication().DefaultHost() } - configOptions := config.ConfigOptions() + configOptions := config.Options for _, option := range configOptions { fmt.Fprintf(opts.IO.Out, "%s=%s\n", option.Key, option.CurrentValue(cfg, host)) diff --git a/pkg/cmd/config/set/set.go b/pkg/cmd/config/set/set.go index dedbd0044..a1fb2bbe9 100644 --- a/pkg/cmd/config/set/set.go +++ b/pkg/cmd/config/set/set.go @@ -88,7 +88,7 @@ func setRun(opts *SetOptions) error { } func ValidateKey(key string) error { - for _, configKey := range config.ConfigOptions() { + for _, configKey := range config.Options { if key == configKey.Key { return nil } @@ -108,7 +108,7 @@ func (e InvalidValueError) Error() string { func ValidateValue(key, value string) error { var validValues []string - for _, v := range config.ConfigOptions() { + for _, v := range config.Options { if v.Key == key { validValues = v.AllowedValues break