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

Merge pull request #57 from LinuxSuRen/fea/open-inter

Allow user to open Jenkins by interfactive mode
......@@ -75,3 +75,13 @@ type WatchOption struct {
Watch bool
Interval int
}
// InteractiveOption allow user to choose whether the mode is interactive
type InteractiveOption struct {
Interactive bool
}
// SetFlag set the option flag to this cmd
func (b *InteractiveOption) SetFlag(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&b.Interactive, "interactive", "i", false, "Interactive mode")
}
......@@ -6,10 +6,13 @@ import (
"os/exec"
"runtime"
"github.com/AlecAivazis/survey"
"github.com/spf13/cobra"
)
type OpenOption struct {
InteractiveOption
Name string
Config bool
}
......@@ -20,6 +23,7 @@ func init() {
rootCmd.AddCommand(openCmd)
openCmd.PersistentFlags().StringVarP(&openOption.Name, "name", "n", "", "Open a specific Jenkins by name")
openCmd.PersistentFlags().BoolVarP(&openOption.Config, "config", "c", false, "Open the configuration page of Jenkins")
openOption.SetFlag(openCmd)
}
var openCmd = &cobra.Command{
......@@ -29,10 +33,19 @@ var openCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
var jenkins *JenkinsServer
if openOption.Name == "" {
jenkins = getCurrentJenkins()
} else {
if openOption.Name == "" && openOption.Interactive {
jenkinsNames := getJenkinsNames()
prompt := &survey.Select{
Message: "Choose a Jenkins that you want to open:",
Options: jenkinsNames,
}
survey.AskOne(prompt, &(openOption.Name))
}
if openOption.Name != "" {
jenkins = findJenkinsByName(openOption.Name)
} else {
jenkins = getCurrentJenkins()
}
if jenkins != nil && jenkins.URL != "" {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册