2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 06:46:34 +00:00

Merge pull request #3925 from hgraeber/add-powershell-completion

Add powershell completion
This commit is contained in:
rawtaz 2022-09-11 01:04:57 +02:00 committed by GitHub
commit d79e61ce5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View File

@ -0,0 +1,6 @@
Enhancement: Provide command completion for powershell
Restic allows generation of completion files for bash, fish and zsh. Now powershell
is supported, too.
https://github.com/restic/restic/pull/3925/files

View File

@ -10,7 +10,7 @@ import (
var cmdGenerate = &cobra.Command{
Use: "generate [flags]",
Short: "Generate manual pages and auto-completion files (bash, fish, zsh)",
Short: "Generate manual pages and auto-completion files (bash, fish, zsh, powershell)",
Long: `
The "generate" command writes automatically generated files (like the man pages
and the auto-completion files for bash, fish and zsh).
@ -25,10 +25,11 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
}
type generateOptions struct {
ManDir string
BashCompletionFile string
FishCompletionFile string
ZSHCompletionFile string
ManDir string
BashCompletionFile string
FishCompletionFile string
ZSHCompletionFile string
PowerShellCompletionFile string
}
var genOpts generateOptions
@ -40,6 +41,7 @@ func init() {
fs.StringVar(&genOpts.BashCompletionFile, "bash-completion", "", "write bash completion `file`")
fs.StringVar(&genOpts.FishCompletionFile, "fish-completion", "", "write fish completion `file`")
fs.StringVar(&genOpts.ZSHCompletionFile, "zsh-completion", "", "write zsh completion `file`")
fs.StringVar(&genOpts.PowerShellCompletionFile, "powershell-completion", "", "write powershell completion `file`")
}
func writeManpages(dir string) error {
@ -75,6 +77,11 @@ func writeZSHCompletion(file string) error {
return cmdRoot.GenZshCompletionFile(file)
}
func writePowerShellCompletion(file string) error {
Verbosef("writing powershell completion file to %v\n", file)
return cmdRoot.GenPowerShellCompletionFile(file)
}
func runGenerate(cmd *cobra.Command, args []string) error {
if genOpts.ManDir != "" {
err := writeManpages(genOpts.ManDir)
@ -104,6 +111,13 @@ func runGenerate(cmd *cobra.Command, args []string) error {
}
}
if genOpts.PowerShellCompletionFile != "" {
err := writePowerShellCompletion(genOpts.PowerShellCompletionFile)
if err != nil {
return err
}
}
var empty generateOptions
if genOpts == empty {
return errors.Fatal("nothing to do, please specify at least one output file/dir")

View File

@ -313,14 +313,14 @@ compiler. Building restic with gccgo may work, but is not supported.
Autocompletion
**************
Restic can write out man pages and bash/fish/zsh compatible autocompletion scripts:
Restic can write out man pages and bash/fish/zsh/powershell compatible autocompletion scripts:
.. code-block:: console
$ ./restic generate --help
The "generate" command writes automatically generated files (like the man pages
and the auto-completion files for bash, fish and zsh).
and the auto-completion files for bash, fish, zsh and powershell).
Usage:
restic generate [flags] [command]
@ -330,6 +330,7 @@ Restic can write out man pages and bash/fish/zsh compatible autocompletion scrip
--fish-completion file write fish completion file
-h, --help help for generate
--man directory write man pages to directory
--powershell-completion write powershell completion file
--zsh-completion file write zsh completion file
Example for using sudo to write a bash completion script directly to the system-wide location:

View File

@ -290,6 +290,7 @@ func generateFiles() {
run("./restic-generate.temp", "generate",
"--man", "doc/man",
"--zsh-completion", "doc/zsh-completion.zsh",
"--powershell-completion", "doc/powershell-completion.ps1",
"--fish-completion", "doc/fish-completion.fish",
"--bash-completion", "doc/bash-completion.sh")
rm("restic-generate.temp")