mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-03 19:42:51 +08:00
Merge pull request #235 from stealthybox/shell-completions
Support bash, fish, zsh, and powershell shell completions as separate sub-commands
This commit is contained in:
@ -17,26 +17,13 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var completionCmd = &cobra.Command{
|
var completionCmd = &cobra.Command{
|
||||||
Use: "completion",
|
Use: "completion",
|
||||||
Short: "Generates bash completion scripts",
|
Short: "Generates completion scripts for various shells",
|
||||||
Example: `To load completion run
|
Long: "The completion sub-command generates completion scripts for various shells",
|
||||||
|
|
||||||
. <(gotk completion)
|
|
||||||
|
|
||||||
To configure your bash shell to load completions for each session add to your bashrc
|
|
||||||
|
|
||||||
# ~/.bashrc or ~/.profile
|
|
||||||
. <(gotk completion)
|
|
||||||
`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
rootCmd.GenBashCompletion(os.Stdout)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
44
cmd/gotk/completion_bash.go
Normal file
44
cmd/gotk/completion_bash.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Flux CD contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var completionBashCmd = &cobra.Command{
|
||||||
|
Use: "bash",
|
||||||
|
Short: "Generates bash completion scripts",
|
||||||
|
Example: `To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion bash)
|
||||||
|
|
||||||
|
To configure your bash shell to load completions for each session add to your bashrc
|
||||||
|
|
||||||
|
# ~/.bashrc or ~/.profile
|
||||||
|
command -v gotk >/dev/null && . <(gotk completion bash)
|
||||||
|
`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
rootCmd.GenBashCompletion(os.Stdout)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
completionCmd.AddCommand(completionBashCmd)
|
||||||
|
}
|
||||||
45
cmd/gotk/completion_fish.go
Normal file
45
cmd/gotk/completion_fish.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Flux CD contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var completionFishCmd = &cobra.Command{
|
||||||
|
Use: "fish",
|
||||||
|
Short: "Generates fish completion scripts",
|
||||||
|
Example: `To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion fish)
|
||||||
|
|
||||||
|
To configure your fish shell to load completions for each session write this script to your completions dir:
|
||||||
|
|
||||||
|
gotk completion fish > ~/.config/fish/completions/gotk
|
||||||
|
|
||||||
|
See http://fishshell.com/docs/current/index.html#completion-own for more details
|
||||||
|
`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
rootCmd.GenFishCompletion(os.Stdout, true)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
completionCmd.AddCommand(completionFishCmd)
|
||||||
|
}
|
||||||
51
cmd/gotk/completion_powershell.go
Normal file
51
cmd/gotk/completion_powershell.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Flux CD contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var completionPowerShellCmd = &cobra.Command{
|
||||||
|
Use: "powershell",
|
||||||
|
Short: "Generates powershell completion scripts",
|
||||||
|
Example: `To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion powershell)
|
||||||
|
|
||||||
|
To configure your powershell shell to load completions for each session add to your powershell profile
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
|
||||||
|
cd "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
|
||||||
|
gotk completion >> gotk-completion.ps1
|
||||||
|
|
||||||
|
Linux:
|
||||||
|
|
||||||
|
cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
|
||||||
|
gotk completion >> gotk-completions.ps1
|
||||||
|
`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
rootCmd.GenPowerShellCompletion(os.Stdout)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
completionCmd.AddCommand(completionPowerShellCmd)
|
||||||
|
}
|
||||||
52
cmd/gotk/completion_zsh.go
Normal file
52
cmd/gotk/completion_zsh.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2020 The Flux CD contributors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var completionZshCmd = &cobra.Command{
|
||||||
|
Use: "zsh",
|
||||||
|
Short: "Generates zsh completion scripts",
|
||||||
|
Example: `To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion zsh) && compdef _gotk gotk
|
||||||
|
|
||||||
|
To configure your zsh shell to load completions for each session add to your zshrc
|
||||||
|
|
||||||
|
# ~/.zshrc or ~/.profile
|
||||||
|
command -v gotk >/dev/null && . <(gotk completion zsh) && compdef _gotk gotk
|
||||||
|
|
||||||
|
or write a cached file in one of the completion directories in your ${fpath}:
|
||||||
|
|
||||||
|
echo "${fpath// /\n}" | grep -i completion
|
||||||
|
gotk completions zsh > _gotk
|
||||||
|
|
||||||
|
mv _gotk ~/.oh-my-zsh/completions # oh-my-zsh
|
||||||
|
mv _gotk ~/.zprezto/modules/completion/external/src/ # zprezto
|
||||||
|
`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
rootCmd.GenZshCompletion(os.Stdout)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
completionCmd.AddCommand(completionZshCmd)
|
||||||
|
}
|
||||||
@ -78,7 +78,7 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.
|
|||||||
|
|
||||||
* [gotk bootstrap](gotk_bootstrap.md) - Bootstrap toolkit components
|
* [gotk bootstrap](gotk_bootstrap.md) - Bootstrap toolkit components
|
||||||
* [gotk check](gotk_check.md) - Check requirements and installation
|
* [gotk check](gotk_check.md) - Check requirements and installation
|
||||||
* [gotk completion](gotk_completion.md) - Generates bash completion scripts
|
* [gotk completion](gotk_completion.md) - Generates completion scripts for various shells
|
||||||
* [gotk create](gotk_create.md) - Create or update sources and resources
|
* [gotk create](gotk_create.md) - Create or update sources and resources
|
||||||
* [gotk delete](gotk_delete.md) - Delete sources and resources
|
* [gotk delete](gotk_delete.md) - Delete sources and resources
|
||||||
* [gotk export](gotk_export.md) - Export resources in YAML format
|
* [gotk export](gotk_export.md) - Export resources in YAML format
|
||||||
|
|||||||
@ -1,28 +1,10 @@
|
|||||||
## gotk completion
|
## gotk completion
|
||||||
|
|
||||||
Generates bash completion scripts
|
Generates completion scripts for various shells
|
||||||
|
|
||||||
### Synopsis
|
### Synopsis
|
||||||
|
|
||||||
Generates bash completion scripts
|
The completion sub-command generates completion scripts for various shells
|
||||||
|
|
||||||
```
|
|
||||||
gotk completion [flags]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```
|
|
||||||
To load completion run
|
|
||||||
|
|
||||||
. <(gotk completion)
|
|
||||||
|
|
||||||
To configure your bash shell to load completions for each session add to your bashrc
|
|
||||||
|
|
||||||
# ~/.bashrc or ~/.profile
|
|
||||||
. <(gotk completion)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
@ -42,4 +24,8 @@ To configure your bash shell to load completions for each session add to your ba
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [gotk](gotk.md) - Command line utility for assembling Kubernetes CD pipelines
|
* [gotk](gotk.md) - Command line utility for assembling Kubernetes CD pipelines
|
||||||
|
* [gotk completion bash](gotk_completion_bash.md) - Generates bash completion scripts
|
||||||
|
* [gotk completion fish](gotk_completion_fish.md) - Generates fish completion scripts
|
||||||
|
* [gotk completion powershell](gotk_completion_powershell.md) - Generates powershell completion scripts
|
||||||
|
* [gotk completion zsh](gotk_completion_zsh.md) - Generates zsh completion scripts
|
||||||
|
|
||||||
|
|||||||
45
docs/cmd/gotk_completion_bash.md
Normal file
45
docs/cmd/gotk_completion_bash.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
## gotk completion bash
|
||||||
|
|
||||||
|
Generates bash completion scripts
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generates bash completion scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
gotk completion bash [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion bash)
|
||||||
|
|
||||||
|
To configure your bash shell to load completions for each session add to your bashrc
|
||||||
|
|
||||||
|
# ~/.bashrc or ~/.profile
|
||||||
|
command -v gotk >/dev/null && . <(gotk completion bash)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [gotk completion](gotk_completion.md) - Generates completion scripts for various shells
|
||||||
|
|
||||||
46
docs/cmd/gotk_completion_fish.md
Normal file
46
docs/cmd/gotk_completion_fish.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
## gotk completion fish
|
||||||
|
|
||||||
|
Generates fish completion scripts
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generates fish completion scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
gotk completion fish [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion fish)
|
||||||
|
|
||||||
|
To configure your fish shell to load completions for each session write this script to your completions dir:
|
||||||
|
|
||||||
|
gotk completion fish > ~/.config/fish/completions/gotk
|
||||||
|
|
||||||
|
See http://fishshell.com/docs/current/index.html#completion-own for more details
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for fish
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [gotk completion](gotk_completion.md) - Generates completion scripts for various shells
|
||||||
|
|
||||||
52
docs/cmd/gotk_completion_powershell.md
Normal file
52
docs/cmd/gotk_completion_powershell.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
## gotk completion powershell
|
||||||
|
|
||||||
|
Generates powershell completion scripts
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generates powershell completion scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
gotk completion powershell [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion powershell)
|
||||||
|
|
||||||
|
To configure your powershell shell to load completions for each session add to your powershell profile
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
|
||||||
|
cd "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
|
||||||
|
gotk completion >> gotk-completion.ps1
|
||||||
|
|
||||||
|
Linux:
|
||||||
|
|
||||||
|
cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
|
||||||
|
gotk completion >> gotk-completions.ps1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for powershell
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [gotk completion](gotk_completion.md) - Generates completion scripts for various shells
|
||||||
|
|
||||||
53
docs/cmd/gotk_completion_zsh.md
Normal file
53
docs/cmd/gotk_completion_zsh.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
## gotk completion zsh
|
||||||
|
|
||||||
|
Generates zsh completion scripts
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
Generates zsh completion scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
gotk completion zsh [flags]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
To load completion run
|
||||||
|
|
||||||
|
. <(gotk completion zsh) && compdef _gotk gotk
|
||||||
|
|
||||||
|
To configure your zsh shell to load completions for each session add to your zshrc
|
||||||
|
|
||||||
|
# ~/.zshrc or ~/.profile
|
||||||
|
command -v gotk >/dev/null && . <(gotk completion zsh) && compdef _gotk gotk
|
||||||
|
|
||||||
|
or write a cached file in one of the completion directories in your ${fpath}:
|
||||||
|
|
||||||
|
echo "${fpath// /\n}" | grep -i completion
|
||||||
|
gotk completions zsh > _gotk
|
||||||
|
|
||||||
|
mv _gotk ~/.oh-my-zsh/completions # oh-my-zsh
|
||||||
|
mv _gotk ~/.zprezto/modules/completion/external/src/ # zprezto
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
```
|
||||||
|
-h, --help help for zsh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options inherited from parent commands
|
||||||
|
|
||||||
|
```
|
||||||
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
```
|
||||||
|
|
||||||
|
### SEE ALSO
|
||||||
|
|
||||||
|
* [gotk completion](gotk_completion.md) - Generates completion scripts for various shells
|
||||||
|
|
||||||
@ -41,9 +41,11 @@ To configure your shell to load gotk completions add to your Bash profile:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# ~/.bashrc or ~/.bash_profile
|
# ~/.bashrc or ~/.bash_profile
|
||||||
. <(gotk completion)
|
. <(gotk completion bash)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`zsh`, `fish`, and `powershell` are also supported with their own sub-commands.
|
||||||
|
|
||||||
## GitOps workflow
|
## GitOps workflow
|
||||||
|
|
||||||
You'll be using a dedicated Git repository e.g. `fleet-infra` to manage one or more Kubernetes clusters.
|
You'll be using a dedicated Git repository e.g. `fleet-infra` to manage one or more Kubernetes clusters.
|
||||||
|
|||||||
Reference in New Issue
Block a user