Export type ConfigOption and group InvalidValueError code

This commit is contained in:
Sam Coe 2020-10-29 22:06:06 +03:00
parent 5c5f52c4c4
commit ce18b943b8
No known key found for this signature in database
GPG key ID: 8E322C20F811D086

View file

@ -10,14 +10,14 @@ import (
"gopkg.in/yaml.v3"
)
type configOption struct {
type ConfigOption struct {
Key string
Description string
DefaultValue string
AllowedValues []string
}
var configOptions = []configOption{
var configOptions = []ConfigOption{
{
Key: "git_protocol",
Description: "the protocol to use for git clone and push operations",
@ -42,7 +42,7 @@ var configOptions = []configOption{
},
}
func ConfigOptions() []configOption {
func ConfigOptions() []ConfigOption {
return configOptions
}
@ -56,6 +56,14 @@ func ValidateKey(key string) error {
return fmt.Errorf("invalid key")
}
type InvalidValueError struct {
ValidValues []string
}
func (e InvalidValueError) Error() string {
return "invalid value"
}
func ValidateValue(key, value string) error {
var validValues []string
@ -79,10 +87,6 @@ func ValidateValue(key, value string) error {
return &InvalidValueError{ValidValues: validValues}
}
func (e InvalidValueError) Error() string {
return "invalid value"
}
// This interface describes interacting with some persistent configuration for gh.
type Config interface {
Get(string, string) (string, error)
@ -338,10 +342,6 @@ func (c *fileConfig) GetWithSource(hostname, key string) (string, string, error)
return value, defaultSource, nil
}
type InvalidValueError struct {
ValidValues []string
}
func (c *fileConfig) Set(hostname, key, value string) error {
if hostname == "" {
return c.SetStringValue(key, value)