提交 69ee6327 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Add option to check update center site and open the browse

上级 d9af8a22
...@@ -14,29 +14,34 @@ import ( ...@@ -14,29 +14,34 @@ import (
"strings" "strings"
"github.com/gosuri/uiprogress" "github.com/gosuri/uiprogress"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
// PluginOptions contains the command line options // PluginOptions contains the command line options
type PluginOptions struct { type PluginOptions struct {
Upload bool Upload bool
CheckUpdate bool
Open bool
} }
func init() { func init() {
rootCmd.AddCommand(pluginCmd) rootCmd.AddCommand(pluginCmd)
pluginCmd.PersistentFlags().BoolVarP(&author.Upload, "upload", "u", false, "Upload plugin to your Jenkins server") pluginCmd.PersistentFlags().BoolVarP(&pluginOpt.Upload, "upload", "u", false, "Upload plugin to your Jenkins server")
pluginCmd.PersistentFlags().BoolVarP(&pluginOpt.CheckUpdate, "check", "c", false, "Checkout update center server")
pluginCmd.PersistentFlags().BoolVarP(&pluginOpt.Open, "open", "o", false, "Open the browse with the address of plugin manager")
viper.BindPFlag("upload", pluginCmd.PersistentFlags().Lookup("upload")) viper.BindPFlag("upload", pluginCmd.PersistentFlags().Lookup("upload"))
} }
var author PluginOptions var pluginOpt PluginOptions
var pluginCmd = &cobra.Command{ var pluginCmd = &cobra.Command{
Use: "plugin", Use: "plugin",
Short: "Manage the plugins of Jenkins", Short: "Manage the plugins of Jenkins",
Long: `Manage the plugins of Jenkins`, Long: `Manage the plugins of Jenkins`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if author.Upload { if pluginOpt.Upload {
crumb, config := getCrumb() crumb, config := getCrumb()
api := fmt.Sprintf("%s/pluginManager/uploadPlugin", config.URL) api := fmt.Sprintf("%s/pluginManager/uploadPlugin", config.URL)
...@@ -74,6 +79,36 @@ var pluginCmd = &cobra.Command{ ...@@ -74,6 +79,36 @@ var pluginCmd = &cobra.Command{
log.Fatal(err) log.Fatal(err)
} }
} }
if pluginOpt.CheckUpdate {
jclient := &client.PluginManager{}
crumb, config := getCrumb()
jclient.CrumbRequestField = crumb.CrumbRequestField
jclient.Crumb = crumb.Crumb
jclient.URL = config.URL
jclient.UserName = config.UserName
jclient.Token = config.Token
jclient.CheckUpdate(func(response *http.Response) {
code := response.StatusCode
if code == 200 {
fmt.Println("update site updated.")
} else {
contentData, _ := ioutil.ReadAll(response.Body)
log.Fatal(fmt.Sprintf("response code is %d, content: ",
code, string(contentData)))
}
})
}
if pluginOpt.Open {
jenkins := getCurrentJenkins()
if jenkins.URL != "" {
open(fmt.Sprintf("%s/pluginManager", jenkins.URL))
} else {
log.Fatal(fmt.Sprintf("No URL fond from %s", jenkins.Name))
}
}
}, },
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册