MCPcopy Create free account
hub / github.com/docker/docker-agent / completeAgentFilename

Function completeAgentFilename

cmd/root/completion.go:116–150  ·  view source on GitHub ↗
(toComplete string)

Source from the content-addressed store, hash-verified

114}
115
116func completeAgentFilename(toComplete string) ([]string, cobra.ShellCompDirective) {
117 dirPrefix, base := filepath.Split(toComplete)
118
119 dirToRead := dirPrefix
120 if dirToRead == "" {
121 dirToRead = "."
122 }
123
124 entries, err := os.ReadDir(dirToRead)
125 if err != nil {
126 return nil, cobra.ShellCompDirectiveNoFileComp
127 }
128
129 var out []string
130 for _, e := range entries {
131 name := e.Name()
132 if !strings.HasPrefix(name, base) {
133 continue
134 }
135
136 switch {
137 case e.IsDir():
138 out = append(out, dirPrefix+name+string(filepath.Separator))
139 case strings.EqualFold(filepath.Ext(name), ".yaml"), strings.EqualFold(filepath.Ext(name), ".yml"):
140 out = append(out, dirPrefix+name)
141 }
142 }
143
144 // Don't add space after single directory completion
145 if len(out) == 1 && strings.HasSuffix(out[0], string(filepath.Separator)) {
146 return out, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
147 }
148
149 return out, cobra.ShellCompDirectiveNoFileComp
150}

Callers 2

completeAliasFunction · 0.85

Calls 1

NameMethod · 0.65

Tested by 1