** * This function is called by the plugin to setup their server. This allows us to call Run on the plugin * os.Args[1] port CF_CLI rpc server is running on * os.Args[2] **OPTIONAL** * SendMetadata - used to fetch the plugin metadata **/
(cmd Plugin)
| 13 | * SendMetadata - used to fetch the plugin metadata |
| 14 | **/ |
| 15 | func Start(cmd Plugin) { |
| 16 | if len(os.Args) < 2 { |
| 17 | fmt.Printf("This cf CLI plugin is not intended to be run on its own\n\n") |
| 18 | os.Exit(1) |
| 19 | } |
| 20 | |
| 21 | cliConnection := NewCliConnection(os.Args[1]) |
| 22 | cliConnection.pingCLI() |
| 23 | if isMetadataRequest(os.Args) { |
| 24 | cliConnection.sendPluginMetadataToCliServer(cmd.GetMetadata()) |
| 25 | } else { |
| 26 | if version := MinCliVersionStr(cmd.GetMetadata().MinCliVersion); version != "" { |
| 27 | ok := cliConnection.isMinCliVersion(version) |
| 28 | if !ok { |
| 29 | fmt.Printf("Minimum CLI version %s is required to run this plugin command\n\n", version) |
| 30 | os.Exit(0) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | cmd.Run(cliConnection, os.Args[2:]) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func isMetadataRequest(args []string) bool { |
| 39 | return len(args) == 3 && args[2] == "SendMetadata" |
no test coverage detected