提交 9517785f 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Allow uses to open multi-jenkins

上级 1e10cd45
......@@ -111,12 +111,18 @@ func getConfig() Config {
return config
}
func getCurrentJenkins() (jenkinsServer JenkinsServer) {
func getCurrentJenkins() (jenkinsServer *JenkinsServer) {
config := getConfig()
current := config.Current
jenkinsServer = findJenkinsByName(current)
return
}
func findJenkinsByName(name string) (jenkinsServer *JenkinsServer) {
for _, cfg := range config.JenkinsServers {
if cfg.Name == current {
jenkinsServer = cfg
if cfg.Name == name {
jenkinsServer = &cfg
break
}
}
......
......@@ -35,7 +35,7 @@ type CrumbIssuer struct {
CrumbRequestField string `json:"crumbRequestField"`
}
func getCrumb() (CrumbIssuer, JenkinsServer) {
func getCrumb() (CrumbIssuer, *JenkinsServer) {
config := getCurrentJenkins()
jenkinsRoot := config.URL
......
package cmd
import (
"fmt"
"log"
"os/exec"
"runtime"
......@@ -8,20 +9,40 @@ import (
"github.com/spf13/cobra"
)
type OpenOption struct {
Name string
Config bool
}
var openOption OpenOption
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")
}
var openCmd = &cobra.Command{
Use: "open",
Short: "Open your Jenkins in the browse",
Long: `Open your Jenkins in the browse`,
Short: "Open your Jenkins with a browse",
Long: `Open your Jenkins with a browse`,
Run: func(cmd *cobra.Command, args []string) {
jenkins := getCurrentJenkins()
if jenkins.URL != "" {
open(jenkins.URL)
var jenkins *JenkinsServer
if openOption.Name == "" {
jenkins = getCurrentJenkins()
} else {
jenkins = findJenkinsByName(openOption.Name)
}
if jenkins != nil && jenkins.URL != "" {
url := jenkins.URL
if openOption.Config {
url = fmt.Sprintf("%s/configure", url)
}
open(url)
} else {
log.Fatalf("No URL found with Jenkins %s", jenkins.Name)
log.Fatalf("No URL found with Jenkins %s", openOption.Name)
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册