-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
64 lines (56 loc) · 1.59 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
package main
import (
"fmt"
"os"
"github.com/chiepomme/chienote/convert"
"github.com/chiepomme/chienote/sync"
"github.com/spf13/cobra"
)
var cfg *config
func main() {
var cmdInit = &cobra.Command{
Use: "init",
Short: "Initialize your configuration file",
Run: func(cmd *cobra.Command, args []string) {
if err := initialize(); err != nil {
fmt.Printf("%+v\n", err)
os.Exit(-1)
}
},
}
var cmdSync = &cobra.Command{
Use: "sync",
Short: "Sync local cache and evernote notes",
Run: func(cmd *cobra.Command, args []string) {
cfg := loadConfig()
if err := sync.Sync(cacheRoot, noteCacheDirName, resourceCacheDirName, cfg.ClientKey, cfg.ClientSecret, cfg.DeveloperToken, cfg.Sandbox, cfg.NotebookName); err != nil {
fmt.Printf("%+v\n", err)
os.Exit(-1)
}
},
}
var cmdConvert = &cobra.Command{
Use: "convert",
Short: "Convert local cache to post files",
Run: func(cmd *cobra.Command, args []string) {
loadConfig()
if err := convert.Convert(cacheRoot, noteCacheDirName, resourceCacheDirName, ".", postDirName, resourceDirName, true); err != nil {
fmt.Printf("%+v\n", err)
os.Exit(-1)
}
},
}
var rootCmd = &cobra.Command{Use: "chienote", Long: "Sync your evernote notebook to your jekyll directory. Execute chienote at your jekyll root."}
rootCmd.AddCommand(cmdInit, cmdSync, cmdConvert)
rootCmd.Execute()
}
func loadConfig() *config {
cfg, err := getConfig()
if err != nil {
fmt.Println("configuration file load error")
fmt.Println("it is recommended to execute init command")
fmt.Printf("%+v", err)
os.Exit(-1)
}
return cfg
}