forked from zupzup/blog-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (45 loc) · 1.22 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
package main
import (
"flag"
"log"
"net/http"
"strconv"
"github.com/RomanosTrechlis/blog-generator/cli"
)
var (
generate bool
server bool
download bool
upload bool
port int
configFile string
)
func init() {
flag.StringVar(&configFile, "configfile", "config.json", "is the file containing site's information")
flag.BoolVar(&server, "run", false, "runs a simple server")
flag.IntVar(&port, "port", 3000, "port of server")
flag.BoolVar(&generate, "generate", false, "generates site content")
flag.BoolVar(&download, "fetch", false, "fetches site content")
flag.BoolVar(&upload, "upload", false, "uploads site content")
}
func main() {
flag.Parse()
siteInfo := cli.ReadConfig(configFile)
if download {
cli.Download(siteInfo.DataSource.Type, siteInfo.DataSource.Repository, siteInfo.TempFolder)
cli.Download(siteInfo.Theme.Type, siteInfo.Theme.Repository, siteInfo.ThemeFolder)
}
if generate {
cli.Generate(&siteInfo)
}
if upload {
cli.Upload(&siteInfo)
}
if server {
fs := http.FileServer(http.Dir(siteInfo.DestFolder))
http.Handle("/", fs)
serverPort := strconv.Itoa(port)
log.Println("Listening @ localhost:" + serverPort + "/")
http.ListenAndServe(":"+serverPort, nil)
}
}