-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (45 loc) · 1.12 KB
/
Copy pathmain.go
File metadata and controls
59 lines (45 loc) · 1.12 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
54
55
56
57
58
59
package main
import (
"context"
"os"
"github.com/evg4b/uncors/internal/cli"
"github.com/evg4b/uncors/internal/di"
"github.com/evg4b/uncors/internal/helpers"
"github.com/evg4b/uncors/internal/infra"
"github.com/evg4b/uncors/internal/tui"
"github.com/spf13/afero"
)
var Version = "v0.0.0"
func main() {
infra.SetupLogging()
container := di.NewContainer(
di.WithFs(afero.NewOsFs()),
di.WithStdout(os.Stdout),
di.WithVersion(Version),
di.WithArgs(os.Args[1:]),
)
// A panic anywhere below is a bug, but the user still deserves a readable
// message instead of a raw stack trace.
defer helpers.PanicInterceptor(func(value any) {
report(value)
osExit(1)
})
defer func() { handleError(container.Close()) }()
if len(os.Args) >= 2 && os.Args[1] == cli.GenerateCertsCmd {
container.Override(di.WithArgs(os.Args[2:]))
handleError(cli.GenerateCerts(container))
return
}
handleError(cli.RunUncors(context.Background(), container))
}
var osExit = os.Exit
func handleError(err error) {
if err != nil {
report(err)
osExit(1)
}
}
func report(value any) {
tui.NewCliOutput(os.Stdout).
Error(value)
}