Make enum values typed strings (#18)
This also moves validation into the parsing process and refactors a bunch of code related to the config. Reviewed-on: #18 Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
8d2b15a7c8
commit
8a903e0703
10 changed files with 232 additions and 173 deletions
60
internal/configparser/ruleconfig.go
Normal file
60
internal/configparser/ruleconfig.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package configparser
|
||||
|
||||
type RuleConfig struct {
|
||||
Type RuleType
|
||||
Name string
|
||||
Modes []string
|
||||
Config interface{}
|
||||
}
|
||||
|
||||
func (dc *RuleConfig) UnmarshalYAML(unmarshal func(data interface{}) error) error {
|
||||
metaConfig := &struct {
|
||||
Type RuleType
|
||||
Name string
|
||||
Modes []string
|
||||
}{}
|
||||
err := unmarshal(metaConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dc.Type = metaConfig.Type
|
||||
dc.Name = metaConfig.Name
|
||||
dc.Modes = metaConfig.Modes
|
||||
|
||||
switch dc.Type {
|
||||
case RuleTypeButton:
|
||||
config := RuleConfigButton{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeButtonCombo:
|
||||
config := RuleConfigButtonCombo{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeButtonLatched:
|
||||
config := RuleConfigButtonLatched{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeAxis:
|
||||
config := RuleConfigAxis{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeAxisCombined:
|
||||
config := RuleConfigAxisCombined{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeAxisToButton:
|
||||
config := RuleConfigAxisToButton{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeAxisToRelaxis:
|
||||
config := RuleConfigAxisToRelaxis{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
case RuleTypeModeSelect:
|
||||
config := RuleConfigModeSelect{}
|
||||
err = unmarshal(&config)
|
||||
dc.Config = config
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue