5
5
"fmt"
6
6
"os"
7
7
"path"
8
+ "path/filepath"
8
9
"strings"
9
10
10
11
"github.com/AlecAivazis/survey/v2"
@@ -21,7 +22,7 @@ func NewRootCommand() (cmd *cobra.Command) {
21
22
cmd = & cobra.Command {
22
23
Use : "mde" ,
23
24
Example : "mde README.md" ,
24
- Args : cobra .ExactArgs (1 ),
25
+ Args : cobra .MinimumNArgs (1 ),
25
26
RunE : opt .runE ,
26
27
}
27
28
cmd .Version = version
@@ -33,10 +34,26 @@ func NewRootCommand() (cmd *cobra.Command) {
33
34
}
34
35
35
36
func (o * option ) runE (cmd * cobra.Command , args []string ) (err error ) {
36
- mdFilePath := args [0 ]
37
+ scriptRunners := NewScriptRunners ()
38
+
39
+ for _ , mdFilePath := range args {
40
+ var files []string
41
+ if files , err = filepath .Glob (mdFilePath ); err != nil {
42
+ return
43
+ }
44
+
45
+ for _ , file := range files {
46
+ var runners ScriptRunners
47
+ if runners , err = o .parseMarkdownRunner (file ); err != nil {
48
+ break
49
+ }
50
+
51
+ scriptRunners = append (scriptRunners , runners ... )
52
+ }
53
+ }
37
54
38
55
for {
39
- err = o .runMarkdown ( mdFilePath )
56
+ err = o .executeScripts ( scriptRunners )
40
57
41
58
if ! o .loop {
42
59
break
@@ -45,20 +62,18 @@ func (o *option) runE(cmd *cobra.Command, args []string) (err error) {
45
62
return
46
63
}
47
64
48
- func (o * option ) runMarkdown (mdFilePath string ) (err error ) {
65
+ func (o * option ) parseMarkdownRunner (mdFilePath string ) (scriptList ScriptRunners , err error ) {
49
66
var mdFile []byte
50
67
mdFile , err = os .ReadFile (mdFilePath )
51
68
if err != nil {
52
69
return
53
70
}
54
71
55
- //Parse the markdown
72
+ // Parse the markdown
73
+ scriptList = ScriptRunners {}
56
74
md := markdown .New (markdown .XHTMLOutput (true ), markdown .Nofollow (true ))
57
75
tokens := md .Parse (mdFile )
58
76
59
- // cmdMap := map[string][]string{}
60
- scriptList := NewScriptRunners ()
61
-
62
77
// Print the result
63
78
var title string
64
79
for _ , t := range tokens {
@@ -111,7 +126,6 @@ func (o *option) runMarkdown(mdFilePath string) (err error) {
111
126
})
112
127
}
113
128
}
114
- err = o .executeScripts (scriptList )
115
129
return
116
130
}
117
131
0 commit comments