@@ -10,6 +10,7 @@ import (
10
10
"regexp"
11
11
"sort"
12
12
"strings"
13
+ "time"
13
14
"unicode"
14
15
15
16
"github.com/BurntSushi/toml"
@@ -330,15 +331,25 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, opts ...UpdateCfgOpt) ([]byte, err
330
331
// create a map of default lines, so we can comment those out later
331
332
defLines := strings .Split (defStr , "\n " )
332
333
defaults := map [string ]struct {}{}
334
+ currentSection := ""
335
+
336
+ defSectionRx := regexp .MustCompile (`\[(.+)]` )
337
+
333
338
for i := range defLines {
334
339
l := strings .TrimSpace (defLines [i ])
335
- if len (l ) == 0 {
340
+ if len (l ) == 0 || l [ 0 ] == '#' {
336
341
continue
337
342
}
338
- if l [0 ] == '#' || l [0 ] == '[' {
343
+ if l [0 ] == '[' {
344
+ m := defSectionRx .FindStringSubmatch (l )
345
+ if len (m ) == 2 {
346
+ currentSection = m [1 ]
347
+ }
339
348
continue
340
349
}
341
- defaults [l ] = struct {}{}
350
+
351
+ qualifiedKey := currentSection + "." + l
352
+ defaults [qualifiedKey ] = struct {}{}
342
353
}
343
354
344
355
nodeLines := strings .Split (nodeStr , "\n " )
@@ -409,7 +420,8 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, opts ...UpdateCfgOpt) ([]byte, err
409
420
// filter lines from options
410
421
optsFilter := updateOpts .keepUncommented != nil && updateOpts .keepUncommented (line )
411
422
// if there is the same line in the default config, comment it out in output
412
- if _ , found := defaults [strings .TrimSpace (nodeLines [i ])]; (cfgDef == nil || found ) && len (line ) > 0 && ! optsFilter {
423
+ qualifiedKey := section + "." + strings .TrimSpace (line )
424
+ if _ , found := defaults [qualifiedKey ]; (cfgDef == nil || found ) && len (line ) > 0 && ! optsFilter {
413
425
line = pad + "#" + line [len (pad ):]
414
426
}
415
427
outLines = append (outLines , line )
@@ -441,6 +453,10 @@ func ConfigUpdate(cfgCur, cfgDef interface{}, opts ...UpdateCfgOpt) ([]byte, err
441
453
}
442
454
return false
443
455
}),
456
+ cmp .Comparer (func (x , y time.Duration ) bool {
457
+ tx , ty := reflect .TypeOf (x ), reflect .TypeOf (y )
458
+ return tx .Kind () == ty .Kind ()
459
+ }),
444
460
}
445
461
446
462
if ! cmp .Equal (cfgUpdated , cfgCur , opts ... ) {
0 commit comments