code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/shell_completion.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package cmd 17 18 import ( 19 "io" 20 21 "github.com/spf13/cobra" 22 ) 23 24 var completionLong = `To load completions: 25 26 Bash: To load completions for each session, execute once: 27 ----- Linux: 28 $ {{.Software}} shell completion bash > /etc/bash_completion.d/{{.Software}} 29 MacOS: 30 $ {{.Software}} shell completion bash > /usr/local/etc/bash_completion.d/{{.Software}} 31 32 33 Zsh: If shell completion is not already enabled in your environment you will need 34 ---- to enable it. You can execute the following once: 35 $ echo "autoload -U compinit; compinit" >> ~/.zshrc 36 37 To load completions for each session, execute once: 38 $ {{.Software}} shell completion zsh > "${fpath[1]}/_{{.Software}}" 39 40 You will need to start a new shell for this setup to take effect. 41 42 43 Fish: To load completions for each session, execute once: 44 ----- $ {{.Software}} shell completion fish > ~/.config/fish/completions/{{.Software}}.fish 45 ` 46 47 func NewCmdShellCompletion(w io.Writer) *cobra.Command { 48 return &cobra.Command{ 49 Use: "completion [bash|zsh|fish|powershell]", 50 Short: "Generate completion script", 51 Long: completionLong, 52 DisableFlagsInUseLine: true, 53 ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, 54 Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), 55 Run: func(cmd *cobra.Command, args []string) { 56 switch args[0] { 57 case "bash": 58 _ = cmd.Root().GenBashCompletion(w) 59 case "zsh": 60 _ = cmd.Root().GenZshCompletion(w) 61 case "fish": 62 _ = cmd.Root().GenFishCompletion(w, true) 63 case "powershell": 64 _ = cmd.Root().GenPowerShellCompletion(w) 65 } 66 }, 67 } 68 }