Skip to content

Commit

Permalink
Rebased and addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathi-tenneti committed Mar 19, 2020
1 parent 0b6c9b7 commit 232c524
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"os"

"github.com/spf13/cobra"
)

func newCompletionCmd() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generators for shell completions",
}
completionCmd.AddCommand(newZshCmd())
completionCmd.AddCommand(newBashCmd())
return completionCmd
}

func newBashCmd() *cobra.Command {
return &cobra.Command{
Use: "bash",
Short: "Generate bash completions",
RunE: func(cmd *cobra.Command, cmdArgs []string) error {
return cmd.Root().GenBashCompletion(os.Stdout)
},
}
}

func newZshCmd() *cobra.Command {
return &cobra.Command{
Use: "zsh",
Short: "Generate zsh completions",
RunE: func(cmd *cobra.Command, cmdArgs []string) error {
return cmd.Root().GenZshCompletion(os.Stdout)
},
}
}
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func buildCmdTree() *cobra.Command {
// kubebuilder version
rootCmd.AddCommand(version.NewVersionCmd())

// kubebuilder completion
rootCmd.AddCommand(newCompletionCmd())

return rootCmd
}

Expand Down

0 comments on commit 232c524

Please sign in to comment.