dynamic nouns for 'wwwctl kernel'

This commit is contained in:
Christian Goll
2021-09-24 14:36:54 +02:00
parent 8010cd2435
commit b3743657b2
3 changed files with 33 additions and 2 deletions

View File

@@ -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
},
}
)

View File

@@ -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.

View File

@@ -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