MCPcopy
hub / github.com/cloudfoundry/cli / RunMethodIfExists

Function RunMethodIfExists

plugin/rpc/run_plugin.go:10–36  ·  view source on GitHub ↗
(rpcService *CliRpcService, args []string, pluginList map[string]pluginconfig.PluginMetadata)

Source from the content-addressed store, hash-verified

8)
9
10func RunMethodIfExists(rpcService *CliRpcService, args []string, pluginList map[string]pluginconfig.PluginMetadata) bool {
11 for _, metadata := range pluginList {
12 for _, command := range metadata.Commands {
13 if command.Name == args[0] || command.Alias == args[0] {
14 args[0] = command.Name
15
16 rpcService.Start()
17 defer rpcService.Stop()
18
19 pluginArgs := append([]string{rpcService.Port()}, args...)
20
21 cmd := exec.Command(metadata.Location, pluginArgs...)
22 cmd.Stdout = os.Stdout
23 cmd.Stdin = os.Stdin
24 cmd.Stderr = os.Stderr
25
26 defer stopPlugin(cmd)
27 err := cmd.Run()
28 if err != nil {
29 os.Exit(1)
30 }
31 return true
32 }
33 }
34 }
35 return false
36}
37
38func stopPlugin(plugin *exec.Cmd) {
39 plugin.Process.Kill()

Callers

nothing calls this directly

Calls 7

stopPluginFunction · 0.85
StartMethod · 0.65
StopMethod · 0.65
CommandMethod · 0.65
RunMethod · 0.65
ExitMethod · 0.65
PortMethod · 0.45

Tested by

no test coverage detected