• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 21458351963

28 Jan 2026 10:45PM UTC coverage: 73.667%. Remained the same
21458351963

push

github

web-flow
Merge pull request #5408 from vitorfloriano/feat-improve-completion

✨ feat(cli): add short description to tab completion in bash

0 of 1 new or added line in 1 file covered. (0.0%)

6630 of 9000 relevant lines covered (73.67%)

40.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.06
/pkg/cli/completion.go
1
/*
2
Copyright 2020 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package cli
18

19
import (
20
        "fmt"
21
        "os"
22

23
        "github.com/spf13/cobra"
24
)
25

26
func (c CLI) newBashCmd() *cobra.Command {
2✔
27
        return &cobra.Command{
2✔
28
                Use:   "bash",
2✔
29
                Short: "Load bash completions",
2✔
30
                Example: fmt.Sprintf(`# To load completion for this session, execute:
2✔
31
$ source <(%[1]s completion bash)
2✔
32

2✔
33
# To load completions for each session, execute once:
2✔
34
Linux:
2✔
35
  $ %[1]s completion bash > /etc/bash_completion.d/%[1]s
2✔
36
MacOS:
2✔
37
  $ %[1]s completion bash > /usr/local/etc/bash_completion.d/%[1]s
2✔
38
`, c.commandName),
2✔
39
                RunE: func(cmd *cobra.Command, _ []string) error {
2✔
NEW
40
                        return cmd.Root().GenBashCompletionV2(os.Stdout, true)
×
41
                },
×
42
        }
43
}
44

45
func (c CLI) newZshCmd() *cobra.Command {
2✔
46
        return &cobra.Command{
2✔
47
                Use:   "zsh",
2✔
48
                Short: "Load zsh completions",
2✔
49
                Example: fmt.Sprintf(`# If shell completion is not already enabled in your environment you will need
2✔
50
# to enable it. You can execute the following once:
2✔
51
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
2✔
52

2✔
53
# To load completions for each session, execute once:
2✔
54
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
2✔
55

2✔
56
# You will need to start a new shell for this setup to take effect.
2✔
57
`, c.commandName),
2✔
58
                RunE: func(cmd *cobra.Command, _ []string) error {
2✔
59
                        return cmd.Root().GenZshCompletion(os.Stdout)
×
60
                },
×
61
        }
62
}
63

64
func (c CLI) newFishCmd() *cobra.Command {
2✔
65
        return &cobra.Command{
2✔
66
                Use:   "fish",
2✔
67
                Short: "Load fish completions",
2✔
68
                Example: fmt.Sprintf(`# To load completion for this session, execute:
2✔
69
$ %[1]s completion fish | source
2✔
70

2✔
71
# To load completions for each session, execute once:
2✔
72
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
2✔
73
`, c.commandName),
2✔
74
                RunE: func(cmd *cobra.Command, _ []string) error {
2✔
75
                        return cmd.Root().GenFishCompletion(os.Stdout, true)
×
76
                },
×
77
        }
78
}
79

80
func (CLI) newPowerShellCmd() *cobra.Command {
2✔
81
        return &cobra.Command{
2✔
82
                Use:   "powershell",
2✔
83
                Short: "Load powershell completions",
2✔
84
                RunE: func(cmd *cobra.Command, _ []string) error {
2✔
85
                        return cmd.Root().GenPowerShellCompletion(os.Stdout)
×
86
                },
×
87
        }
88
}
89

90
func (c CLI) newCompletionCmd() *cobra.Command {
1✔
91
        cmd := &cobra.Command{
1✔
92
                Use:   "completion",
1✔
93
                Short: "Load completions for the specified shell",
1✔
94
                Long: fmt.Sprintf(`Output shell completion code for the specified shell.
1✔
95
The shell code must be evaluated to provide interactive completion of %[1]s commands.
1✔
96
Detailed instructions on how to do this for each shell are provided in their own commands.
1✔
97
`, c.commandName),
1✔
98
        }
1✔
99
        cmd.AddCommand(c.newBashCmd())
1✔
100
        cmd.AddCommand(c.newZshCmd())
1✔
101
        cmd.AddCommand(c.newFishCmd())
1✔
102
        cmd.AddCommand(c.newPowerShellCmd())
1✔
103
        return cmd
1✔
104
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc