Skip to content

Commit 58fed2e

Browse files
committed
respect target directory order
1 parent 4cd8db8 commit 58fed2e

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

main.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,26 @@ var (
5353
title string
5454
outputPath string
5555

56-
targetDirectories = newMapString()
56+
targetDirectories = newDirectoryOptions()
5757
messageOnlyFromThisFile string
5858
)
5959

60-
type mapString map[string][]parse.ParseOption
60+
type directoryOption struct {
61+
directory string
62+
options []parse.ParseOption
63+
}
64+
65+
type directoryOptions []directoryOption
6166

62-
func newMapString() mapString {
63-
return mapString(make(map[string][]parse.ParseOption))
67+
func newDirectoryOptions() directoryOptions {
68+
return directoryOptions(make([]directoryOption, 0))
6469
}
65-
func (m mapString) String() string {
70+
71+
func (do directoryOptions) String() string {
6672
return ""
6773
}
68-
func (m mapString) Set(s string) error {
74+
75+
func (do *directoryOptions) Set(s string) error {
6976
for _, elem := range strings.Split(s, ",") {
7077
pair := strings.Split(elem, "=")
7178
if len(pair) != 2 {
@@ -80,12 +87,13 @@ func (m mapString) Set(s string) error {
8087
opts = append(opts, parse.ParseService)
8188
}
8289
}
83-
m[pair[0]] = opts
90+
*do = append(*do, directoryOption{directory: pair[0], options: opts})
8491
}
8592
return nil
8693
}
87-
func (m mapString) Type() string {
88-
return "map[string][]parse.ParseOption"
94+
95+
func (do directoryOptions) Type() string {
96+
return "[]directoryOption"
8997
}
9098

9199
func init() {
@@ -126,20 +134,20 @@ func CommandFunc(cmd *cobra.Command, args []string) error {
126134
return err
127135
}
128136
} else {
129-
for k, opts := range targetDirectories {
130-
log.Println("opening", k)
137+
for _, elem := range targetDirectories {
138+
log.Println("opening", elem.directory)
131139
c1 := filepath.Base(filepath.Dir(messageOnlyFromThisFile))
132-
c2 := filepath.Base(k)
140+
c2 := filepath.Base(elem.directory)
133141
bs := ""
134142
if c1 == c2 {
135143
bs = messageOnlyFromThisFile
136144
log.Println("message only from this file:", messageOnlyFromThisFile)
137145
}
138-
proto, err := parse.ReadDir(k, bs)
146+
proto, err := parse.ReadDir(elem.directory, bs)
139147
if err != nil {
140148
return err
141149
}
142-
ms, err := proto.Markdown("", opts, languageOptions...)
150+
ms, err := proto.Markdown("", elem.options, languageOptions...)
143151
if err != nil {
144152
return err
145153
}

0 commit comments

Comments
 (0)