-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_completions.go
47 lines (42 loc) · 908 Bytes
/
generate_completions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/Tom5521/fsize/flags"
"github.com/spf13/cobra"
)
func GenerateCompletions(cmd *cobra.Command, args []string) (err error) {
var (
customName bool
filename string
completionFunc func(string) error
)
if len(args) == 0 {
customName = false
filename = "fsize-completions"
} else {
customName = true
filename = args[0]
}
switch {
case flags.GenZshCompletion:
if !customName {
filename += ".zsh"
}
completionFunc = cmd.GenZshCompletionFile
case flags.GenFishCompletion:
if !customName {
filename += ".fish"
}
completionFunc = func(filename string) error {
return cmd.GenFishCompletionFile(filename, true)
}
case flags.GenBashCompletion:
if !customName {
filename += ".sh"
}
completionFunc = func(s string) error {
return cmd.GenBashCompletionFileV2(s, true)
}
}
err = completionFunc(filename)
return
}