未验证 提交 d17ea3c3 编写于 作者: Z Zhao Xiaojie 提交者: GitHub

Merge pull request #52 from LinuxSuRen/fea/confirm-del-job

Confirm before user delete a job
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/AlecAivazis/survey" "github.com/AlecAivazis/survey"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
...@@ -65,6 +66,10 @@ func (b *BatchOption) Confirm(message string) bool { ...@@ -65,6 +66,10 @@ func (b *BatchOption) Confirm(message string) bool {
return true return true
} }
func (b *BatchOption) SetFlag(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&b.Batch, "batch", "b", false, "Batch mode, no need confirm")
}
// WatchOption for the resources which can be watched // WatchOption for the resources which can be watched
type WatchOption struct { type WatchOption struct {
Watch bool Watch bool
......
package cmd package cmd
import ( import (
"fmt"
"log" "log"
"github.com/linuxsuren/jenkins-cli/client" "github.com/linuxsuren/jenkins-cli/client"
...@@ -8,12 +9,15 @@ import ( ...@@ -8,12 +9,15 @@ import (
) )
type JobDeleteOption struct { type JobDeleteOption struct {
BatchOption
} }
var jobDeleteOption JobDeleteOption var jobDeleteOption JobDeleteOption
func init() { func init() {
jobCmd.AddCommand(jobDeleteCmd) jobCmd.AddCommand(jobDeleteCmd)
jobDeleteOption.SetFlag(jobDeleteCmd)
// jobDeleteCmd.Flags().BoolVarP(&jobDeleteOption.Batch, "batch", "b", false, "Batch mode, no need confirm")
} }
var jobDeleteCmd = &cobra.Command{ var jobDeleteCmd = &cobra.Command{
...@@ -27,6 +31,9 @@ var jobDeleteCmd = &cobra.Command{ ...@@ -27,6 +31,9 @@ var jobDeleteCmd = &cobra.Command{
} }
jobName := args[0] jobName := args[0]
if !jobDeleteOption.Confirm(fmt.Sprintf("Are you sure to delete job %s ?", jobName)) {
return
}
jenkins := getCurrentJenkins() jenkins := getCurrentJenkins()
jclient := &client.JobClient{} jclient := &client.JobClient{}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册