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

Add batchOption for job build

上级 e25c8531
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/AlecAivazis/survey"
"gopkg.in/yaml.v2"
)
......@@ -12,11 +13,6 @@ 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)
}
......@@ -47,3 +43,24 @@ func Format(obj interface{}, format string) (data []byte, err error) {
return nil, fmt.Errorf("not support format %s", format)
}
// BatchOption represent the options for a batch operation
type BatchOption struct {
Batch bool
}
// Confirm prompte user if they really want to do this
func (b *BatchOption) Confirm(message string) bool {
if !b.Batch {
confirm := false
prompt := &survey.Confirm{
Message: message,
}
survey.AskOne(prompt, &confirm)
if !confirm {
return false
}
}
return true
}
package cmd
import (
"fmt"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type JobBuildOption struct {
BatchOption
}
var jobBuildOption JobBuildOption
func init() {
jobCmd.AddCommand(jobBuildCmd)
jobBuildCmd.Flags().BoolVarP(&jobBuildOption.Batch, "batch", "b", false, "Batch mode, no need confirm")
}
var jobBuildCmd = &cobra.Command{
......@@ -19,6 +28,10 @@ var jobBuildCmd = &cobra.Command{
return
}
if !jobBuildOption.Confirm(fmt.Sprintf("Are you sure to build job %s", jobOption.Name)) {
return
}
jenkins := getCurrentJenkins()
jclient := &client.JobClient{}
jclient.URL = jenkins.URL
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册