This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
95 lines (74 loc) · 2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2016 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
// 基于 Git 的博客系统。
package main
import (
"encoding/json"
"flag"
"fmt"
"runtime"
"github.com/issue9/logs"
"github.com/issue9/web"
"github.com/issue9/web/encoding"
"github.com/issue9/web/encoding/html"
"github.com/caixw/gitype/app"
"github.com/caixw/gitype/path"
"github.com/caixw/gitype/vars"
)
const usage = `%s 是一个基于 Git 的博客系统。
源代码以 MIT 开源许可发布于:%s
常见用法:
%s -preview -appdir="./"
%s -appdir="./"
参数:
`
func main() {
help := flag.Bool("h", false, "显示当前信息")
version := flag.Bool("v", false, "显示程序的版本信息")
preview := flag.Bool("preview", false, "是否启用预览模式")
appdir := flag.String("appdir", "./", "指定运行的工作目录")
init := flag.String("init", "", "初始化一个工作目录")
flag.Usage = func() {
fmt.Printf(usage, vars.Name, vars.URL, vars.Name, vars.Name)
flag.PrintDefaults()
}
flag.Parse()
switch {
case *help:
flag.Usage()
return
case *version:
printVersion()
return
case len(*init) > 0:
if err := app.Init(path.New(*init)); err != nil {
panic(err)
}
fmt.Printf("操作成功,你现在可以在 %s 中修改具体的参数配置!\n", *init)
return
}
path := path.New(*appdir)
if *preview {
fmt.Println("预览模式,监视以下数据文件:", path.DataDir)
}
if err := web.Init(path.ConfDir); err != nil {
panic(err)
}
htmlMgr := html.New(nil)
if err := encoding.AddMarshal("text/html", htmlMgr.Marshal); err != nil {
panic(err)
}
// webhook 用到此编码
if err := encoding.AddMarshal("application/json", json.Marshal); err != nil {
panic(err)
}
logs.Critical(app.Run(path, htmlMgr, *preview))
logs.Flush()
}
func printVersion() {
fmt.Println(vars.Name, vars.Version(), "build with", runtime.Version())
if len(vars.CommitHash()) > 0 {
fmt.Println("Git commit hash:", vars.CommitHash())
}
}