-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (36 loc) · 1018 Bytes
/
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
package cli
import (
"github.com/alecthomas/kingpin"
"github.com/debabky/pem-inclusion-prover-svc/internal/config"
"github.com/debabky/pem-inclusion-prover-svc/internal/service"
"gitlab.com/distributed_lab/kit/kv"
"gitlab.com/distributed_lab/logan/v3"
)
func Run(args []string) bool {
log := logan.New()
defer func() {
if rvr := recover(); rvr != nil {
log.WithRecover(rvr).Error("app panicked")
}
}()
cfg := config.New(kv.MustFromEnv())
log = cfg.Log()
app := kingpin.New("pem-inclusion-prover-svc", "")
runCmd := app.Command("run", "run command")
serviceCmd := runCmd.Command("service", "run service") // you can insert custom help
// custom commands go here...
cmd, err := app.Parse(args[1:])
if err != nil {
log.WithError(err).Error("failed to parse arguments")
return false
}
switch cmd {
case serviceCmd.FullCommand():
service.Run(cfg)
// handle any custom commands here in the same way
default:
log.Errorf("unknown command %s", cmd)
return false
}
return true
}