Skip to content

Commit

Permalink
Support autocompletion of the version in k3d installation (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed May 18, 2022
1 parent 1393197 commit f405bf0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ require (
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-github/v29 v29.0.3
github.com/huandu/xstrings v1.3.2 // indirect
github.com/jenkins-x/go-scm v1.11.1
github.com/linuxsuren/cobra-extension v0.0.13
github.com/linuxsuren/cobra-extension v0.0.15
github.com/linuxsuren/go-cli-alias v0.0.10
github.com/linuxsuren/http-downloader v0.0.35
github.com/mitchellh/copystructure v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9
github.com/linuxsuren/cobra-extension v0.0.6/go.mod h1:qcEJv7BbL0UpK6MbrTESP/nKf1+z1wQdMAnE1NBl3QQ=
github.com/linuxsuren/cobra-extension v0.0.10/go.mod h1:nDsXgvm0lSWVV+byAEfwhIGFDoIp0Sq9wkfNUDBp5do=
github.com/linuxsuren/cobra-extension v0.0.11/go.mod h1:gn69Dtq72JCGZbjW46c14MoE0z/BtDAQWV9Jvr9KczY=
github.com/linuxsuren/cobra-extension v0.0.13 h1:nqqvZMeyfhxSHXeCjejg4yR9kRFP+0R79R8lZwmpevs=
github.com/linuxsuren/cobra-extension v0.0.13/go.mod h1:gn69Dtq72JCGZbjW46c14MoE0z/BtDAQWV9Jvr9KczY=
github.com/linuxsuren/cobra-extension v0.0.15 h1:uEsn4U+W3XBCFuhyHdkzbVobDR5DD/qsyZZsSZ5H7YU=
github.com/linuxsuren/cobra-extension v0.0.15/go.mod h1:gn69Dtq72JCGZbjW46c14MoE0z/BtDAQWV9Jvr9KczY=
github.com/linuxsuren/go-cli-alias v0.0.10 h1:qzaz9RiTVKIWryxw3Hx0q//wjt+VIP+BElgRlSWrDhU=
github.com/linuxsuren/go-cli-alias v0.0.10/go.mod h1:g+k4hlbE/lilrEq/5emhMznb9my/lOXSH++/mPli6gw=
github.com/linuxsuren/http-downloader v0.0.2-0.20201207132639-19888a6beaec/go.mod h1:zRZY9FCDBuYNDxbI2Ny5suasZsMk7J6q9ecQ3V3PIqI=
Expand Down
18 changes: 18 additions & 0 deletions kubectl-plugin/install/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bytes"
"fmt"
"github.com/Masterminds/semver"
"github.com/google/go-github/v29/github"
"github.com/kubesphere-sigs/ks/kubectl-plugin/common"
"github.com/kubesphere-sigs/ks/kubectl-plugin/types"
gh "github.com/linuxsuren/cobra-extension/github"
"github.com/linuxsuren/http-downloader/pkg/installer"
"github.com/spf13/cobra"
"io/ioutil"
Expand Down Expand Up @@ -64,6 +66,22 @@ You can get more details from https://github.com/rancher/k3d/`,
"rancher/k3s:v1.21.4-k3s1"))
_ = cmd.RegisterFlagCompletionFunc("components", common.PluginAbleComponentsCompletion())
_ = cmd.RegisterFlagCompletionFunc("nightly", common.ArrayCompletion("latest"))
_ = cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return getKubeSphereVersionList(), cobra.ShellCompDirectiveNoFileComp
})
return
}

func getKubeSphereVersionList() (tags []string) {
ghClient := &gh.ReleaseClient{
Client: github.NewClient(nil),
}

if tagList, err := ghClient.GetTagList("kubesphere", "kubesphere", 6); err == nil && tagList != nil {
for i := range tagList {
tags = append(tags, tagList[i].Name)
}
}
return
}

Expand Down

0 comments on commit f405bf0

Please sign in to comment.