-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_completions.go
35 lines (27 loc) · 1011 Bytes
/
shell_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
package zulu
import (
"fmt"
"github.com/zulucmd/zflag/v2"
)
// FlagOptFilename instructs the various shell completion implementations to
// limit completions for the flag to the specified file extensions.
func FlagOptFilename(extensions ...string) zflag.Opt {
return zflag.OptAnnotation(BashCompFilenameExt, extensions)
}
// FlagOptDirname instructs the various shell completion implementations to
// limit completions for the flag to directory names.
func FlagOptDirname(dirnames ...string) zflag.Opt {
return zflag.OptAnnotation(BashCompSubdirsInDir, dirnames)
}
// FlagOptCompletionFunc is used to register a function to provide completion for a flag.
func FlagOptCompletionFunc(f FlagCompletionFn) zflag.Opt {
return func(flag *zflag.Flag) error {
flagCompletionMutex.Lock()
defer flagCompletionMutex.Unlock()
if _, exists := flagCompletionFunctions[flag]; exists {
return fmt.Errorf("flag '%s' already registered", flag.Name)
}
flagCompletionFunctions[flag] = f
return nil
}
}