github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/main.go (about) 1 //go:build go1.13 2 // +build go1.13 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 10 "github.com/LukasHeimann/cloudfoundrycli/v8/cf/cmd" 11 "github.com/LukasHeimann/cloudfoundrycli/v8/command/common" 12 "github.com/LukasHeimann/cloudfoundrycli/v8/util/command_parser" 13 "github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3" 14 "github.com/LukasHeimann/cloudfoundrycli/v8/util/panichandler" 15 plugin_util "github.com/LukasHeimann/cloudfoundrycli/v8/util/plugin" 16 "github.com/LukasHeimann/cloudfoundrycli/v8/util/ui" 17 ) 18 19 func main() { 20 var exitCode int 21 defer panichandler.HandlePanic() 22 23 config, err := configv3.GetCFConfig() 24 if err != nil { 25 fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error()) 26 os.Exit(1) 27 } 28 29 commandUI, err := ui.NewUI(config) 30 if err != nil { 31 fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error()) 32 os.Exit(1) 33 } 34 35 p, err := command_parser.NewCommandParser() 36 if err != nil { 37 fmt.Fprintf(os.Stderr, "Unexpected error: %s\n", err.Error()) 38 os.Exit(1) 39 } 40 41 exitCode, err = p.ParseCommandFromArgs(commandUI, os.Args[1:]) 42 if err == nil { 43 os.Exit(exitCode) 44 } 45 46 if unknownCommandError, ok := err.(command_parser.UnknownCommandError); ok { 47 plugin, commandIsPlugin := plugin_util.IsPluginCommand(os.Args[1:]) 48 49 switch { 50 case commandIsPlugin: 51 err = plugin_util.RunPlugin(plugin) 52 if err != nil { 53 exitCode = 1 54 } 55 56 case common.ShouldFallbackToLegacy: 57 cmd.Main(os.Getenv("CF_TRACE"), os.Args) 58 //NOT REACHED, legacy main will exit the process 59 60 default: 61 unknownCommandError.Suggest(plugin_util.PluginCommandNames()) 62 fmt.Fprintf(os.Stderr, "%s\n", unknownCommandError.Error()) 63 os.Exit(1) 64 } 65 } 66 67 os.Exit(exitCode) 68 }