From 88569c27df10b621c560ca112064ec54f94bdbbd Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 15 Apr 2020 09:20:49 +0800 Subject: [PATCH] Add file as a options for jcli plugin upload --- app/cmd/plugin_upload.go | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/app/cmd/plugin_upload.go b/app/cmd/plugin_upload.go index eea16f3..47ac3de 100644 --- a/app/cmd/plugin_upload.go +++ b/app/cmd/plugin_upload.go @@ -23,6 +23,7 @@ type PluginUploadOption struct { RemotePassword string RemoteJenkins string ShowProgress bool + FileName string RoundTripper http.RoundTripper @@ -37,6 +38,8 @@ func init() { pluginCmd.AddCommand(pluginUploadCmd) pluginUploadCmd.Flags().BoolVarP(&pluginUploadOption.ShowProgress, "show-progress", "", true, i18n.T("Whether show the upload progress")) + pluginUploadCmd.Flags().StringVarP(&pluginUploadOption.FileName, "file", "f", "", + i18n.T("The plugin file path which should end with .hpi")) pluginUploadCmd.Flags().StringVarP(&pluginUploadOption.Remote, "remote", "r", "", i18n.T("Remote plugin URL")) pluginUploadCmd.Flags().StringVarP(&pluginUploadOption.RemoteUser, "remote-user", "", "", @@ -50,6 +53,25 @@ func init() { i18n.T("Whether skip the previous command hook")) pluginUploadCmd.Flags().BoolVarP(&pluginUploadOption.SkipPostHook, "skip-posthook", "", false, i18n.T("Whether skip the post command hook")) + + if err := pluginUploadCmd.RegisterFlagCompletionFunc("file", pluginUploadOption.HPICompletion); err != nil { + pluginCmd.PrintErrln(err) + } +} + +func (o *PluginUploadOption) HPICompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + targetFiles := make([]string, 0) + if files, err := filepath.Glob("*.hpi"); err == nil { + targetFiles = append(targetFiles, files...) + } + if files, err := filepath.Glob("target/*.hpi"); err == nil { + targetFiles = append(targetFiles, files...) + } + return targetFiles, cobra.ShellCompDirectiveNoFileComp } var pluginUploadCmd = &cobra.Command{ @@ -111,20 +133,7 @@ jcli plugin upload sample.hpi --show-progress=false`, executePostCmd(cmd, args, cmd.OutOrStdout()) }, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - targetFiles := make([]string, 0) - if files, err := filepath.Glob("*.hpi"); err == nil { - targetFiles = append(targetFiles, files...) - } - if files, err := filepath.Glob("target/*.hpi"); err == nil { - targetFiles = append(targetFiles, files...) - } - return targetFiles, cobra.ShellCompDirectiveNoFileComp - }, + ValidArgsFunction: pluginUploadOption.HPICompletion, Run: func(cmd *cobra.Command, _ []string) { jclient := &client.PluginManager{ JenkinsCore: client.JenkinsCore{ -- GitLab