Skip to content

Commit

Permalink
Add support to define a suite of plugins (#124)
Browse files Browse the repository at this point in the history
* Add support to define a suite of plugins

* Add test for findSuiteByName
  • Loading branch information
LinuxSuRen committed Aug 28, 2019
1 parent e5f8e59 commit 92ab7a6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
18 changes: 18 additions & 0 deletions app/cmd/config.go
Expand Up @@ -55,10 +55,18 @@ type PreHook struct {
Command string `yaml:"cmd"`
}

// PluginSuite define a suite of plugins
type PluginSuite struct {
Name string `yaml:"name"`
Plugins []string `yaml:"plugins"`
Description string `yaml:"description"`
}

type Config struct {
Current string `yaml:"current"`
JenkinsServers []JenkinsServer `yaml:"jenkins_servers"`
PreHooks []PreHook `yaml:"preHooks"`
PluginSuites []PluginSuite `yaml:"pluginSuites"`
}

func setCurrentJenkins(name string) {
Expand Down Expand Up @@ -113,6 +121,16 @@ func findJenkinsByName(name string) (jenkinsServer *JenkinsServer) {
return
}

func findSuiteByName(name string) (suite *PluginSuite) {
for _, cfg := range config.PluginSuites {
if cfg.Name == name {
suite = &cfg
break
}
}
return
}

func loadDefaultConfig() (err error) {
userHome := userHomeDir()
configPath := fmt.Sprintf("%s/.jenkins-cli.yaml", userHome)
Expand Down
14 changes: 14 additions & 0 deletions app/cmd/config_test.go
Expand Up @@ -51,5 +51,19 @@ var _ = Describe("Table util test", func() {
current = getCurrentJenkins()
Expect(current).To(Equal(&config.JenkinsServers[0]))
})

It("findSuiteByName", func() {
config = &Config{}
suite := findSuiteByName("fake")
Expect(suite).To(BeNil())

pluginName := "plugin-one"
config.PluginSuites = []PluginSuite{PluginSuite{
Name: pluginName,
}}
suite = findSuiteByName(pluginName)
Expect(suite).NotTo(BeNil())
Expect(suite.Name).To(Equal(pluginName))
})
})
})
1 change: 1 addition & 0 deletions app/cmd/plugin.go
Expand Up @@ -6,6 +6,7 @@ import (

// PluginOptions contains the command line options
type PluginOptions struct {
Suite string
}

var pluginOpt PluginOptions
Expand Down
9 changes: 9 additions & 0 deletions app/cmd/plugin_install.go
Expand Up @@ -11,6 +11,7 @@ import (

func init() {
pluginCmd.AddCommand(pluginInstallCmd)
pluginInstallCmd.Flags().StringVarP(&pluginOpt.Suite, "suite", "", "", "Suite of plugins")
}

var pluginInstallCmd = &cobra.Command{
Expand All @@ -28,6 +29,14 @@ var pluginInstallCmd = &cobra.Command{
plugins := make([]string, len(args))
plugins = append(plugins, args...)

if pluginOpt.Suite != "" {
if suite := findSuiteByName(pluginOpt.Suite); suite != nil {
plugins = append(plugins, suite.Plugins...)
} else {
log.Fatal("Cannot found suite", pluginOpt.Suite)
}
}

if len(plugins) == 0 {
for {
var keyword string
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Expand Up @@ -2,15 +2,13 @@ module github.com/jenkins-zh/jenkins-cli

go 1.12

replace github.com/AlecAivazis/survey v1.8.5 => gopkg.in/AlecAivazis/survey.v1 v1.8.5

require (
github.com/AlecAivazis/survey/v2 v2.0.1
github.com/Pallinder/go-randomdata v1.2.0
github.com/atotto/clipboard v0.1.2
github.com/golang/mock v1.3.1
github.com/gosuri/uilive v0.0.3 // indirect
github.com/gosuri/uiprogress v0.0.1
github.com/linuxsuren/jenkins-cli v0.0.17
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/onsi/ginkgo v1.9.0
github.com/onsi/gomega v1.6.0
Expand Down
10 changes: 1 addition & 9 deletions go.sum
Expand Up @@ -12,9 +12,9 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -30,16 +30,11 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/linuxsuren/jenkins-cli v0.0.17 h1:1wmK+ryKVUXjcoz6mm1C7oarEvkV3zgd0yO7s1zhHvY=
github.com/linuxsuren/jenkins-cli v0.0.17/go.mod h1:DghQ0y57x79eo+GJkcUqzAggit/1DMIbhMmlMTfbxGM=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
Expand Down Expand Up @@ -71,7 +66,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 h1:8dUaAV7K4uHsF56JQWkprecIQKdPHtR9jCHF5nB8uzc=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -95,8 +89,6 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
gopkg.in/AlecAivazis/survey.v1 v1.8.5 h1:QoEEmn/d5BbuPIL2qvXwzJdttFFhRQFkaq+tEKb7SMI=
gopkg.in/AlecAivazis/survey.v1 v1.8.5/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand Down

0 comments on commit 92ab7a6

Please sign in to comment.