github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/plugin/plugin_shim.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 "os" 6 "strconv" 7 ) 8 9 /** 10 * This function is called by the plugin to setup their server. This allows us to call Run on the plugin 11 * os.Args[1] port CF_CLI rpc server is running on 12 * os.Args[2] **OPTIONAL** 13 * SendMetadata - used to fetch the plugin metadata 14 **/ 15 func Start(cmd Plugin) { 16 cliConnection := NewCliConnection(os.Args[1]) 17 18 cliConnection.pingCLI() 19 if isMetadataRequest(os.Args) { 20 cliConnection.sendPluginMetadataToCliServer(cmd.GetMetadata()) 21 } else { 22 if version := MinCliVersionStr(cmd.GetMetadata().MinCliVersion); version != "" { 23 ok := cliConnection.isMinCliVersion(version) 24 if !ok { 25 fmt.Printf("Minimum CLI version %s is required to run this plugin command\n\n", version) 26 os.Exit(0) 27 } 28 } 29 30 cmd.Run(cliConnection, os.Args[2:]) 31 } 32 } 33 34 func isMetadataRequest(args []string) bool { 35 return len(args) == 3 && args[2] == "SendMetadata" 36 } 37 38 func MinCliVersionStr(version VersionType) string { 39 if version.Major == 0 && version.Minor == 0 && version.Build == 0 { 40 return "" 41 } 42 43 return strconv.Itoa(version.Major) + "." + strconv.Itoa(version.Minor) + "." + strconv.Itoa(version.Build) 44 }