@@ -13,7 +13,7 @@ import (
13
13
// The returned function is mainly intended to be passed to
14
14
// cobra/Command.RegisterFlagCompletionFunc or assigned to
15
15
// cobra/Command.ValidArgsFunction.
16
- func SuggestCandidates (cs ... string ) func ( * cobra.Command , [] string , string ) ([] string , cobra. ShellCompDirective ) {
16
+ func SuggestCandidates (cs ... string ) cobra.CompletionFunc {
17
17
return SuggestCandidatesF (func () []string {
18
18
return cs
19
19
})
@@ -23,9 +23,7 @@ func SuggestCandidates(cs ...string) func(*cobra.Command, []string, string) ([]s
23
23
// to obtain a list of completion candidates. Once the list of candidates is
24
24
// obtained the function returned by SuggestCandidatesF behaves like the
25
25
// function returned by SuggestCandidates.
26
- func SuggestCandidatesF (
27
- cf func () []string ,
28
- ) func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
26
+ func SuggestCandidatesF (cf func () []string ) cobra.CompletionFunc {
29
27
return SuggestCandidatesCtx (func (* cobra.Command , []string ) []string {
30
28
return cf ()
31
29
})
@@ -37,10 +35,8 @@ func SuggestCandidatesF(
37
35
// depend on a previously selected item like a server.
38
36
//
39
37
// Once the list of candidates is obtained the function returned by
40
- // SuggestCandidatesF behaves like the function returned by SuggestCandidates.
41
- func SuggestCandidatesCtx (
42
- cf func (* cobra.Command , []string ) []string ,
43
- ) func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
38
+ // SuggestCandidatesCtx behaves like the function returned by SuggestCandidates.
39
+ func SuggestCandidatesCtx (cf func (* cobra.Command , []string ) []string ) cobra.CompletionFunc {
44
40
return func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
45
41
cs := cf (cmd , args )
46
42
if toComplete == "" {
@@ -60,7 +56,7 @@ func SuggestCandidatesCtx(
60
56
}
61
57
62
58
// SuggestNothing returns a function that provides no suggestions.
63
- func SuggestNothing () func ( * cobra.Command , [] string , string ) ([] string , cobra. ShellCompDirective ) {
59
+ func SuggestNothing () cobra.CompletionFunc {
64
60
return func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
65
61
return nil , cobra .ShellCompDirectiveDefault
66
62
}
@@ -75,9 +71,7 @@ func SuggestNothing() func(*cobra.Command, []string, string) ([]string, cobra.Sh
75
71
// calls the function at vfs[4] if it exists. To skip suggestions for an
76
72
// argument in the middle of a list of arguments pass either nil or
77
73
// SuggestNothing. Using SuggestNothing is preferred.
78
- func SuggestArgs (
79
- vfs ... func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ),
80
- ) func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
74
+ func SuggestArgs (vfs ... cobra.CompletionFunc ) cobra.CompletionFunc {
81
75
return func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
82
76
// Number of argument to suggest. args contains the already present
83
77
// command line arguments.
@@ -95,8 +89,7 @@ func SuggestArgs(
95
89
96
90
// NoFileCompletion returns a function that provides completion suggestions without
97
91
// file completion.
98
- func NoFileCompletion (f func (* cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective )) func (
99
- * cobra.Command , []string , string ) ([]string , cobra.ShellCompDirective ) {
92
+ func NoFileCompletion (f cobra.CompletionFunc ) cobra.CompletionFunc {
100
93
return func (command * cobra.Command , i []string , s string ) ([]string , cobra.ShellCompDirective ) {
101
94
candidates , _ := f (command , i , s )
102
95
return candidates , cobra .ShellCompDirectiveNoFileComp
0 commit comments