MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Main

Function Main

cf/cmd/cmd.go:32–164  ·  view source on GitHub ↗
(traceEnv string, args []string)

Source from the content-addressed store, hash-verified

30var cmdRegistry = commandregistry.Commands
31
32func Main(traceEnv string, args []string) {
33
34 // handle `cf -v` for cf version
35 if len(args) == 2 && (args[1] == "-v" || args[1] == "--version") {
36 args[1] = "version"
37 }
38
39 // handles `cf`
40 if len(args) == 1 {
41 args = []string{args[0], "help"}
42 }
43
44 // handles `cf [COMMAND] -h ...`
45 // rearrange args to `cf help COMMAND` and let `command help` to print out usage
46 args = append([]string{args[0]}, handleHelp(args[1:])...)
47
48 newArgs, isVerbose := handleVerbose(args)
49 args = newArgs
50
51 errFunc := func(err error) {
52 if err != nil {
53 ui := terminal.NewUI(
54 os.Stdin,
55 Writer,
56 terminal.NewTeePrinter(Writer),
57 trace.NewLogger(Writer, isVerbose, traceEnv, ""),
58 )
59 ui.Failed(fmt.Sprintf("Config error: %s", err))
60 os.Exit(1)
61 }
62 }
63
64 // Only used to get Trace, so our errorHandler doesn't matter, since it's not used
65 configPath, err := confighelpers.DefaultFilePath()
66 if err != nil {
67 errFunc(err)
68 }
69 config := coreconfig.NewRepositoryFromFilepath(configPath, errFunc)
70 defer config.Close()
71
72 traceConfigVal := config.Trace()
73
74 // Writer is assigned in writer_unix.go/writer_windows.go
75 traceLogger := trace.NewLogger(Writer, isVerbose, traceEnv, traceConfigVal)
76
77 deps := commandregistry.NewDependency(Writer, traceLogger, os.Getenv("CF_DIAL_TIMEOUT"))
78 defer deps.Config.Close()
79
80 warningProducers := []net.WarningProducer{}
81 for _, warningProducer := range deps.Gateways {
82 warningProducers = append(warningProducers, warningProducer)
83 }
84
85 warningsCollector := net.NewWarningsCollector(deps.UI, warningProducers...)
86
87 commandsloader.Load()
88
89 // run core command

Callers 3

mainFunction · 0.92
RunPluginFunction · 0.92
handleErrorMethod · 0.92

Calls 15

FailedMethod · 0.95
SkipFlagParsingMethod · 0.95
ParseMethod · 0.95
PrintWarningsMethod · 0.95
PluginsMethod · 0.95
ListCommandsMethod · 0.95
NewUIFunction · 0.92
NewTeePrinterFunction · 0.92
NewLoggerFunction · 0.92
DefaultFilePathFunction · 0.92
NewDependencyFunction · 0.92

Tested by

no test coverage detected