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
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.annabunches.net/annabunches/joyful/internal/configparser"
|
||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||
|
@ -33,24 +32,25 @@ func NewRule(config configparser.RuleConfig, pDevs map[string]Device, vDevs map[
|
|||
|
||||
base := NewMappingRuleBase(config.Name, config.Modes)
|
||||
|
||||
switch strings.ToLower(config.Type) {
|
||||
case RuleTypeButton:
|
||||
switch config.Type {
|
||||
case configparser.RuleTypeButton:
|
||||
newRule, err = NewMappingRuleButton(config.Config.(configparser.RuleConfigButton), pDevs, vDevs, base)
|
||||
case RuleTypeButtonCombo:
|
||||
case configparser.RuleTypeButtonCombo:
|
||||
newRule, err = NewMappingRuleButtonCombo(config.Config.(configparser.RuleConfigButtonCombo), pDevs, vDevs, base)
|
||||
case RuleTypeButtonLatched:
|
||||
case configparser.RuleTypeButtonLatched:
|
||||
newRule, err = NewMappingRuleButtonLatched(config.Config.(configparser.RuleConfigButtonLatched), pDevs, vDevs, base)
|
||||
case RuleTypeAxis:
|
||||
case configparser.RuleTypeAxis:
|
||||
newRule, err = NewMappingRuleAxis(config.Config.(configparser.RuleConfigAxis), pDevs, vDevs, base)
|
||||
case RuleTypeAxisCombined:
|
||||
case configparser.RuleTypeAxisCombined:
|
||||
newRule, err = NewMappingRuleAxisCombined(config.Config.(configparser.RuleConfigAxisCombined), pDevs, vDevs, base)
|
||||
case RuleTypeAxisToButton:
|
||||
case configparser.RuleTypeAxisToButton:
|
||||
newRule, err = NewMappingRuleAxisToButton(config.Config.(configparser.RuleConfigAxisToButton), pDevs, vDevs, base)
|
||||
case RuleTypeAxisToRelaxis:
|
||||
case configparser.RuleTypeAxisToRelaxis:
|
||||
newRule, err = NewMappingRuleAxisToRelaxis(config.Config.(configparser.RuleConfigAxisToRelaxis), pDevs, vDevs, base)
|
||||
case RuleTypeModeSelect:
|
||||
case configparser.RuleTypeModeSelect:
|
||||
newRule, err = NewMappingRuleModeSelect(config.Config.(configparser.RuleConfigModeSelect), pDevs, modes, base)
|
||||
default:
|
||||
// Shouldn't actually be possible to get here...
|
||||
err = fmt.Errorf("bad rule type '%s' for rule '%s'", config.Type, config.Name)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package mappingrules
|
||||
|
||||
const (
|
||||
RuleTypeButton = "button"
|
||||
RuleTypeButtonCombo = "button-combo"
|
||||
RuleTypeButtonLatched = "button-latched"
|
||||
RuleTypeAxis = "axis"
|
||||
RuleTypeAxisCombined = "axis-combined"
|
||||
RuleTypeAxisToButton = "axis-to-button"
|
||||
RuleTypeAxisToRelaxis = "axis-to-relaxis"
|
||||
RuleTypeModeSelect = "mode-select"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue