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

Function completeTemplateNames

internal/cli/storage.go:849–888  ·  view source on GitHub ↗

completeTemplateNames is a ValidArgsFunction for in storage download template. It requires node (args[0]) and storage (args[1]) to already be present.

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

Source from the content-addressed store, hash-verified

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.
849func completeTemplateNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
850 if len(args) < 1 {
851 return completeNodeNames(cmd, args, toComplete)
852 }
853
854 if len(args) < 2 {
855 return completeStorageNames(cmd, args, toComplete)
856 }
857
858 nodeName := args[0]
859
860 session, err := initCLISession(cmd)
861 if err != nil || session == nil {
862 return nil, cobra.ShellCompDirectiveError
863 }
864
865 client, err := session.clientForNode(context.Background(), nodeName)
866 if err != nil {
867 return nil, cobra.ShellCompDirectiveError
868 }
869
870 templates, err := client.GetAvailableTemplates(nodeName)
871 if err != nil {
872 return nil, cobra.ShellCompDirectiveError
873 }
874
875 seen := make(map[string]bool)
876 var names []string
877
878 for _, t := range templates {
879 if strings.HasPrefix(t.Filename, toComplete) && !seen[t.Filename] {
880 seen[t.Filename] = true
881 names = append(names, t.Filename)
882 }
883 }
884
885 sort.Strings(names)
886
887 return names, cobra.ShellCompDirectiveNoFileComp
888}

Callers

nothing calls this directly

Calls 5

completeNodeNamesFunction · 0.85
completeStorageNamesFunction · 0.85
initCLISessionFunction · 0.85
clientForNodeMethod · 0.80
GetAvailableTemplatesMethod · 0.80

Tested by

no test coverage detected