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

Allow uses to open multi-jenkins

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