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

Function completeNodeNames

internal/cli/cli_helpers.go:529–553  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

527// completeNodeNames is a Cobra ValidArgsFunction that returns node names for
528// tab completion. It requires no positional args already provided.
529func 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

Callers 2

completeStorageNamesFunction · 0.85
completeTemplateNamesFunction · 0.85

Calls 2

initCLISessionFunction · 0.85
getNodesMethod · 0.80

Tested by

no test coverage detected