Skip to content

Commit 415a79c

Browse files
committed
Merge pull request #68 from vcaputo/unit_serialize_consolidate_disjointed_sections
unit: Consolidate disjointed unitOption sections in unit.Serialize
2 parents e3e4f60 + 6654289 commit 415a79c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

unit/serialize.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@ func Serialize(opts []*UnitOption) io.Reader {
1313
return &buf
1414
}
1515

16-
curSection := opts[0].Section
17-
18-
writeSectionHeader(&buf, curSection)
19-
writeNewline(&buf)
20-
16+
idx := map[string][]*UnitOption{}
2117
for _, opt := range opts {
22-
if opt.Section != curSection {
23-
curSection = opt.Section
18+
idx[opt.Section] = append(idx[opt.Section], opt)
19+
}
2420

25-
writeNewline(&buf)
26-
writeSectionHeader(&buf, curSection)
21+
for curSection, curOpts := range idx {
22+
writeSectionHeader(&buf, curSection)
23+
writeNewline(&buf)
24+
25+
for _, opt := range curOpts {
26+
writeOption(&buf, opt)
2727
writeNewline(&buf)
2828
}
29-
30-
writeOption(&buf, opt)
3129
writeNewline(&buf)
3230
}
3331

0 commit comments

Comments
 (0)