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
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/streamnative/pulsarctl/pkg/cmdutils"
"github.com/streamnative/pulsarctl/pkg/ctl/cluster"
"github.com/streamnative/pulsarctl/pkg/ctl/completion"
"os"
)

Expand Down Expand Up @@ -59,6 +60,7 @@ func init() {

func addCommands(flagGrouping *cmdutils.FlagGrouping) {
rootCmd.AddCommand(cluster.Command(flagGrouping))
rootCmd.AddCommand(completion.Command(rootCmd))
}

func main() {
Expand Down
62 changes: 62 additions & 0 deletions pkg/ctl/completion/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package completion

import (
"github.com/kris-nova/logger"
"github.com/spf13/cobra"
"os"
)

func Command(rootCmd *cobra.Command) *cobra.Command {
var bashCompletionCmd = &cobra.Command{
Use: "bash",
Short: "Generates bash completion scripts",
Long: `To load completion run

. <(pulsarctl completion bash)

To configure your bash shell to load completions for each session add to your bashrc

# ~/.bashrc or ~/.profile
. <(pulsarctl completion bash)

If you are stuck on Bash 3 (macOS) use

source /dev/stdin <<<"$(pulsarctl completion bash)"
`,
RunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.GenBashCompletion(os.Stdout)
},
}

var zshCompletionCmd = &cobra.Command{
Use: "zsh",
Short: "Generates zsh completion scripts",
Long: `To configure your zsh shell, run:

mkdir -p ~/.zsh/completion/
pulsarctl completion zsh > ~/.zsh/completion/_pulsarctl

and put the following in ~/.zshrc:

fpath=($fpath ~/.zsh/completion)
`,
RunE: func(cmd *cobra.Command, args []string) error {
return rootCmd.GenZshCompletion(os.Stdout)
},
}

cmd := &cobra.Command{
Use: "completion",
Short: "Generates shell completion scripts",
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

cmd.AddCommand(bashCompletionCmd)
cmd.AddCommand(zshCompletionCmd)

return cmd
}