From b3743657b2a277700f997f830905b8745476b8e6 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 24 Sep 2021 14:36:54 +0200 Subject: [PATCH] dynamic nouns for 'wwwctl kernel' --- internal/app/wwctl/kernel/delete/root.go | 12 +++++++++++- internal/app/wwctl/kernel/imprt/root.go | 5 +++++ internal/app/wwctl/node/delete/root.go | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/internal/app/wwctl/kernel/delete/root.go b/internal/app/wwctl/kernel/delete/root.go index 8295e4b5..4e714b46 100644 --- a/internal/app/wwctl/kernel/delete/root.go +++ b/internal/app/wwctl/kernel/delete/root.go @@ -1,6 +1,9 @@ package delete -import "github.com/spf13/cobra" +import ( + "github.com/hpcng/warewulf/internal/pkg/kernel" + "github.com/spf13/cobra" +) var ( baseCmd = &cobra.Command{ @@ -9,6 +12,13 @@ var ( Long: "This command will delete a kernel that has been imported into Warewulf.", RunE: CobraRunE, Args: cobra.MinimumNArgs(1), + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + list, _ := kernel.ListKernels() + return list, cobra.ShellCompDirectiveNoFileComp + }, } ) diff --git a/internal/app/wwctl/kernel/imprt/root.go b/internal/app/wwctl/kernel/imprt/root.go index 5f97901c..eab31e79 100644 --- a/internal/app/wwctl/kernel/imprt/root.go +++ b/internal/app/wwctl/kernel/imprt/root.go @@ -1,6 +1,7 @@ package imprt import ( + "github.com/hpcng/warewulf/internal/pkg/container" "github.com/spf13/cobra" ) @@ -26,6 +27,10 @@ func init() { baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this kernel for the default profile") baseCmd.PersistentFlags().StringVarP(&OptRoot, "root", "r", "/", "Import kernel from root (chroot) directory") baseCmd.PersistentFlags().StringVarP(&OptContainer, "container", "C", "", "Import kernel from container") + baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + list, _ := container.ListSources() + return list, cobra.ShellCompDirectiveNoFileComp + }) } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/node/delete/root.go b/internal/app/wwctl/node/delete/root.go index c7aa4840..b62664f2 100644 --- a/internal/app/wwctl/node/delete/root.go +++ b/internal/app/wwctl/node/delete/root.go @@ -1,6 +1,9 @@ package delete -import "github.com/spf13/cobra" +import ( + "github.com/hpcng/warewulf/internal/pkg/node" + "github.com/spf13/cobra" +) var ( baseCmd = &cobra.Command{ @@ -10,6 +13,19 @@ var ( Args: cobra.MinimumNArgs(1), RunE: CobraRunE, Aliases: []string{"rm", "del"}, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) != 0 { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + nodeDB, _ := node.New() + nodes, _ := nodeDB.FindAllNodes() + var node_names []string + for _, node := range nodes { + node_names = append(node_names, node.Id.Get()) + } + return node_names, cobra.ShellCompDirectiveNoFileComp + }, } SetYes bool SetForce string