1+ package commands
2+
3+ import (
4+ "os"
5+
6+ "github.com/spf13/cobra"
7+ )
8+
9+ var completionCmd = & cobra.Command {
10+ Use : "completion [shell]" ,
11+ Short : "Generate shell completion scripts" ,
12+ Hidden : true ,
13+ Long : `Generate shell completion scripts for menlo.
14+
15+ To load completions:
16+
17+ Bash:
18+
19+ $ source <(menlo completion bash)
20+
21+ # To load completions for each session, execute once:
22+ # Linux:
23+ $ menlo completion bash > /etc/bash_completion.d/menlo
24+ # macOS:
25+ $ menlo completion bash > /usr/local/etc/bash_completion.d/menlo
26+
27+ Zsh:
28+
29+ # If shell completion is not already enabled in your environment,
30+ # you will need to enable it. You can execute the following once:
31+
32+ $ echo "autoload -U compinit; compinit" >> ~/.zshrc
33+
34+ # To load completions for each session, execute once:
35+ $ menlo completion zsh > "${fpath[1]}/_menlo"
36+
37+ # You will need to start a new shell for this setup to take effect.
38+
39+ Fish:
40+
41+ $ menlo completion fish | source
42+
43+ # To load completions for each session, execute once:
44+ $ menlo completion fish > ~/.config/fish/completions/menlo.fish
45+
46+ PowerShell:
47+
48+ PS> menlo completion powershell | Out-String | Invoke-Expression
49+
50+ # To load completions for every session, add the output of the previous
51+ # command to your powershell profile.
52+ ` ,
53+ DisableFlagsInUseLine : true ,
54+ ValidArgs : []string {"bash" , "zsh" , "fish" , "powershell" },
55+ Args : cobra .MatchAll (cobra .ExactArgs (1 ), cobra .OnlyValidArgs ),
56+ RunE : func (cmd * cobra.Command , args []string ) error {
57+ switch args [0 ] {
58+ case "bash" :
59+ return rootCmd .GenBashCompletion (os .Stdout )
60+ case "zsh" :
61+ return rootCmd .GenZshCompletion (os .Stdout )
62+ case "fish" :
63+ return rootCmd .GenFishCompletion (os .Stdout , true )
64+ case "powershell" :
65+ return rootCmd .GenPowerShellCompletionWithDesc (os .Stdout )
66+ }
67+ return nil
68+ },
69+ }
70+
71+ func init () {
72+ rootCmd .AddCommand (completionCmd )
73+ }
0 commit comments