This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (71 loc) · 1.63 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
89
90
91
package main
import (
"os"
"fmt"
"errors"
"runtime"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"
"github.com/abdfnx/gomo/tools"
"github.com/abdfnx/gomo/cmd/gomo"
"github.com/abdfnx/gomo/cmd/factory"
"github.com/abdfnx/gomo/internal/checker"
"github.com/AlecAivazis/survey/v2/terminal"
surveyCore "github.com/AlecAivazis/survey/v2/core"
)
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()
cmdFactory := factory.New()
hasDebug := os.Getenv("DEBUG") != ""
stderr := cmdFactory.IOStreams.ErrOut
if !cmdFactory.IOStreams.ColorEnabled() {
surveyCore.DisableColor = true
} else {
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
switch style {
case "white":
if cmdFactory.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 := gomo.Execute(cmdFactory, 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 gomo.HasFailed() {
return exitError
}
checker.Check(version)
return exitOK
}