Allow append mode when config cannot be loaded

This commit is contained in:
2025-12-27 02:09:00 -05:00
parent b707d67113
commit 422ca0295a
+4 -1
View File
@@ -42,6 +42,7 @@ func LoadConfig() (*ConfigT, error) {
// If used in append mode, any nil values in the // If used in append mode, any nil values in the
// input cfg will be substituted with the existing values. // input cfg will be substituted with the existing values.
func WriteConfig(cfg *ConfigT, appendMode bool) error { func WriteConfig(cfg *ConfigT, appendMode bool) error {
start:
if appendMode { if appendMode {
// check if any fields are nil // check if any fields are nil
var hasNilFields bool var hasNilFields bool
@@ -58,7 +59,9 @@ func WriteConfig(cfg *ConfigT, appendMode bool) error {
if hasNilFields { if hasNilFields {
oldCfg, err := LoadConfig() oldCfg, err := LoadConfig()
if err != nil { if err != nil {
return err // failed to load config, leave append mode
appendMode = false
goto start
} }
oldValue := reflect.ValueOf(&oldCfg.Libmutton).Elem() oldValue := reflect.ValueOf(&oldCfg.Libmutton).Elem()
for i := 0; i < cfgValue.NumField(); i++ { for i := 0; i < cfgValue.NumField(); i++ {