MCPcopy Create free account
hub / github.com/celer-pkg/celer / completion

Method completion

cmds/cmd_update.go:215–265  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, toComplete string)

Source from the content-addressed store, hash-verified

213}
214
215func (u *updateCmd) completion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
216 var suggestions []string
217 var buildtreesDir = dirs.BuildtreesDir
218
219 // Support port completion.
220 if fileio.PathExists(buildtreesDir) {
221 entities, err := os.ReadDir(buildtreesDir)
222 if err != nil {
223 return suggestions, cobra.ShellCompDirectiveNoFileComp
224 }
225
226 for _, entity := range entities {
227 if entity.IsDir() && strings.HasPrefix(entity.Name(), toComplete) {
228 suggestions = append(suggestions, entity.Name())
229 }
230 }
231 }
232
233 // Support project completion.
234 if fileio.PathExists(dirs.ConfProjectsDir) {
235 entities, err := os.ReadDir(dirs.ConfProjectsDir)
236 if err != nil {
237 // Don't fail completion, just return what we have.
238 return suggestions, cobra.ShellCompDirectiveNoFileComp
239 }
240
241 for _, entity := range entities {
242 if !entity.IsDir() && strings.HasSuffix(entity.Name(), ".toml") {
243 fileName := strings.TrimSuffix(entity.Name(), ".toml")
244 if strings.HasPrefix(fileName, toComplete) {
245 suggestions = append(suggestions, fileName)
246 }
247 }
248 }
249 }
250
251 // Support flags completion.
252 flags := []string{
253 "--conf-repo", "-c",
254 "--ports-repo", "-p",
255 "--recursive", "-r",
256 "--force", "-f",
257 }
258 for _, flag := range flags {
259 if strings.HasPrefix(flag, toComplete) {
260 suggestions = append(suggestions, flag)
261 }
262 }
263
264 return suggestions, cobra.ShellCompDirectiveNoFileComp
265}

Callers 1

TestUpdateCmd_CompletionFunction · 0.95

Calls 2

PathExistsFunction · 0.92
NameMethod · 0.65

Tested by 1

TestUpdateCmd_CompletionFunction · 0.76