-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (42 loc) · 964 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"fmt"
"os"
"github.com/515hikaru/hutago/action"
"github.com/515hikaru/hutago/loader"
"github.com/515hikaru/hutago/parser"
)
const (
varsion = "v0.1.0"
failCode = 1
successCode = 0
)
func run() {
recursive := flag.Bool("r", false, "search directories and their contents recursively")
flag.Parse()
targetDirectory := flag.Arg(0)
if targetDirectory == "" {
targetDirectory = "content"
*recursive = true
}
fileNames, err := loader.ListDirectoryContents(targetDirectory, *recursive)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(failCode)
}
if len(fileNames) == 0 {
fmt.Fprintf(os.Stderr, "%s has no markdown files.\n", targetDirectory)
os.Exit(failCode)
}
mmap, err := parser.CreateHeaders(fileNames, targetDirectory)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(failCode)
}
action.PrintTags(mmap)
}
func main() {
run()
os.Exit(successCode)
}