This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
executable file
·88 lines (69 loc) · 1.68 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"errors"
"fmt"
"os"
"runtime"
surveyCore "github.com/AlecAivazis/survey/v2/core"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/mgutz/ansi"
"github.com/scmn-dev/secman/v6/cli/factory"
"github.com/scmn-dev/secman/v6/cli/secman"
"github.com/scmn-dev/secman/v6/tools"
"github.com/spf13/cobra"
)
var (
version string
buildDate string
)
type exitCode int
const (
exitOK exitCode = 0
exitError exitCode = 1
exitCancel exitCode = 2
)
func main() {
code := mainRun()
os.Exit(int(code))
}
func mainRun() exitCode {
runtime.LockOSThread()
cliFactory := factory.New()
hasDebug := os.Getenv("DEBUG") != ""
stderr := cliFactory.IOStreams.ErrOut
if !cliFactory.IOStreams.ColorEnabled() {
surveyCore.DisableColor = true
} else {
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
switch style {
case "white":
if cliFactory.IOStreams.ColorSupport256() {
return fmt.Sprintf("\x1b[%d;5;%dm", 38, 242)
}
return ansi.ColorCode("default")
default:
return ansi.ColorCode(style)
}
}
}
if len(os.Args) > 1 && os.Args[1] != "" {
cobra.MousetrapHelpText = ""
}
RootCmd := secman.Execute(cliFactory, version, buildDate)
if cmd, err := RootCmd.ExecuteC(); err != nil {
if err == tools.SilentError {
return exitError
} else if tools.IsUserCancellation(err) {
if errors.Is(err, terminal.InterruptErr) {
fmt.Fprint(stderr, "\n")
}
return exitCancel
}
tools.PrintError(stderr, err, cmd, hasDebug)
return exitError
}
if secman.HasFailed() {
return exitError
}
return exitOK
}