MCPcopy Index your code
hub / github.com/docker/cli / Unique

Function Unique

cli/command/completion/functions.go:239–260  ·  view source on GitHub ↗

Unique wraps a completion func and removes completion results that are already consumed (i.e., appear in "args"). For example: # initial completion: args is empty, so all results are shown command one two three # "one" is already used so omitted command one two three

(fn cobra.CompletionFunc)

Source from the content-addressed store, hash-verified

237// command one <tab>
238// two three
239func Unique(fn cobra.CompletionFunc) cobra.CompletionFunc {
240 return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
241 all, dir := fn(cmd, args, toComplete)
242 if len(all) == 0 || len(args) == 0 {
243 return all, dir
244 }
245
246 alreadyCompleted := make(map[string]struct{}, len(args))
247 for _, a := range args {
248 alreadyCompleted[a] = struct{}{}
249 }
250
251 out := make([]string, 0, len(all))
252 for _, c := range all {
253 if _, ok := alreadyCompleted[c]; !ok {
254 out = append(out, c)
255 }
256 }
257
258 return out, dir
259 }
260}

Callers 8

TestUniqueFunction · 0.85
ImageNamesFunction · 0.85
ImageNamesWithBaseFunction · 0.85
ContainerNamesFunction · 0.85
VolumeNamesFunction · 0.85
NetworkNamesFunction · 0.85
EnvVarNamesFunction · 0.85
FromListFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestUniqueFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…