/
cmd.go
102 lines (90 loc) · 2.17 KB
/
cmd.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
96
97
98
99
100
101
102
package command
import (
"os"
"github.com/kleister/kleister-ui/pkg/config"
"github.com/kleister/kleister-ui/pkg/version"
"github.com/urfave/cli/v2"
)
const (
defaultMetricsAddr = "0.0.0.0:8001"
defaultServerAddress = "0.0.0.0:8081"
)
// Run parses the command line arguments and executes the program.
func Run() error {
cfg := config.Load()
app := &cli.App{
Name: "kleister-ui",
Version: version.String,
Usage: "Etherpad for markdown with go",
Authors: RootAuthors(cfg),
Flags: RootFlags(cfg),
Before: RootBefore(cfg),
Commands: RootCommands(cfg),
}
cli.HelpFlag = &cli.BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "Show the help",
}
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the version",
}
return app.Run(os.Args)
}
// RootAuthors defines global authors.
func RootAuthors(_ *config.Config) []*cli.Author {
return []*cli.Author{
{
Name: "Thomas Boerger",
Email: "thomas@webhippie.de",
},
}
}
// RootFlags defines the global flags.
func RootFlags(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "config-file",
Value: "",
Usage: "Path to config file",
EnvVars: []string{"KLEISTER_UI_CONFIG_FILE"},
},
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"KLEISTER_UI_LOG_LEVEL"},
Destination: &cfg.Logs.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Value: true,
Usage: "Enable pretty logging",
EnvVars: []string{"KLEISTER_UI_LOG_PRETTY"},
Destination: &cfg.Logs.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Value: true,
Usage: "Enable colored logging",
EnvVars: []string{"KLEISTER_UI_LOG_COLOR"},
Destination: &cfg.Logs.Color,
},
}
}
// RootBefore defines global before.
func RootBefore(cfg *config.Config) cli.BeforeFunc {
return func(c *cli.Context) error {
return setup(cfg)
}
}
// RootCommands defines global commands.
func RootCommands(cfg *config.Config) []*cli.Command {
return []*cli.Command{
Gen(cfg),
Health(cfg),
Server(cfg),
}
}