| 304 | } |
| 305 | |
| 306 | func (c *cleanCmd) completion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 307 | var suggestions []string |
| 308 | |
| 309 | // Support port completion. |
| 310 | if fileio.PathExists(dirs.BuildtreesDir) { |
| 311 | entities, err := os.ReadDir(dirs.BuildtreesDir) |
| 312 | if err == nil { |
| 313 | for _, entity := range entities { |
| 314 | if entity.IsDir() && strings.HasPrefix(entity.Name(), toComplete) { |
| 315 | suggestions = append(suggestions, entity.Name()) |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // Support project completion. |
| 322 | if fileio.PathExists(dirs.ConfProjectsDir) { |
| 323 | entities, err := os.ReadDir(dirs.ConfProjectsDir) |
| 324 | if err == nil { |
| 325 | for _, entity := range entities { |
| 326 | if !entity.IsDir() && strings.HasSuffix(entity.Name(), ".toml") { |
| 327 | fileName := strings.TrimSuffix(entity.Name(), ".toml") |
| 328 | if strings.HasPrefix(fileName, toComplete) { |
| 329 | suggestions = append(suggestions, fileName) |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | // Support flags completion. |
| 337 | for _, flag := range []string{"--dev", "-d", "--recursive", "-r", "--all", "-a"} { |
| 338 | if strings.HasPrefix(flag, toComplete) { |
| 339 | suggestions = append(suggestions, flag) |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | return suggestions, cobra.ShellCompDirectiveNoFileComp |
| 344 | } |