Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PowerShell code completion #16232

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions cmd/minikube/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/minikube/pkg/minikube/reason"
)

const longDescription = `Outputs minikube shell completion for the given shell (bash, zsh or fish)
const longDescription = `Outputs minikube shell completion for the given shell (bash, zsh, fish or powershell)

This depends on the bash-completion binary. Example installation instructions:
OS X:
Expand All @@ -47,6 +47,16 @@ const longDescription = `Outputs minikube shell completion for the given shell (

Additionally, you may want to output the completion to a file and source in your .bashrc

Windows:
## Save completion code to a script and execute in the profile
PS> minikube completion powershell > $HOME\.minikube-completion.ps1
PS> Add-Content $PROFILE '. $HOME\.minikube-completion.ps1'

## Execute completion code in the profile
PS> Add-Content $PROFILE 'if (Get-Command minikube -ErrorAction SilentlyContinue) {
minikube completion powershell | Out-String | Invoke-Expression
}'

Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion
`
Expand Down Expand Up @@ -75,7 +85,7 @@ var completionCmd = &cobra.Command{
if len(args) != 1 {
exit.Message(reason.Usage, "Usage: minikube completion SHELL")
}
if args[0] != "bash" && args[0] != "zsh" && args[0] != "fish" {
if args[0] != "bash" && args[0] != "zsh" && args[0] != "fish" && args[0] != "powershell" {
exit.Message(reason.Usage, "Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]})
}
},
Expand Down Expand Up @@ -117,10 +127,23 @@ var fishCmd = &cobra.Command{
},
}

var powershellCmd = &cobra.Command{
Use: "powershell",
Short: "powershell completion.",
Long: "Generate command completion for PowerShell.",
Run: func(cmd *cobra.Command, args []string) {
err := GeneratePowerShellCompletion(os.Stdout, cmd.Root())
if err != nil {
exit.Error(reason.InternalCompletion, "powershell completion failed", err)
}
},
}

func init() {
completionCmd.AddCommand(bashCmd)
completionCmd.AddCommand(zshCmd)
completionCmd.AddCommand(fishCmd)
completionCmd.AddCommand(powershellCmd)
}

// GenerateBashCompletion generates the completion for the bash shell
Expand Down Expand Up @@ -329,3 +352,18 @@ func GenerateFishCompletion(w io.Writer, cmd *cobra.Command) error {

return nil
}

// GeneratePowerShellCompletion generates the completion for the PowerShell
func GeneratePowerShellCompletion(w io.Writer, cmd *cobra.Command) error {
_, err := w.Write([]byte(boilerPlate))
if err != nil {
return err
}

err = cmd.GenPowerShellCompletionWithDesc(w)
if err != nil {
return errors.Wrap(err, "Error generating powershell completion")
}

return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/samalba/dockerclient v0.0.0-20160414174713-91d7393ff859 // indirect
github.com/shirou/gopsutil/v3 v3.23.3
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1471,8 +1471,8 @@ github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKv
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
Expand Down
48 changes: 47 additions & 1 deletion site/content/en/docs/commands/completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Generate command completion for a shell

### Synopsis

Outputs minikube shell completion for the given shell (bash, zsh or fish)
Outputs minikube shell completion for the given shell (bash, zsh, fish or powershell)

This depends on the bash-completion binary. Example installation instructions:
OS X:
Expand All @@ -30,6 +30,16 @@ Outputs minikube shell completion for the given shell (bash, zsh or fish)

Additionally, you may want to output the completion to a file and source in your .bashrc

Windows:
## Save completion code to a script and execute in the profile
PS> minikube completion powershell > $HOME\.minikube-completion.ps1
PS> Add-Content $PROFILE '. $HOME\.minikube-completion.ps1'

## Execute completion code in the profile
PS> Add-Content $PROFILE 'if (Get-Command minikube -ErrorAction SilentlyContinue) {
minikube completion powershell | Out-String | Invoke-Expression
}'

Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion

Expand Down Expand Up @@ -171,6 +181,42 @@ minikube completion help [command] [flags]
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

## minikube completion powershell

powershell completion.

### Synopsis

Generate command completion for PowerShell.

```shell
minikube completion powershell [flags]
```

### Options inherited from parent commands

```
--add_dir_header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
-b, --bootstrapper string The name of the cluster bootstrapper that will set up the Kubernetes cluster. (default "kubeadm")
-h, --help
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log_file string If non-empty, use this log file (no effect when -logtostderr=true)
--log_file_max_size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files
--one_output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
-p, --profile string The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently. (default "minikube")
--rootless Force to use rootless driver (docker and podman driver only)
--skip-audit Skip recording the current command in the audit logs.
--skip_headers If true, avoid header prefixes in the log messages
--skip_log_headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
--user string Specifies the user executing the operation. Useful for auditing operations executed by 3rd party tools. Defaults to the operating system username.
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

## minikube completion zsh

zsh completion.
Expand Down
5 changes: 4 additions & 1 deletion translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
"Found driver(s) but none were healthy. See above for suggestions how to fix installed drivers.": "Treiber wurden gefunden, sind aber nicht funktional. Schauen Sie die obigen Anmerkungen an, um die installierten Treiber zu reparieren.",
"Found network options:": "Gefundene Netzwerkoptionen:",
"Found {{.number}} invalid profile(s) ! ": "{{.number}} ungütliger Profile gefunden !",
"Generate command completion for PowerShell.": "",
"Generate command completion for a shell": "Generiere die Befehls-Vervollständigung für eine Shell",
"Generate command completion for bash.": "Generiere die Befehls-Vervollständigung für bash.",
"Generate command completion for fish .": "Generiere die Befehls-Vervollständigung für fish.",
Expand Down Expand Up @@ -469,7 +470,7 @@
"Options: {{.options}}": "Optionen: {{.options}}",
"Output format. Accepted values: [json, yaml]": "",
"Output format. Accepted values: [json]": "Ausgabe Format. Akzeptierte Werte: [json]",
"Outputs minikube shell completion for the given shell (bash, zsh or fish)\n\n\tThis depends on the bash-completion binary. Example installation instructions:\n\tOS X:\n\t\t$ brew install bash-completion\n\t\t$ source $(brew --prefix)/etc/bash_completion\n\t\t$ minikube completion bash \u003e ~/.minikube-completion # for bash users\n\t\t$ minikube completion zsh \u003e ~/.minikube-completion # for zsh users\n\t\t$ source ~/.minikube-completion\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\tUbuntu:\n\t\t$ apt-get install bash-completion\n\t\t$ source /etc/bash_completion\n\t\t$ source \u003c(minikube completion bash) # for bash users\n\t\t$ source \u003c(minikube completion zsh) # for zsh users\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\n\tAdditionally, you may want to output the completion to a file and source in your .bashrc\n\n\tNote for zsh users: [1] zsh completions are only supported in versions of zsh \u003e= 5.2\n\tNote for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion\n": "",
"Outputs minikube shell completion for the given shell (bash, zsh, fish or powershell)\n\n\tThis depends on the bash-completion binary. Example installation instructions:\n\tOS X:\n\t\t$ brew install bash-completion\n\t\t$ source $(brew --prefix)/etc/bash_completion\n\t\t$ minikube completion bash \u003e ~/.minikube-completion # for bash users\n\t\t$ minikube completion zsh \u003e ~/.minikube-completion # for zsh users\n\t\t$ source ~/.minikube-completion\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\tUbuntu:\n\t\t$ apt-get install bash-completion\n\t\t$ source /etc/bash_completion\n\t\t$ source \u003c(minikube completion bash) # for bash users\n\t\t$ source \u003c(minikube completion zsh) # for zsh users\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\n\tAdditionally, you may want to output the completion to a file and source in your .bashrc\n\n\tWindows:\n\t\t## Save completion code to a script and execute in the profile\n\t\tPS\u003e minikube completion powershell \u003e $HOME\\.minikube-completion.ps1\n\t\tPS\u003e Add-Content $PROFILE '. $HOME\\.minikube-completion.ps1'\n\n\t\t## Execute completion code in the profile\n\t\tPS\u003e Add-Content $PROFILE 'if (Get-Command minikube -ErrorAction SilentlyContinue) {\n\t\t minikube completion powershell | Out-String | Invoke-Expression\n\t\t }'\n\n\tNote for zsh users: [1] zsh completions are only supported in versions of zsh \u003e= 5.2\n\tNote for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion\n": "",
"Outputs the licenses of dependencies to a directory": "",
"Overwrite image even if same image:tag name exists": "Überschreibe das Image, auch wenn ein Image mit dem gleichen Image:Tag-Namen existiert",
"Path to socket vmnet binary (QEMU driver only)": "",
Expand Down Expand Up @@ -1014,6 +1015,8 @@
"numa node is only supported on k8s v1.18 and later": "Numa Node wird nur von k8s Version v1.18 oder später unterstützt",
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "Ausgabe Layout (EXPERIMENTELL, nur JSON): 'nodes' oder 'clusters'",
"pause Kubernetes": "pausiere Kubernetes",
"powershell completion failed": "",
"powershell completion.": "",
"preload extraction failed: \"No space left on device\"": "",
"preload extraction failed: \\\"No space left on device\\\"": "Auspacken von Preload fehlgeschlagen: \\\"Es ist kein Speicherplatz mehr verfügbar\\\"",
"profile sets the current minikube profile, or gets the current profile if no arguments are provided. This is used to run and manage multiple minikube instance. You can return to the default minikube profile by running `minikube profile default`": "",
Expand Down
5 changes: 4 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"Found driver(s) but none were healthy. See above for suggestions how to fix installed drivers.": "",
"Found network options:": "Se han encontrado las siguientes opciones de red:",
"Found {{.number}} invalid profile(s) ! ": "Se encontraron {{.number}} perfil(es) invalido(s)",
"Generate command completion for PowerShell.": "",
"Generate command completion for a shell": "",
"Generate command completion for bash.": "",
"Generate command completion for fish .": "",
Expand Down Expand Up @@ -476,7 +477,7 @@
"Operations on nodes": "",
"Options: {{.options}}": "",
"Output format. Accepted values: [json, yaml]": "",
"Outputs minikube shell completion for the given shell (bash, zsh or fish)\n\n\tThis depends on the bash-completion binary. Example installation instructions:\n\tOS X:\n\t\t$ brew install bash-completion\n\t\t$ source $(brew --prefix)/etc/bash_completion\n\t\t$ minikube completion bash \u003e ~/.minikube-completion # for bash users\n\t\t$ minikube completion zsh \u003e ~/.minikube-completion # for zsh users\n\t\t$ source ~/.minikube-completion\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\tUbuntu:\n\t\t$ apt-get install bash-completion\n\t\t$ source /etc/bash_completion\n\t\t$ source \u003c(minikube completion bash) # for bash users\n\t\t$ source \u003c(minikube completion zsh) # for zsh users\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\n\tAdditionally, you may want to output the completion to a file and source in your .bashrc\n\n\tNote for zsh users: [1] zsh completions are only supported in versions of zsh \u003e= 5.2\n\tNote for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion\n": "",
"Outputs minikube shell completion for the given shell (bash, zsh, fish or powershell)\n\n\tThis depends on the bash-completion binary. Example installation instructions:\n\tOS X:\n\t\t$ brew install bash-completion\n\t\t$ source $(brew --prefix)/etc/bash_completion\n\t\t$ minikube completion bash \u003e ~/.minikube-completion # for bash users\n\t\t$ minikube completion zsh \u003e ~/.minikube-completion # for zsh users\n\t\t$ source ~/.minikube-completion\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\tUbuntu:\n\t\t$ apt-get install bash-completion\n\t\t$ source /etc/bash_completion\n\t\t$ source \u003c(minikube completion bash) # for bash users\n\t\t$ source \u003c(minikube completion zsh) # for zsh users\n\t\t$ minikube completion fish \u003e ~/.config/fish/completions/minikube.fish # for fish users\n\n\tAdditionally, you may want to output the completion to a file and source in your .bashrc\n\n\tWindows:\n\t\t## Save completion code to a script and execute in the profile\n\t\tPS\u003e minikube completion powershell \u003e $HOME\\.minikube-completion.ps1\n\t\tPS\u003e Add-Content $PROFILE '. $HOME\\.minikube-completion.ps1'\n\n\t\t## Execute completion code in the profile\n\t\tPS\u003e Add-Content $PROFILE 'if (Get-Command minikube -ErrorAction SilentlyContinue) {\n\t\t minikube completion powershell | Out-String | Invoke-Expression\n\t\t }'\n\n\tNote for zsh users: [1] zsh completions are only supported in versions of zsh \u003e= 5.2\n\tNote for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion\n": "",
"Outputs the licenses of dependencies to a directory": "",
"Overwrite image even if same image:tag name exists": "",
"Path to socket vmnet binary (QEMU driver only)": "",
Expand Down Expand Up @@ -1009,6 +1010,8 @@
"numa node is only supported on k8s v1.18 and later": "",
"output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster'": "",
"pause Kubernetes": "",
"powershell completion failed": "",
"powershell completion.": "",
"preload extraction failed: \"No space left on device\"": "",
"profile sets the current minikube profile, or gets the current profile if no arguments are provided. This is used to run and manage multiple minikube instance. You can return to the default minikube profile by running `minikube profile default`": "",
"provisioning host for node": "",
Expand Down
Loading