Skip to content

Commit

Permalink
Adds Zsh completion (finishes issue knative#130) (knative#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien authored and rhuss committed May 27, 2019
1 parent cab4baf commit 4dfcd62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/cmd/kn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.

### SEE ALSO

* [kn completion](kn_completion.md) - Output bash completion code
* [kn completion](kn_completion.md) - Output shell completion code (default Bash)
* [kn revision](kn_revision.md) - Revision command group
* [kn service](kn_service.md) - Service command group
* [kn version](kn_version.md) - Prints the client version
Expand Down
5 changes: 3 additions & 2 deletions docs/cmd/kn_completion.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## kn completion

Output bash completion code
Output shell completion code (default Bash)

### Synopsis

Output bash completion code
Output shell completion code (default Bash)

```
kn completion [flags]
Expand All @@ -14,6 +14,7 @@ kn completion [flags]

```
-h, --help help for completion
--zsh Generates completion code for Zsh shell.
```

### Options inherited from parent commands
Expand Down
22 changes: 16 additions & 6 deletions pkg/kn/commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ import (
"github.com/spf13/cobra"
)

type CompletionFlags struct {
Zsh bool
}

func NewCompletionCommand(p *KnParams) *cobra.Command {
var completionFlags CompletionFlags

completionCmd := &cobra.Command{
Use: "completion",
Short: "Output bash completion code",
Run: completionAction,
Short: "Output shell completion code (default Bash)",
Run: func(cmd *cobra.Command, args []string) {
if completionFlags.Zsh {
cmd.Root().GenZshCompletion(os.Stdout)
} else {
cmd.Root().GenBashCompletion(os.Stdout)
}
},
}
return completionCmd
}

func completionAction(cmd *cobra.Command, args []string) {
cmd.Root().GenBashCompletion(os.Stdout)
completionCmd.Flags().BoolVar(&completionFlags.Zsh, "zsh", false, "Generates completion code for Zsh shell.")
return completionCmd
}

0 comments on commit 4dfcd62

Please sign in to comment.