mirror of https://github.com/knative/client.git
parent
f77c034c4a
commit
462973c51f
|
|
@ -20,26 +20,13 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type CompletionFlags struct {
|
||||
Zsh bool
|
||||
}
|
||||
|
||||
func NewCompletionCommand(p *KnParams) *cobra.Command {
|
||||
var completionFlags CompletionFlags
|
||||
|
||||
completionCmd := &cobra.Command{
|
||||
return &cobra.Command{
|
||||
Use: "completion",
|
||||
Short: "Output shell completion code (default Bash)",
|
||||
Hidden: true, // Don't show this in help listing.
|
||||
Short: "Output shell completion code (Bash)",
|
||||
Hidden: true, // Don't show this in help listing
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if completionFlags.Zsh {
|
||||
cmd.Root().GenZshCompletion(os.Stdout)
|
||||
} else {
|
||||
cmd.Root().GenBashCompletion(os.Stdout)
|
||||
}
|
||||
cmd.Root().GenBashCompletion(os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
completionCmd.Flags().BoolVar(&completionFlags.Zsh, "zsh", false, "Generates completion code for Zsh shell.")
|
||||
return completionCmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func TestCompletion(t *testing.T) {
|
|||
t.Run("creates a CompletionCommand", func(t *testing.T) {
|
||||
setup()
|
||||
assert.Equal(t, completionCmd.Use, "completion")
|
||||
assert.Equal(t, completionCmd.Short, "Output shell completion code (default Bash)")
|
||||
assert.Equal(t, completionCmd.Short, "Output shell completion code (Bash)")
|
||||
assert.Assert(t, completionCmd.RunE == nil)
|
||||
})
|
||||
|
||||
|
|
@ -50,13 +50,4 @@ func TestCompletion(t *testing.T) {
|
|||
completionCmd.Run(fakeRootCmd, []string{})
|
||||
assert.Assert(t, ReadStdout(t) != "")
|
||||
})
|
||||
|
||||
t.Run("returns completion code for ZSH", func(t *testing.T) {
|
||||
setup()
|
||||
CaptureStdout(t)
|
||||
defer ReleaseStdout(t)
|
||||
|
||||
completionCmd.Run(fakeRootCmd, []string{"--zsh"})
|
||||
assert.Assert(t, ReadStdout(t) != "")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue