-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from ozzieba/bash_completion
Add shell completion
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package completion | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/kubicorn/kubicorn/pkg/logger" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Command will create the `completion` commands | ||
func Command(rootCmd *cobra.Command) *cobra.Command { | ||
var bashCompletionCmd = &cobra.Command{ | ||
Use: "bash", | ||
Short: "Generates bash completion scripts", | ||
Long: `To load completion run | ||
. <(eksctl completion bash) | ||
To configure your bash shell to load completions for each session add to your bashrc | ||
# ~/.bashrc or ~/.profile | ||
. <(eksctl completion bash) | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
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/ | ||
eksctl completion zsh > ~/.zsh/completion/_eksctl | ||
and put the following in ~/.zshrc: | ||
fpath=($fpath ~/.zsh/completion) | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rootCmd.GenZshCompletion(os.Stdout) | ||
}, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "completion", | ||
Short: "Generates shell completion scripts", | ||
Run: func(c *cobra.Command, _ []string) { | ||
if err := c.Help(); err != nil { | ||
logger.Debug("ignoring error %q", err.Error()) | ||
} | ||
}, | ||
} | ||
|
||
cmd.AddCommand(bashCompletionCmd) | ||
cmd.AddCommand(zshCompletionCmd) | ||
|
||
return cmd | ||
} |