mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
commands: Add PowerShell completion support
Revert "Refactor: Remove powershell support" with fixes
Thanks to Ben Mezger (@benmezger) for the original code.
See #8122
This reverts commit a7c515e1b5
.
This commit is contained in:
parent
7118f89cf3
commit
5f621df257
1 changed files with 9 additions and 5 deletions
|
@ -25,8 +25,10 @@ var _ cmder = (*genautocompleteCmd)(nil)
|
||||||
|
|
||||||
type genautocompleteCmd struct {
|
type genautocompleteCmd struct {
|
||||||
autocompleteTarget string
|
autocompleteTarget string
|
||||||
// bash, zsh or fish
|
|
||||||
|
// bash, zsh, fish or powershell
|
||||||
autocompleteType string
|
autocompleteType string
|
||||||
|
|
||||||
*baseCmd
|
*baseCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ for convenience, and the command may need superuser rights, e.g.:
|
||||||
Add ` + "`--completionfile=/path/to/file`" + ` flag to set alternative
|
Add ` + "`--completionfile=/path/to/file`" + ` flag to set alternative
|
||||||
file-path and name.
|
file-path and name.
|
||||||
|
|
||||||
Add ` + "`--type={bash, zsh or fish}`" + ` flag to set alternative
|
Add ` + "`--type={bash, zsh, fish or powershell}`" + ` flag to set alternative
|
||||||
shell type.
|
shell type.
|
||||||
|
|
||||||
Logout and in again to reload the completion scripts,
|
Logout and in again to reload the completion scripts,
|
||||||
|
@ -65,12 +67,14 @@ or just source them in directly:
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cc.autocompleteType {
|
switch cc.autocompleteType {
|
||||||
case "zsh":
|
|
||||||
err = cmd.Root().GenZshCompletion(target)
|
|
||||||
case "bash":
|
case "bash":
|
||||||
err = cmd.Root().GenBashCompletion(target)
|
err = cmd.Root().GenBashCompletion(target)
|
||||||
|
case "zsh":
|
||||||
|
err = cmd.Root().GenZshCompletion(target)
|
||||||
case "fish":
|
case "fish":
|
||||||
err = cmd.Root().GenFishCompletion(target, true)
|
err = cmd.Root().GenFishCompletion(target, true)
|
||||||
|
case "powershell":
|
||||||
|
err = cmd.Root().GenPowerShellCompletion(target)
|
||||||
default:
|
default:
|
||||||
return newUserError("Unsupported completion type")
|
return newUserError("Unsupported completion type")
|
||||||
}
|
}
|
||||||
|
@ -87,7 +91,7 @@ or just source them in directly:
|
||||||
})
|
})
|
||||||
|
|
||||||
cc.cmd.PersistentFlags().StringVarP(&cc.autocompleteTarget, "completionfile", "f", "", "autocompletion file, defaults to stdout")
|
cc.cmd.PersistentFlags().StringVarP(&cc.autocompleteTarget, "completionfile", "f", "", "autocompletion file, defaults to stdout")
|
||||||
cc.cmd.PersistentFlags().StringVarP(&cc.autocompleteType, "type", "t", "bash", "autocompletion type (zsh, bash or fish)")
|
cc.cmd.PersistentFlags().StringVarP(&cc.autocompleteType, "type", "t", "bash", "autocompletion type (bash, zsh, fish, or powershell)")
|
||||||
|
|
||||||
return cc
|
return cc
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue