GetAddonNamesFunc returns a function for autocomplete that provides addon names from the cached add-on registry. If numArgs is 0, completion will be provided for infinite arguments, otherwise it will only be provided for the numArgs number of arguments.
(numArgs int)
| 884 | // If numArgs is 0, completion will be provided for infinite arguments, |
| 885 | // otherwise it will only be provided for the numArgs number of arguments. |
| 886 | func GetAddonNamesFunc(numArgs int) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { |
| 887 | return func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { |
| 888 | // Don't provide completions if the user keeps hitting space after |
| 889 | // exhausting all of the valid arguments. |
| 890 | if numArgs > 0 && len(args)+1 > numArgs { |
| 891 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 892 | } |
| 893 | |
| 894 | addons, err := ListAvailableAddonsFromRegistry() |
| 895 | if err != nil { |
| 896 | // If we can't get addons, return no completions |
| 897 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 898 | } |
| 899 | |
| 900 | // Extract addon names in owner/repo format |
| 901 | // Don't show arguments that are already written on the command line |
| 902 | var addonNames []string |
| 903 | for _, addon := range addons { |
| 904 | addonName := fmt.Sprintf("%s/%s", addon.User, addon.Repo) |
| 905 | if !slices.Contains(args, addonName) { |
| 906 | addonNames = append(addonNames, addonName) |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | return addonNames, cobra.ShellCompDirectiveNoFileComp |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // RemoveAddon removes an addon, taking care to respect #ddev-generated |
| 915 | // addonName can be the "Name", or the full "Repository" like ddev/ddev-redis, or |
no test coverage detected