Skip to content

Commit

Permalink
lxddoc: Within a config group, alphabetically sort the config options
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Aug 3, 2023
1 parent dbd1fdd commit ae1ac4c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lxd/config/generate/lxddoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -191,7 +192,38 @@ func parse(path string, outputYAMLPath string, excludedPaths []string) (*doc, er
return nil, err
}

yamlDoc.Configs = projectEntries
// Within each group, alphabetically sort the entries by key (config option key)
orderedProjectEntries := make(map[string][]any, len(projectEntries))
for groupKey, entries := range projectEntries {
var sortedConfigOptionKeysPerGroup []string
for _, configEntry := range entries {
c := configEntry.(map[string]any)
for k := range c {
sortedConfigOptionKeysPerGroup = append(sortedConfigOptionKeysPerGroup, k)
}
}

sort.Strings(sortedConfigOptionKeysPerGroup)
for _, configOptionKey := range sortedConfigOptionKeysPerGroup {
for _, configEntry := range entries {
c := configEntry.(map[string]any)
for k := range c {
if k == configOptionKey {
_, ok := orderedProjectEntries[groupKey]
if !ok {
orderedProjectEntries[groupKey] = []any{c}
} else {
orderedProjectEntries[groupKey] = append(orderedProjectEntries[groupKey], c)
}

break
}
}
}
}
}

yamlDoc.Configs = orderedProjectEntries
data, err := yaml.Marshal(yamlDoc)
if err != nil {
return nil, fmt.Errorf("Error while marshaling project documentation: %v", err)
Expand Down

0 comments on commit ae1ac4c

Please sign in to comment.