-
Notifications
You must be signed in to change notification settings - Fork 1
/
go2md.go
48 lines (42 loc) · 997 Bytes
/
go2md.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
package main
import (
_ "embed"
"io"
"log/slog"
"os"
"slices"
"github.com/jylitalo/go2md/cmd"
"github.com/jylitalo/tint"
"github.com/mattn/go-isatty"
)
//go:embed version.txt
var Version string // value from version.txt file
func execute(writer io.WriteCloser) error {
return cmd.NewCommand(writer, Version).Execute()
}
func setupLogging(debug bool, color bool) {
logLevel := slog.LevelInfo
if debug {
logLevel = slog.LevelDebug
}
w := os.Stderr
log := slog.New(tint.NewHandler(w, &tint.Options{
Level: logLevel,
NoColor: !isatty.IsTerminal(w.Fd()) || !color,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if a.Key == slog.TimeKey && len(groups) == 0 {
return slog.Attr{}
}
return a
},
}))
slog.SetDefault(log)
slog.Debug("go2md started")
}
func main() {
setupLogging(slices.Contains(os.Args, "--debug"), !slices.Contains(os.Args, "--no-color"))
if err := execute(os.Stdout); err != nil {
slog.Error(err.Error())
os.Exit(1)
}
}