feat(completion): Add support for powershell completion (#1408)

This commit is to add support for powershell completion script.

Note: PowerShell v5.0+ is required
This commit is contained in:
Tam Mach 2020-10-11 04:11:00 +11:00 committed by GitHub
parent 70cd9ba63b
commit 073e590a63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,13 @@ func (e *Executor) initCompletion() {
RunE: e.executeFishCompletion, RunE: e.executeFishCompletion,
} }
completionCmd.AddCommand(fishCmd) completionCmd.AddCommand(fishCmd)
powerShell := &cobra.Command{
Use: "powershell",
Short: "Output powershell completion script",
RunE: e.executePowerShellCompletion,
}
completionCmd.AddCommand(powerShell)
} }
func (e *Executor) executeBashCompletion(cmd *cobra.Command, args []string) error { func (e *Executor) executeBashCompletion(cmd *cobra.Command, args []string) error {
@ -67,3 +74,12 @@ func (e *Executor) executeFishCompletion(cmd *cobra.Command, args []string) erro
return nil return nil
} }
func (e *Executor) executePowerShellCompletion(cmd *cobra.Command, args []string) error {
err := cmd.Root().GenPowerShellCompletion(os.Stdout)
if err != nil {
return errors.Wrap(err, "generate powershell completion")
}
return nil
}