Skip to content

Commit 7bc6bb5

Browse files
committed
fix ordering issue
1 parent e536d35 commit 7bc6bb5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/docgen/lister.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
"io/ioutil"
1919
"path/filepath"
2020
"regexp"
21+
"sort"
2122
"strings"
2223

2324
"emperror.dev/errors"
2425
"github.com/go-logr/logr"
26+
"github.com/iancoleman/orderedmap"
2527
)
2628

2729
type SourceLister struct {
@@ -53,7 +55,9 @@ func NewSourceLister(sources map[string]SourceDir, logger logr.Logger) *SourceLi
5355

5456
func (sl *SourceLister) ListSources() ([]DocItem, error) {
5557
sourceList := []DocItem{}
56-
for category, p := range sl.Sources {
58+
59+
for _, key := range orderedMap(sl.Sources).Keys() {
60+
p := sl.Sources[key]
5761
files, err := ioutil.ReadDir(p.Path)
5862
if err != nil {
5963
return nil, errors.WrapIff(err, "failed to read files from %s", p.Path)
@@ -67,7 +71,7 @@ func (sl *SourceLister) ListSources() ([]DocItem, error) {
6771
SourcePath: fullPath,
6872
DestPath: p.DestPath,
6973
DefaultValueFromTagExtractor: sl.DefaultValueFromTagExtractor,
70-
Category: category,
74+
Category: key,
7175
},
7276
)
7377
}
@@ -118,3 +122,12 @@ func (lister *SourceLister) Generate() error {
118122

119123
return nil
120124
}
125+
126+
func orderedMap(original map[string]SourceDir) *orderedmap.OrderedMap {
127+
o := orderedmap.New()
128+
for k, v := range original {
129+
o.Set(k, v)
130+
}
131+
o.SortKeys(sort.Strings)
132+
return o
133+
}

0 commit comments

Comments
 (0)