-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
35 lines (28 loc) · 1009 Bytes
/
utils.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
package main
import (
"github.com/spf13/cobra"
)
func ValidArgsFunctionTargets(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
targets, _, err := autocompleteInit(cmd.Context(), false)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
directive := cobra.ShellCompDirectiveNoFileComp
isFuzzy, suggestions := autocompleteTargetName(targets, toComplete)
if isFuzzy {
directive |= cobra.ShellCompDirectiveNoMatching
}
return suggestions, directive
}
func ValidArgsFunctionLabelsOrTargets(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
targets, labels, err := autocompleteInit(cmd.Context(), false)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
directive := cobra.ShellCompDirectiveNoFileComp
isFuzzy, suggestions := autocompleteLabelOrTarget(targets, labels, toComplete)
if isFuzzy {
directive |= cobra.ShellCompDirectiveNoMatching
}
return suggestions, directive
}