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

Add batch mode option

上级 a4038fd6
......@@ -7,10 +7,16 @@ import (
"gopkg.in/yaml.v2"
)
// OutputOption represent the format of output
type OutputOption struct {
Format string
}
// BatchOption represent the options for a batch operation
type BatchOption struct {
Batch bool
}
type FormatOutput interface {
Output(obj interface{}, format string) (data []byte, err error)
}
......
......@@ -11,8 +11,16 @@ import (
"github.com/spf13/cobra"
)
// RestartOption holds the options for restart cmd
type RestartOption struct {
BatchOption
}
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{
......@@ -21,13 +29,16 @@ var restartCmd = &cobra.Command{
Long: `Restart your Jenkins`,
Run: func(cmd *cobra.Command, args []string) {
crumb, config := getCrumb()
confirm := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("Are you sure to restart Jenkins %s?", config.URL),
}
survey.AskOne(prompt, &confirm)
if !confirm {
return
if !restartOption.Batch {
confirm := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("Are you sure to restart Jenkins %s?", config.URL),
}
survey.AskOne(prompt, &confirm)
if !confirm {
return
}
}
api := fmt.Sprintf("%s/safeRestart", config.URL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册