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