mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Allow append mode when config cannot be loaded
This commit is contained in:
+4
-1
@@ -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++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user