github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/command/plugin/add_plugin_repo_command.go (about) 1 package plugin 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/pluginaction" 6 "code.cloudfoundry.org/cli/command" 7 "code.cloudfoundry.org/cli/command/flag" 8 "code.cloudfoundry.org/cli/command/plugin/shared" 9 ) 10 11 //go:generate counterfeiter . AddPluginRepoActor 12 13 type AddPluginRepoActor interface { 14 AddPluginRepository(repoName string, repoURL string) error 15 } 16 17 type AddPluginRepoCommand struct { 18 RequiredArgs flag.AddPluginRepoArgs `positional-args:"yes"` 19 usage interface{} `usage:"CF_NAME add-plugin-repo REPO_NAME URL\n\nEXAMPLES:\n CF_NAME add-plugin-repo ExampleRepo https://example.com/repo"` 20 relatedCommands interface{} `related_commands:"install-plugin, list-plugin-repos"` 21 SkipSSLValidation bool `short:"k" hidden:"true" description:"Skip SSL certificate validation"` 22 UI command.UI 23 Config command.Config 24 Actor AddPluginRepoActor 25 } 26 27 func (cmd *AddPluginRepoCommand) Setup(config command.Config, ui command.UI) error { 28 cmd.UI = ui 29 cmd.Config = config 30 cmd.Actor = pluginaction.NewActor(config, shared.NewClient(config, ui, cmd.SkipSSLValidation)) 31 return nil 32 } 33 34 func (cmd AddPluginRepoCommand) Execute(args []string) error { 35 err := cmd.Actor.AddPluginRepository(cmd.RequiredArgs.PluginRepoName, cmd.RequiredArgs.PluginRepoURL) 36 switch e := err.(type) { 37 case actionerror.RepositoryAlreadyExistsError: 38 cmd.UI.DisplayTextWithFlavor("{{.RepositoryURL}} already registered as {{.RepositoryName}}", 39 map[string]interface{}{ 40 "RepositoryName": e.Name, 41 "RepositoryURL": e.URL, 42 }) 43 case nil: 44 cmd.UI.DisplayTextWithFlavor("{{.RepositoryURL}} added as {{.RepositoryName}}", 45 map[string]interface{}{ 46 "RepositoryName": cmd.RequiredArgs.PluginRepoName, 47 "RepositoryURL": cmd.RequiredArgs.PluginRepoURL, 48 }) 49 default: 50 return err 51 } 52 53 return nil 54 }