From c7ea09d5eff5961f4bff6b841413a55a65be566e Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie Date: Tue, 2 Jul 2019 13:55:52 +0800 Subject: [PATCH] Add batch mode option --- app/cmd/common.go | 6 ++++++ app/cmd/restart.go | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/cmd/common.go b/app/cmd/common.go index f057aa0..0bedde9 100644 --- a/app/cmd/common.go +++ b/app/cmd/common.go @@ -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) } diff --git a/app/cmd/restart.go b/app/cmd/restart.go index 50828fd..937b8e2 100644 --- a/app/cmd/restart.go +++ b/app/cmd/restart.go @@ -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) -- GitLab