Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ module github.com/linuxsuren/go-cli-plugin
go 1.15

require (
github.com/golang/mock v1.4.4
github.com/gosuri/uilive v0.0.3 // indirect
github.com/gosuri/uiprogress v0.0.1
github.com/linuxsuren/cobra-extension v0.0.1 // indirect
github.com/linuxsuren/cobra-extension v0.0.1
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.6.1 // indirect
Expand Down
15 changes: 8 additions & 7 deletions pkg/cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

// NewConfigPluginFetchCmd create a command for fetching plugin metadata
func NewConfigPluginFetchCmd(pluginOrg, pluginRepo string) (cmd *cobra.Command) {
pluginFetchCmd := jcliPluginFetchCmd{
PluginOrg: pluginOrg,
PluginRepo: pluginRepo,
pluginFetchCmd := &jcliPluginFetchCmd{
PluginOrg: pluginOrg,
PluginRepoName: pluginRepo,
}

cmd = &cobra.Command{
Expand All @@ -34,7 +34,7 @@ but you can change it by giving a command parameter.`, pluginFetchCmd.PluginOrg,
// add flags
flags := cmd.Flags()
flags.StringVarP(&pluginFetchCmd.PluginRepo, "plugin-repo", "",
fmt.Sprintf("https://github.com/%s/%s", pluginFetchCmd.PluginOrg, pluginFetchCmd.PluginRepo),
fmt.Sprintf("https://github.com/%s/%s", pluginFetchCmd.PluginOrg, pluginFetchCmd.PluginRepoName),
"The plugin git repository URL")
flags.BoolVarP(&pluginFetchCmd.Reset, "reset", "", true,
"If you want to reset the git local repo when pulling it")
Expand All @@ -56,11 +56,12 @@ func (c *jcliPluginFetchCmd) Run(cmd *cobra.Command, args []string) (err error)
return
}

pluginRepo := fmt.Sprintf("%s/.%s/plugins-repo", userHome, c.PluginRepo)
pluginRepoCache := fmt.Sprintf("%s/.jenkins-cli/plugins-repo", userHome)
c.output = cmd.OutOrStdout()

cmd.Printf("start to fetch metadata from '%s', cache to '%s'\n", c.PluginRepo, pluginRepoCache)
var r *git.Repository
if r, err = git.PlainOpen(pluginRepo); err == nil {
if r, err = git.PlainOpen(pluginRepoCache); err == nil {
var w *git.Worktree
if w, err = r.Worktree(); err != nil {
return
Expand All @@ -80,7 +81,7 @@ func (c *jcliPluginFetchCmd) Run(cmd *cobra.Command, args []string) (err error)
}
} else {
cloneOptions := c.getCloneOptions()
_, err = git.PlainClone(pluginRepo, false, cloneOptions)
_, err = git.PlainClone(pluginRepoCache, false, cloneOptions)
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *jcliPluginInstallCmd) Run(cmd *cobra.Command, args []string) (err error
}

var data []byte
pluginsMetadataFile := fmt.Sprintf("%s/.%s/plugins-repo/%s.yaml", c.PluginRepo, userHome, name)
pluginsMetadataFile := fmt.Sprintf("%s/.%s/plugins-repo/%s.yaml", userHome, c.PluginRepo, name)
if data, err = ioutil.ReadFile(pluginsMetadataFile); err == nil {
plugin := pkg.Plugin{}
if err = yaml.Unmarshal(data, &plugin); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// NewConfigPluginListCmd create a command for list all jcli plugins
func NewConfigPluginListCmd() (cmd *cobra.Command) {
configPluginListCmd := configPluginListCmd{}
configPluginListCmd := &configPluginListCmd{}

cmd = &cobra.Command{
Use: "list",
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type (
Password string
SSHKeyFile string

output io.Writer
PluginOrg string
output io.Writer
PluginOrg string
PluginRepoName string
}

jcliPluginInstallCmd struct {
Expand Down
6 changes: 5 additions & 1 deletion pkg/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func FindPlugins() (plugins []Plugin, err error) {

plugins = make([]Plugin, 0)
pluginsDir := fmt.Sprintf("%s/.jenkins-cli/plugins-repo/*.yaml", userHome)
if files, err := filepath.Glob(pluginsDir); err == nil {
//fmt.Println("start to parse plugin file from dir", pluginsDir)
var files []string
if files, err = filepath.Glob(pluginsDir); err == nil {
for _, metaFile := range files {
var data []byte
plugin := Plugin{}
Expand All @@ -54,6 +56,8 @@ func FindPlugins() (plugins []Plugin, err error) {
}
plugins = append(plugins, plugin)
}
} else {
fmt.Println("failed to parse file", metaFile)
}
}
}
Expand Down