completeNodeNames is a Cobra ValidArgsFunction that returns node names for tab completion. It requires no positional args already provided.
(cmd *cobra.Command, args []string, toComplete string)
| 527 | // completeNodeNames is a Cobra ValidArgsFunction that returns node names for |
| 528 | // tab completion. It requires no positional args already provided. |
| 529 | func completeNodeNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 530 | if len(args) != 0 { |
| 531 | return nil, cobra.ShellCompDirectiveNoFileComp |
| 532 | } |
| 533 | |
| 534 | session, err := initCLISession(cmd) |
| 535 | if err != nil || session == nil { |
| 536 | return nil, cobra.ShellCompDirectiveError |
| 537 | } |
| 538 | |
| 539 | nodes, err := session.getNodes(context.Background()) |
| 540 | if err != nil { |
| 541 | return nil, cobra.ShellCompDirectiveError |
| 542 | } |
| 543 | |
| 544 | var names []string |
| 545 | |
| 546 | for _, n := range nodes { |
| 547 | if n != nil && strings.HasPrefix(n.Name, toComplete) { |
| 548 | names = append(names, n.Name) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | return names, cobra.ShellCompDirectiveNoFileComp |
| 553 | } |
| 554 | |
| 555 | // completeVMIDs is a Cobra ValidArgsFunction that returns VMID completions |
| 556 | // with the guest name and type as description. Requires no positional args |
no test coverage detected