-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (44 loc) · 1.03 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"log"
"os"
)
var (
flagIn *string
flagOut *string
)
func init() {
}
func main() {
flagIn = flag.String("in", "", "JSON input file")
flagOut = flag.String("out", "", "Markdown output file")
flag.Parse()
if flagIn == nil || *flagIn == "" {
log.Fatalln("No -in flag passed.")
}
if flagOut == nil || *flagOut == "" {
log.Fatalln("No -out flag passed.")
}
fmt.Println("TiddlyWiki 5 JSON to Markdown Converter")
fmt.Println("---------------------------------------")
fmt.Printf("In: %s\n", *flagIn)
fmt.Printf("Out: %s\n", *flagOut)
if err := os.Mkdir(*flagOut, 0755); os.IsExist(err) {
fmt.Println("Output folder exists.")
} else if err != nil {
fmt.Printf("Error creating output folder: %v.\n", err)
} else {
fmt.Println("Output folder created.")
}
json, err := os.ReadFile(*flagIn)
if err != nil {
log.Fatalf("Error reading JSON: %v", err)
}
err = ProcessJson(string(json), *flagOut)
if err != nil {
log.Fatalf("Conversion error: %v\n", err)
}
fmt.Println("Done.")
}