-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
84 lines (76 loc) · 2.1 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 (
"github.com/Depado/smallblog/cmd"
"github.com/Depado/smallblog/router"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var rootCmd = &cobra.Command{
Use: "smallblog",
Short: "Smallblog is a simple self-hosted no-db blog",
Long: "A simple blog engine which parses markdown files with front-matter in yaml.",
}
// Serve command that will actually run the server
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start serving the blog",
Run: func(c *cobra.Command, args []string) {
r := router.New(
viper.GetString("blog.pages"),
viper.GetString("server.host"),
viper.GetInt("server.port"),
viper.GetBool("server.debug"),
viper.GetString("server.root_url"),
viper.GetBool("gitalk.enabled"),
viper.GetString("gitalk.token"),
viper.GetString("gitalk.repo"),
viper.GetString("gitalk.owner"),
viper.GetStringSlice("gitalk.admins"),
viper.GetBool("analytics.enabled"),
viper.GetString("analytics.tag"),
viper.GetBool("blog.share"),
)
if err := r.SetupRoutes(); err != nil {
logrus.WithError(err).Fatal("Unable to setup routes")
}
r.Start()
},
}
var generateCmd = &cobra.Command{
Use: "generate [output directory]",
Short: "Generate a static site",
Run: func(c *cobra.Command, args []string) {
output := "build"
if len(args) > 0 {
output = args[0]
}
if err := cmd.RunGenerate(
output,
viper.GetString("blog.pages"),
viper.GetString("blog.title"),
viper.GetString("blog.description"),
); err != nil {
logrus.WithError(err).Fatal()
}
},
}
func main() {
var err error
cobra.OnInitialize(cmd.Initialize)
if err = cmd.BindPersistentFlags(rootCmd); err != nil {
logrus.WithError(err).Fatal()
}
if err = cmd.BindServeFlags(serveCmd); err != nil {
logrus.WithError(err).Fatal()
}
// Adding commands to the root command
rootCmd.AddCommand(serveCmd, generateCmd, cmd.VersionCmd)
// Adding new command to the root command
if err = cmd.AddNewCommand(rootCmd); err != nil {
logrus.WithError(err).Fatal()
}
if err := rootCmd.Execute(); err != nil {
logrus.WithError(err).Fatal()
}
}