github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/util/configv3/plugin_repository.go (about)

     1  package configv3
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  )
     7  
     8  const (
     9  	// DefaultPluginRepoName is the name of the preinstalled plugin repository.
    10  	DefaultPluginRepoName = "CF-Community"
    11  
    12  	// DefaultPluginRepoURL is the URL of the preinstalled plugin repository.
    13  	DefaultPluginRepoURL = "https://plugins.cloudfoundry.org"
    14  )
    15  
    16  // PluginRepository is a saved plugin repository
    17  type PluginRepository struct {
    18  	Name string `json:"Name"`
    19  	URL  string `json:"URL"`
    20  }
    21  
    22  // AddPluginRepository adds an new repository to the plugin config. It does not
    23  // add duplicates to the config.
    24  func (config *Config) AddPluginRepository(name string, url string) {
    25  	config.ConfigFile.PluginRepositories = append(config.ConfigFile.PluginRepositories,
    26  		PluginRepository{Name: name, URL: url})
    27  }
    28  
    29  // PluginRepositories returns the currently configured plugin repositories from the
    30  // .cf/config.json.
    31  func (config *Config) PluginRepositories() []PluginRepository {
    32  	repos := config.ConfigFile.PluginRepositories
    33  	sort.Slice(repos, func(i, j int) bool {
    34  		return strings.ToLower(repos[i].Name) < strings.ToLower(repos[j].Name)
    35  	})
    36  	return repos
    37  }