-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
restart.go
59 lines (50 loc) · 1.3 KB
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
"net/http"
"github.com/AlecAivazis/survey/v2"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
)
// RestartOption holds the options for restart cmd
type RestartOption struct {
BatchOption
RoundTripper http.RoundTripper
}
var restartOption RestartOption
func init() {
rootCmd.AddCommand(restartCmd)
restartCmd.Flags().BoolVarP(&restartOption.Batch, "batch", "b", false, "Batch mode, no need confirm")
}
var restartCmd = &cobra.Command{
Use: "restart",
Short: "Restart your Jenkins",
Long: `Restart your Jenkins`,
Run: func(cmd *cobra.Command, _ []string) {
jenkins := getCurrentJenkinsFromOptionsOrDie()
if !restartOption.Batch {
confirm := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("Are you sure to restart Jenkins %s?", jenkins.URL),
}
if err := survey.AskOne(prompt, &confirm); !confirm {
return
} else if err != nil {
cmd.PrintErrln(err)
return
}
}
jclient := &client.CoreClient{
JenkinsCore: client.JenkinsCore{
RoundTripper: restartOption.RoundTripper,
Debug: rootOptions.Debug,
},
}
getCurrentJenkinsAndClient(&(jclient.JenkinsCore))
if err := jclient.Restart(); err == nil {
cmd.Println("Please wait while Jenkins is restarting")
} else {
cmd.PrintErrln(err)
}
},
}