-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
67 lines (62 loc) · 1.31 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
package main
import (
"context"
"log/slog"
"os"
"runtime/debug"
"time"
"github.com/urfave/cli/v3"
)
func main() {
rev, t := getBuildInfo()
version := rev + " (" + t.String() + ")"
cli := &cli.Command{
Name: "bf",
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Aliases: []string{"l"},
Sources: cli.EnvVars("LOG_LEVEL"),
Value: slog.LevelInfo.String(),
Action: func(_ context.Context, _ *cli.Command, l string) error {
logLevel := new(slog.LevelVar)
if err := logLevel.UnmarshalText([]byte(l)); err != nil {
return err
}
hdlr := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel})
slog.SetDefault(slog.New(hdlr))
return nil
},
},
},
Commands: []*cli.Command{
caServeCmd,
caIssueCmd,
idCmd,
proxyCmd,
newCmd,
},
DefaultCommand: "serve",
}
if err := cli.Run(context.Background(), os.Args); err != nil {
panic(err)
}
}
func getBuildInfo() (rev string, t time.Time) {
if bi, ok := debug.ReadBuildInfo(); ok {
for _, s := range bi.Settings {
if s.Key == "vcs.revision" {
rev = s.Value
} else if s.Key == "vcs.time" {
if t2, err := time.Parse(time.RFC3339, s.Value); err == nil {
t = t2
}
}
if rev != "" && !t.IsZero() {
break
}
}
}
return
}