(cmd *cobra.Command, args []string, toComplete string)
| 638 | } |
| 639 | |
| 640 | func completeCommunityScriptSlugs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 641 | if len(args) != 0 { |
| 642 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 643 | } |
| 644 | |
| 645 | session, err := initCLISession(cmd) |
| 646 | if err != nil || session == nil || ensureCommunityScriptsEnabled(session) != nil { |
| 647 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 648 | } |
| 649 | |
| 650 | scripts, err := core.FetchScripts() |
| 651 | if err != nil { |
| 652 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 653 | } |
| 654 | |
| 655 | prefix := strings.ToLower(toComplete) |
| 656 | completions := make([]string, 0, len(scripts)) |
| 657 | for _, script := range scripts { |
| 658 | if prefix == "" || strings.HasPrefix(strings.ToLower(script.Slug), prefix) { |
| 659 | completions = append(completions, fmt.Sprintf("%s\t%s", script.Slug, script.Name)) |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | return completions, cobra.ShellCompDirectiveNoFileComp |
| 664 | } |
nothing calls this directly
no test coverage detected