Export type ConfigOption and group InvalidValueError code
This commit is contained in:
parent
5c5f52c4c4
commit
ce18b943b8
1 changed files with 11 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue