── shell completions ───────────────────────────────────────────────────────── completeStorageNames is a ValidArgsFunction for positional args. It requires the arg to already be present (index 0).
(cmd *cobra.Command, args []string, toComplete string)
| 813 | // completeStorageNames is a ValidArgsFunction for <storage> positional args. |
| 814 | // It requires the <node> arg to already be present (index 0). |
| 815 | func completeStorageNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 816 | if len(args) < 1 { |
| 817 | return completeNodeNames(cmd, args, toComplete) |
| 818 | } |
| 819 | |
| 820 | nodeName := args[0] |
| 821 | |
| 822 | session, err := initCLISession(cmd) |
| 823 | if err != nil || session == nil { |
| 824 | return nil, cobra.ShellCompDirectiveError |
| 825 | } |
| 826 | |
| 827 | client, err := session.clientForNode(context.Background(), nodeName) |
| 828 | if err != nil { |
| 829 | return nil, cobra.ShellCompDirectiveError |
| 830 | } |
| 831 | |
| 832 | storages, err := client.GetNodeStorages(nodeName) |
| 833 | if err != nil { |
| 834 | return nil, cobra.ShellCompDirectiveError |
| 835 | } |
| 836 | |
| 837 | var names []string |
| 838 | for _, s := range storages { |
| 839 | if s != nil && strings.HasPrefix(s.Name, toComplete) { |
| 840 | names = append(names, s.Name) |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return names, cobra.ShellCompDirectiveNoFileComp |
| 845 | } |
| 846 | |
| 847 | // completeTemplateNames is a ValidArgsFunction for <template> in storage download template. |
| 848 | // It requires node (args[0]) and storage (args[1]) to already be present. |
no test coverage detected