未验证 提交 3b07e63b 编写于 作者: JenkinsInChina's avatar JenkinsInChina 提交者: GitHub

Add timeout option for plugin check command (#422)

上级 b55703d8
......@@ -2,10 +2,10 @@ package cmd
import (
"fmt"
"github.com/jenkins-zh/jenkins-cli/app/helper"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"io/ioutil"
"net/http"
"time"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
......@@ -14,33 +14,40 @@ import (
// PluginCheckoutOption is the option for plugin checkout command
type PluginCheckoutOption struct {
RoundTripper http.RoundTripper
// Timeout is the timeout setting for check Jenkins update-center
Timeout int64
}
var pluginCheckoutOption PluginCheckoutOption
func init() {
pluginCmd.AddCommand(pluginCheckCmd)
flags := pluginCheckCmd.Flags()
flags.Int64VarP(&pluginCheckoutOption.Timeout, "timeout", "", 30,
"Timeout in second setting for checking Jenkins update-center")
}
var pluginCheckCmd = &cobra.Command{
Use: "check",
Short: i18n.T("Check update center server"),
Long: i18n.T(`Check update center server`),
Run: func(cmd *cobra.Command, _ []string) {
RunE: func(cmd *cobra.Command, _ []string) (err error) {
jClient := &client.PluginManager{
JenkinsCore: client.JenkinsCore{
RoundTripper: pluginCheckoutOption.RoundTripper,
Timeout: time.Duration(pluginCheckoutOption.Timeout) * time.Second,
},
}
getCurrentJenkinsAndClientOrDie(&(jClient.JenkinsCore))
getCurrentJenkinsAndClient(&(jClient.JenkinsCore))
err := jClient.CheckUpdate(func(response *http.Response) {
err = jClient.CheckUpdate(func(response *http.Response) {
code := response.StatusCode
if code != 200 {
contentData, _ := ioutil.ReadAll(response.Body)
cmd.PrintErrln(fmt.Sprintf("response code is %d, content: %s", code, string(contentData)))
}
})
helper.CheckErr(cmd, err)
return
},
}
......@@ -26,8 +26,7 @@ var pluginListCmd = &cobra.Command{
Use: "list",
Short: i18n.T("Print all the plugins which are installed"),
Long: i18n.T("Print all the plugins which are installed"),
Example: ` jcli plugin list --filter name=github
jcli plugin list --filter hasUpdate
Example: ` jcli plugin list --filter ShortName=github
jcli plugin list --no-headers`,
RunE: func(cmd *cobra.Command, _ []string) (err error) {
jClient := &client.PluginManager{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册