-
Notifications
You must be signed in to change notification settings - Fork 929
/
main.go
68 lines (55 loc) · 1.52 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
//go:build go1.13
// +build go1.13
package main
import (
"fmt"
"os"
"code.cloudfoundry.org/cli/cf/cmd"
"code.cloudfoundry.org/cli/command/common"
"code.cloudfoundry.org/cli/util/command_parser"
"code.cloudfoundry.org/cli/util/configv3"
"code.cloudfoundry.org/cli/util/panichandler"
plugin_util "code.cloudfoundry.org/cli/util/plugin"
"code.cloudfoundry.org/cli/util/ui"
)
func main() {
var exitCode int
defer panichandler.HandlePanic()
config, err := configv3.GetCFConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error())
os.Exit(1)
}
commandUI, err := ui.NewUI(config)
if err != nil {
fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error())
os.Exit(1)
}
p, err := command_parser.NewCommandParser(config)
if err != nil {
fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error())
os.Exit(1)
}
exitCode, err = p.ParseCommandFromArgs(commandUI, os.Args[1:])
if err == nil {
os.Exit(exitCode)
}
if unknownCommandError, ok := err.(command_parser.UnknownCommandError); ok {
plugin, commandIsPlugin := plugin_util.IsPluginCommand(os.Args[1:])
switch {
case commandIsPlugin:
err = plugin_util.RunPlugin(plugin)
if err != nil {
exitCode = 1
}
case common.ShouldFallbackToLegacy:
cmd.Main(os.Getenv("CF_TRACE"), os.Args)
//NOT REACHED, legacy main will exit the process
default:
unknownCommandError.Suggest(plugin_util.PluginCommandNames())
fmt.Fprintf(os.Stderr, "%s\n", unknownCommandError.Error())
os.Exit(1)
}
}
os.Exit(exitCode)
}