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