Skip to content

Commit 1dd6d85

Browse files
Merge pull request #8725 from jenkins-x/completion
feat: cli completion
2 parents d6d2b18 + e7399f7 commit 1dd6d85

File tree

6 files changed

+359
-201
lines changed

6 files changed

+359
-201
lines changed

Diff for: .goreleaser.yml

+15-28
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,75 @@ env:
66
before:
77
hooks:
88
- go mod download
9-
109
builds:
1110
- id: jx
1211
# Path to main.go file or main package.
1312
# Default is `.`.
1413
main: ./cmd/main.go
15-
1614
# Binary name.
1715
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
1816
# Default is the name of the project directory.
1917
binary: jx
20-
2118
# Custom ldflags templates.
2219
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
2320
ldflags:
2421
- -X "{{.Env.ROOTPACKAGE}}/pkg/cmd/version.Version={{.Env.VERSION}}" -X "{{.Env.ROOTPACKAGE}}/pkg/cmd/version.Revision={{.Env.REV}}" -X "{{.Env.ROOTPACKAGE}}/pkg/cmd/version.Branch={{.Env.BRANCH}}" -X "{{.Env.ROOTPACKAGE}}/pkg/cmd/version.BuildDate={{.Env.BUILDDATE}}" -X "{{.Env.ROOTPACKAGE}}/pkg/cmd/version.GoVersion={{.Env.GOVERSION}}"
25-
2622
# GOOS list to build for.
2723
# For more info refer to: https://golang.org/doc/install/source#environment
2824
# Defaults are darwin and linux.
2925
goos:
3026
- windows
3127
- darwin
3228
- linux
33-
3429
# GOARCH to build for.
3530
# For more info refer to: https://golang.org/doc/install/source#environment
3631
# Defaults are 386 and amd64.
3732
goarch:
3833
- amd64
39-
- arm
4034
- arm64
41-
35+
ignore:
36+
- goos: windows
37+
goarch: arm64
4238
archives:
4339
- name_template: "jx-{{ .Os }}-{{ .Arch }}"
4440
format_overrides:
4541
- goos: windows
4642
format: zip
47-
4843
checksum:
4944
# You can change the name of the checksums file.
5045
# Default is `jx_{{ .Version }}_checksums.txt`.
5146
name_template: "jx-checksums.txt"
52-
5347
# Algorithm to be used.
5448
# Accepted options are sha256, sha512, sha1, crc32, md5, sha224 and sha384.
5549
# Default is sha256.
5650
algorithm: sha256
57-
5851
changelog:
5952
# set it to true if you wish to skip the changelog generation
6053
disable: true
61-
6254
release:
6355
# If set to true, will not auto-publish the release.
6456
# Default is false.
6557
draft: false
66-
6758
# If set to auto, will mark the release as not ready for production
6859
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
6960
# If set to true, will mark the release as not ready for production.
7061
# Default is false.
7162
prerelease: true
72-
7363
# You can change the name of the GitHub release.
7464
# Default is `{{.Tag}}`
7565
name_template: "{{.Env.VERSION}}"
76-
7766
sboms:
7867
- artifacts: archive
79-
80-
8168
signs:
82-
- cmd: cosign
83-
env:
84-
- COSIGN_EXPERIMENTAL=1
85-
certificate: '${artifact}.pem'
86-
output: true
87-
artifacts: all
88-
args:
89-
- sign-blob
90-
- --yes=true
91-
- '--output-certificate=${certificate}'
92-
- '--output-signature=${signature}'
93-
- '${artifact}'
69+
- cmd: cosign
70+
env:
71+
- COSIGN_EXPERIMENTAL=1
72+
certificate: '${artifact}.pem'
73+
output: true
74+
artifacts: all
75+
args:
76+
- sign-blob
77+
- --yes=true
78+
- '--output-certificate=${certificate}'
79+
- '--output-signature=${signature}'
80+
- '${artifact}'

Diff for: go.mod

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ require (
99
github.com/jenkins-x/jx-logging/v3 v3.0.17
1010
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1111
github.com/rhysd/go-github-selfupdate v1.2.3
12-
github.com/spf13/cobra v1.8.0
12+
github.com/spf13/cobra v1.8.1
1313
github.com/spf13/pflag v1.0.5
1414
github.com/stretchr/testify v1.9.0
15-
k8s.io/api v0.31.1
16-
k8s.io/apimachinery v0.31.1
17-
k8s.io/client-go v0.31.1
18-
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3
15+
k8s.io/api v0.31.2
16+
k8s.io/apimachinery v0.31.2
17+
k8s.io/client-go v0.31.2
18+
sigs.k8s.io/kustomize/kyaml v0.17.1
1919

2020
)
2121

@@ -24,6 +24,7 @@ require (
2424
github.com/AlecAivazis/survey/v2 v2.3.4 // indirect
2525
github.com/MakeNowJust/heredoc v1.0.0 // indirect
2626
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
27+
github.com/creack/pty v1.1.18 // indirect
2728
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2829
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
2930
github.com/fatih/color v1.15.0 // indirect

Diff for: go.sum

+13-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEe
1414
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
1515
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
1616
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
17-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
17+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1818
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
19-
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
2019
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
20+
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
21+
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
2122
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2223
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2324
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -149,8 +150,8 @@ github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNl
149150
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
150151
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
151152
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
152-
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
153-
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
153+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
154+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
154155
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
155156
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
156157
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -256,12 +257,12 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
256257
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
257258
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
258259
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
259-
k8s.io/api v0.31.1 h1:Xe1hX/fPW3PXYYv8BlozYqw63ytA92snr96zMW9gWTU=
260-
k8s.io/api v0.31.1/go.mod h1:sbN1g6eY6XVLeqNsZGLnI5FwVseTrZX7Fv3O26rhAaI=
261-
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
262-
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
263-
k8s.io/client-go v0.31.1 h1:f0ugtWSbWpxHR7sjVpQwuvw9a3ZKLXX0u0itkFXufb0=
264-
k8s.io/client-go v0.31.1/go.mod h1:sKI8871MJN2OyeqRlmA4W4KM9KBdBUpDLu/43eGemCg=
260+
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
261+
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
262+
k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw=
263+
k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
264+
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
265+
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
265266
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
266267
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
267268
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 h1:MErs8YA0abvOqJ8gIupA1Tz6PKXYUw34XsGlA7uSL1k=
@@ -270,8 +271,8 @@ k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 h1:MDF6h2H/h4tbzmtIKTuctcwZmY0tY
270271
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
271272
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
272273
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
273-
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 h1:W6cLQc5pnqM7vh3b7HvGNfXrJ/xL6BDMS0v1V/HHg5U=
274-
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3/go.mod h1:JWP1Fj0VWGHyw3YUPjXSQnRnrwezrZSrApfX5S0nIag=
274+
sigs.k8s.io/kustomize/kyaml v0.17.1 h1:TnxYQxFXzbmNG6gOINgGWQt09GghzgTP6mIurOgrLCQ=
275+
sigs.k8s.io/kustomize/kyaml v0.17.1/go.mod h1:9V0mCjIEYjlXuCdYsSXvyoy2BTsLESH7TlGV81S282U=
275276
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
276277
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
277278
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=

Diff for: pkg/cmd/namespace/namespace.go

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"sort"
8+
"strings"
89

910
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper"
1011
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/templates"
@@ -77,9 +78,28 @@ func NewCmdNamespace() (*cobra.Command, *Options) {
7778
cmd := &cobra.Command{
7879
Use: "namespace",
7980
Aliases: []string{"ns"},
81+
Args: cobra.MaximumNArgs(1),
8082
Short: "View or change the current namespace context in the current Kubernetes cluster",
8183
Long: cmdLong,
8284
Example: cmdExample,
85+
ValidArgsFunction: func(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
86+
client, _, err := kube.LazyCreateKubeClientAndNamespace(o.KubeClient, "")
87+
if err != nil {
88+
return nil, cobra.ShellCompDirectiveError
89+
}
90+
names, err := getNamespaceNames(client)
91+
92+
if err != nil {
93+
return nil, cobra.ShellCompDirectiveError
94+
}
95+
var contextNames []string
96+
for _, v := range names {
97+
if strings.HasPrefix(v, toComplete) {
98+
contextNames = append(contextNames, v)
99+
}
100+
}
101+
return contextNames, cobra.ShellCompDirectiveNoFileComp
102+
},
83103
Run: func(_ *cobra.Command, args []string) {
84104
o.Args = args
85105
err := o.Run()

0 commit comments

Comments
 (0)