-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (46 loc) · 1.02 KB
/
main.go
File metadata and controls
53 lines (46 loc) · 1.02 KB
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
package main
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/akm/git-exec/core"
)
func main() {
if len(os.Args) < 2 {
core.Help()
os.Exit(1)
}
logLevelMap := map[string]slog.Level{
"debug": slog.LevelDebug,
"info": slog.LevelInfo,
"warn": slog.LevelWarn,
"error": slog.LevelError,
}
logLevel, ok := logLevelMap[strings.ToLower(os.Getenv("LOG_LEVEL"))]
if !ok {
logLevel = slog.LevelWarn
}
logHandler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel})
slog.SetDefault(slog.New(logHandler))
options, commandArgs, err := core.ParseOptions(os.Args[1:])
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse arguments: %s\n", err.Error())
}
if options.Help {
core.Help()
os.Exit(0)
} else if options.Version {
if len(commandArgs) == 0 {
showVersion()
os.Exit(0)
} else {
showVersionWithExecName(filepath.Base(os.Args[0]))
}
}
if err := core.Run(options, commandArgs); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}