-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (49 loc) · 917 Bytes
/
main.go
File metadata and controls
62 lines (49 loc) · 917 Bytes
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"log"
"os"
)
func main() {
cwd := flag.String("d", "cwd", "the directory of files to parse")
flag.Parse()
var dir string
if *cwd == "cwd" || *cwd == "." {
dir = getCwd()
} else {
dir = *cwd
}
err := preFlightChecks(dir)
if err != nil {
log.Panic(fmt.Sprint("pre-flight checks error:", err))
}
files, err := getFileList(dir)
if err != nil {
log.Panic(err)
}
if err := addFrontMatter(files); err != nil {
log.Panic(err)
}
}
func addFrontMatter(files []string) error {
for _, file := range files {
info, err := os.Stat(file)
if err != nil {
return err
}
log.Println("working on", info.Name())
title, i, err := getTitle(file)
if err != nil {
return err
}
log.Println("title: ", title)
f := frontMatter{Title: title}
err = f.addToFile(file, i)
if err != nil {
return err
}
log.Println("done")
}
return nil
}