-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (33 loc) · 848 Bytes
/
Copy pathmain.go
File metadata and controls
40 lines (33 loc) · 848 Bytes
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
package main
import (
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"github.com/hashmap-kz/kubectl-apidocs/cmd"
"github.com/hashmap-kz/kubectl-apidocs/internal/apidocs"
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
func main() {
// debug logger
var logFile *os.File
if os.Getenv("KUBECTL_APIDOCS_DEBUG_LOG") == "enable" {
lg := filepath.Join(os.TempDir(), "kubectl-apidocs.log")
logFile, err := os.OpenFile(lg, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o666)
if err != nil {
slog.Error("failed to open log file", "error", err)
return
}
slog.SetDefault(apidocs.InitLogger(logFile))
} else {
slog.SetDefault(slog.New(slog.NewTextHandler(io.Discard, nil)))
}
// app
if err := cmd.NewCmdAPIDocs().Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
_ = logFile.Close()
os.Exit(1)
}
_ = logFile.Close()
}