-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (49 loc) · 1.24 KB
/
main.go
File metadata and controls
58 lines (49 loc) · 1.24 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
// Copyright © 2026 Ping Identity Corporation
package main
import (
"fmt"
"os"
"runtime/debug"
"slices"
"github.com/pingidentity/pingcli/cmd"
"github.com/pingidentity/pingcli/internal/output"
)
var (
// these will be set by the goreleaser configuration
// to appropriate values for the compiled binary
version string = "dev"
commit string = "dev"
)
func main() {
// Try to get the commit hash from the build info if it wasn't set by goreleaser
if commit == "dev" {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
commit = setting.Value
break
}
}
}
}
rootCmd := cmd.NewRootCommand(version, commit)
err := rootCmd.Execute()
if err != nil {
output.UserError(fmt.Sprintf("Failed to execute pingcli: %v", err), nil)
os.Exit(1)
}
if !slices.Contains(os.Args, "--version") &&
!slices.Contains(os.Args, "-v") &&
!slices.Contains(os.Args, "--help") &&
!slices.Contains(os.Args, "-h") {
detailedExitCodeWarnLogged, err := output.DetailedExitCodeWarnLogged()
if err != nil {
output.UserError(fmt.Sprintf("Failed to execute pingcli: %v", err), nil)
os.Exit(1)
}
if detailedExitCodeWarnLogged {
os.Exit(2)
}
}
os.Exit(0)
}