github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/commands/pluginrepo/list_plugin_repos.go (about) 1 package pluginrepo 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/commandregistry" 5 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 6 "code.cloudfoundry.org/cli/cf/flags" 7 "code.cloudfoundry.org/cli/cf/requirements" 8 "code.cloudfoundry.org/cli/cf/terminal" 9 10 . "code.cloudfoundry.org/cli/cf/i18n" 11 ) 12 13 type ListPluginRepos struct { 14 ui terminal.UI 15 config coreconfig.Reader 16 } 17 18 func init() { 19 commandregistry.Register(&ListPluginRepos{}) 20 } 21 22 func (cmd *ListPluginRepos) MetaData() commandregistry.CommandMetadata { 23 return commandregistry.CommandMetadata{ 24 Name: "list-plugin-repos", 25 Description: T("List all the added plugin repositories"), 26 Usage: []string{ 27 T("CF_NAME list-plugin-repos"), 28 }, 29 } 30 } 31 32 func (cmd *ListPluginRepos) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 33 usageReq := requirements.NewUsageRequirement(commandregistry.CLICommandUsagePresenter(cmd), 34 T("No argument required"), 35 func() bool { 36 return len(fc.Args()) != 0 37 }, 38 ) 39 40 reqs := []requirements.Requirement{ 41 usageReq, 42 } 43 return reqs, nil 44 } 45 46 func (cmd *ListPluginRepos) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 47 cmd.ui = deps.UI 48 cmd.config = deps.Config 49 return cmd 50 } 51 52 func (cmd *ListPluginRepos) Execute(c flags.FlagContext) error { 53 repos := cmd.config.PluginRepos() 54 55 table := cmd.ui.Table([]string{T("Repo Name"), T("URL")}) 56 57 for _, repo := range repos { 58 table.Add(repo.Name, repo.URL) 59 } 60 61 cmd.ui.Ok() 62 cmd.ui.Say("") 63 64 err := table.Print() 65 if err != nil { 66 return err 67 } 68 69 cmd.ui.Say("") 70 return nil 71 }