/
option.go
23 lines (20 loc) · 938 Bytes
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package config
// A OptionDefinition is something with a default value and a validator.
// Only requirement is that values are JSON structures.
type OptionDefinition struct {
Description string // Description of the config option
Default interface{} // Default value
Env string // Environment variable to attempt to load from (optional)
Parse bool // True, if string input should be parsed as JSON
Validate func(value interface{}) error
}
// RegisterOptions takes in the name of the command and an map of OptionDefinition objects
func RegisterOptions(command string, options map[string]OptionDefinition) {
if _, ok := OptionsDefinitions[command]; !ok {
OptionsDefinitions[command] = make(map[string]OptionDefinition)
}
// we could just copy 'options' but sometimes there might already be other options
for key, option := range options {
OptionsDefinitions[command][key] = option
}
}