-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
71 lines (61 loc) · 1.43 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
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"fmt"
"github.com/schollz/progressbar/v3"
"os"
)
var Version string
func main() {
SrcPath = flag.String("s", "","Specify the directory where Joplin exported the RAW data" )
DestPath = flag.String("d", "", "The directory of Obsidian vault")
flag.Parse()
fmt.Printf("joplin2obsidian %s\n\n", Version)
if len(*SrcPath)==0 || len(*DestPath)==0 {
_, err := fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
CheckError(err)
flag.PrintDefaults()
os.Exit(-1)
}
chkPath := func(p string) {
if fi, err := os.Stat(p);os.IsNotExist(err) {
println(fmt.Sprintf("%s isn't exist", p))
os.Exit(-1)
} else {
if !fi.Mode().IsDir() {
println(fmt.Sprintf("%s isn't a directory", p))
os.Exit(-1)
}
}
}
chkPath(*SrcPath)
chkPath(*DestPath)
progress := make(chan int,1)
done := make(chan bool, 1)
go HandlingCoreBusiness(progress, done)
go func() {
var bar *progressbar.ProgressBar
step := 0
for newStep := range progress {
if newStep != step {
if bar != nil {
bar.Finish()
}
step = newStep
bar = progressbar.Default(-1, StepDesc[newStep])
err := bar.Set(0)
CheckError(err)
}
if bar!=nil {
err := bar.Add(1)
CheckError(err)
}
}
if bar!=nil {
bar.Finish()
}
}()
<-done
fmt.Printf("\n\nDone!\n\n")
fmt.Println(fmt.Sprintf("The next step is to open %s as vault in Obsidian, Then you will see what you want to see.", *DestPath))
}