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