github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/util/configv3/plugins.go (about) 1 package configv3 2 3 import ( 4 "path/filepath" 5 6 "code.cloudfoundry.org/cli/util/sorting" 7 ) 8 9 const ( 10 // DefaultPluginRepoName is the name of the preinstalled plugin repository. 11 DefaultPluginRepoName = "CF-Community" 12 13 // DefaultPluginRepoURL is the URL of the preinstalled plugin repository. 14 DefaultPluginRepoURL = "https://plugins.cloudfoundry.org" 15 ) 16 17 // PluginRepos is a saved plugin repository 18 type PluginRepos struct { 19 Name string `json:"Name"` 20 URL string `json:"URL"` 21 } 22 23 // PluginsConfig represents the plugin configuration 24 type PluginsConfig struct { 25 Plugins map[string]Plugin `json:"Plugins"` 26 } 27 28 // Plugin represents the plugin as a whole, not be confused with PluginCommand 29 type Plugin struct { 30 Location string `json:"Location"` 31 Version PluginVersion `json:"Version"` 32 Commands PluginCommands `json:"Commands"` 33 } 34 35 // PluginVersion is the plugin version information 36 type PluginVersion struct { 37 Major int `json:"Major"` 38 Minor int `json:"Minor"` 39 Build int `json:"Build"` 40 } 41 42 // PluginCommands is a list of plugins that implements the sort.Interface 43 type PluginCommands []PluginCommand 44 45 func (p PluginCommands) Len() int { return len(p) } 46 func (p PluginCommands) Swap(i int, j int) { p[i], p[j] = p[j], p[i] } 47 func (p PluginCommands) Less(i int, j int) bool { return sorting.SortAlphabetic(p[i].Name, p[j].Name) } 48 49 // PluginCommand represents an individual command inside a plugin 50 type PluginCommand struct { 51 Name string `json:"Name"` 52 Alias string `json:"Alias"` 53 HelpText string `json:"HelpText"` 54 UsageDetails PluginUsageDetails `json:"UsageDetails"` 55 } 56 57 // PluginUsageDetails contains the usage metadata provided by the plugin 58 type PluginUsageDetails struct { 59 Usage string `json:"Usage"` 60 Options map[string]string `json:"Options"` 61 } 62 63 // PluginHome returns the plugin configuration directory based off: 64 // 1. The $CF_PLUGIN_HOME environment variable if set 65 // 2. Defaults to the home diretory (outlined in LoadConfig)/.cf/plugins 66 func (config *Config) PluginHome() string { 67 if config.ENV.CFPluginHome != "" { 68 return filepath.Join(config.ENV.CFPluginHome, ".cf", "plugins") 69 } 70 71 return filepath.Join(homeDirectory(), ".cf", "plugins") 72 } 73 74 // Plugins returns back the plugin configuration read from the plugin home 75 func (config *Config) Plugins() map[string]Plugin { 76 return config.pluginConfig.Plugins 77 } 78 79 // PluginRepos returns the currently configured plugin repositories from the 80 // .cf/config.json 81 func (config *Config) PluginRepos() []PluginRepos { 82 return config.ConfigFile.PluginRepos 83 }