-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
84 lines (71 loc) · 2.35 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
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"log"
"os"
"time"
"github.com/anna-ssg/anna/v3/cmd/anna"
"github.com/spf13/cobra"
)
func main() {
var addr string
var prof bool
var renderDrafts bool
var serve string
var webconsole bool
var version bool
var validateHTMLLayouts bool
var renderSpecificSite string
Version := "v3.0.0" // to be set at build time $(git describe --tags)
rootCmd := &cobra.Command{
Use: "anna",
Short: "Static Site Generator",
Run: func(cmd *cobra.Command, args []string) {
annaCmd := anna.Cmd{
RenderDrafts: renderDrafts,
Addr: addr,
RenderSpecificSite: renderSpecificSite,
ServeSpecificSite: serve,
ErrorLogger: log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile),
InfoLogger: log.New(os.Stderr, "LOG\t", log.Ldate|log.Ltime),
}
if serve != "" {
annaCmd.LiveReload = true
annaCmd.LiveReloadManager()
}
if prof {
startTime := time.Now()
annaCmd.VanillaRenderManager()
elapsedTime := time.Since(startTime)
annaCmd.PrintStats(elapsedTime)
}
if version {
annaCmd.InfoLogger.Println("Current version:", Version)
}
if validateHTMLLayouts {
annaCmd.ValidateHTMLManager()
}
if webconsole {
server := anna.NewWizardServer(":8080")
go server.Start()
<-anna.FormSubmittedCh // wait for response
if err := server.Stop(); err != nil {
annaCmd.InfoLogger.Println(err)
}
annaCmd.LiveReloadManager()
}
annaCmd.VanillaRenderManager()
},
}
rootCmd.Flags().StringVarP(&addr, "addr", "a", "8000", "specify port to serve rendered content to")
rootCmd.Flags().BoolVarP(&renderDrafts, "draft", "d", false, "renders draft posts")
rootCmd.Flags().BoolVarP(&validateHTMLLayouts, "layout", "l", false, "validates html layouts")
// Do not set default values for string flags
rootCmd.Flags().StringVarP(&renderSpecificSite, "render-site", "r", "", "specify the specific site directory to render")
rootCmd.Flags().BoolVarP(&prof, "prof", "p", false, "enable profiling")
rootCmd.Flags().StringVarP(&serve, "serve", "s", "", "specify the specific site directory to serve")
rootCmd.Flags().BoolVarP(&version, "version", "v", false, "prints current version number")
rootCmd.Flags().BoolVarP(&webconsole, "webconsole", "w", false, "wizard to setup anna")
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}