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