plugin_download.go 1.8 KB
Newer Older
LinuxSuRen's avatar
LinuxSuRen 已提交
1 2 3
package cmd

import (
4
	"github.com/jenkins-zh/jenkins-cli/app/i18n"
5
	"github.com/jenkins-zh/jenkins-cli/client"
LinuxSuRen's avatar
LinuxSuRen 已提交
6
	"github.com/spf13/cobra"
7
	"net/http"
LinuxSuRen's avatar
LinuxSuRen 已提交
8 9
)

10 11 12 13 14 15 16 17 18 19 20 21
// PluginDownloadOption is the option for plugin download command
type PluginDownloadOption struct {
	SkipDependency bool
	SkipOptional   bool
	UseMirror      bool
	ShowProgress   bool

	RoundTripper http.RoundTripper
}

var pluginDownloadOption PluginDownloadOption

LinuxSuRen's avatar
LinuxSuRen 已提交
22 23
func init() {
	pluginCmd.AddCommand(pluginDownloadCmd)
24
	pluginDownloadCmd.Flags().BoolVarP(&pluginDownloadOption.SkipDependency, "skip-dependency", "", false,
25
		i18n.T("If you want to skip download dependency of plugin"))
26
	pluginDownloadCmd.Flags().BoolVarP(&pluginDownloadOption.SkipOptional, "skip-optional", "", true,
27
		i18n.T("If you want to skip download optional dependency of plugin"))
28
	pluginDownloadCmd.Flags().BoolVarP(&pluginDownloadOption.UseMirror, "use-mirror", "", true,
29
		i18n.T("If you want to download plugin from a mirror site"))
30
	pluginDownloadCmd.Flags().BoolVarP(&pluginDownloadOption.ShowProgress, "show-progress", "", true,
31
		i18n.T("If you want to show the progress of download a plugin"))
LinuxSuRen's avatar
LinuxSuRen 已提交
32 33 34 35
}

var pluginDownloadCmd = &cobra.Command{
	Use:   "download <keyword>",
36 37
	Short: i18n.T("Download the plugins"),
	Long:  i18n.T(`Download the plugins which contain the target plugin and its dependencies`),
38
	Args:  cobra.MinimumNArgs(1),
LinuxSuRen's avatar
LinuxSuRen 已提交
39
	Run: func(cmd *cobra.Command, args []string) {
40 41 42 43 44 45 46 47 48
		jClient := &client.PluginAPI{
			SkipDependency: pluginDownloadOption.SkipDependency,
			SkipOptional:   pluginDownloadOption.SkipOptional,
			UseMirror:      pluginDownloadOption.UseMirror,
			ShowProgress:   pluginDownloadOption.ShowProgress,
			MirrorURL:      getDefaultMirror(),
			RoundTripper:   pluginDownloadOption.RoundTripper,
		}
		jClient.DownloadPlugins(args)
LinuxSuRen's avatar
LinuxSuRen 已提交
49 50
	},
}