MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / completeVMIDs

Function completeVMIDs

internal/cli/cli_helpers.go:558–587  ·  view source on GitHub ↗

completeVMIDs is a Cobra ValidArgsFunction that returns VMID completions with the guest name and type as description. Requires no positional args already provided.

(cmd *cobra.Command, args []string, toComplete string)

Source from the content-addressed store, hash-verified

556// with the guest name and type as description. Requires no positional args
557// already provided.
558func completeVMIDs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
559 if len(args) != 0 {
560 return nil, cobra.ShellCompDirectiveNoFileComp
561 }
562
563 session, err := initCLISession(cmd)
564 if err != nil || session == nil {
565 return nil, cobra.ShellCompDirectiveError
566 }
567
568 vms, err := session.getVMs(context.Background())
569 if err != nil {
570 return nil, cobra.ShellCompDirectiveError
571 }
572
573 var completions []string
574
575 for _, vm := range vms {
576 if vm == nil {
577 continue
578 }
579
580 id := fmt.Sprintf("%d", vm.ID)
581 if strings.HasPrefix(id, toComplete) {
582 completions = append(completions, fmt.Sprintf("%s\t%s (%s)", id, vm.Name, vm.Type))
583 }
584 }
585
586 return completions, cobra.ShellCompDirectiveNoFileComp
587}
588
589// addNoWaitFlag adds a --no-wait flag to cmd for task-producing commands.
590func addNoWaitFlag(cmd *cobra.Command) {

Callers

nothing calls this directly

Calls 2

initCLISessionFunction · 0.85
getVMsMethod · 0.80

Tested by

no test coverage detected