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

Add batch mode option

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