Files
warewulf/internal/app/wwctl/profile/set/root.go
Christian Goll 457c7c16b1 wwctl commands without NodeInfo
mostly remove Get and calls for the id

Signed-off-by: Christian Goll <cgoll@suse.com>
2024-10-17 13:35:42 -04:00

82 lines
2.7 KiB
Go

package set
import (
"log"
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/container"
"github.com/warewulf/warewulf/internal/pkg/kernel"
"github.com/warewulf/warewulf/internal/pkg/node"
"github.com/warewulf/warewulf/internal/pkg/overlay"
)
type variables struct {
setNetDevDel string
setDiskDel string
setPartDel string
setFsDel string
setNodeAll bool
setYes bool
setForce bool
partName string
diskName string
fsName string
profileConf node.NodeConf
profileDel node.NodeConfDel
profileAdd node.NodeConfAdd
}
func GetCommand() *cobra.Command {
vars := variables{}
vars.profileConf = node.NewNode("")
baseCmd := &cobra.Command{
Use: "set [OPTIONS] [PROFILE ...]",
Short: "Configure node profile properties",
Long: "This command sets configuration properties for the node PROFILE(s).\n\n" +
"Note: use the string 'UNSET' to remove a configuration",
Aliases: []string{"modify"},
Args: cobra.MinimumNArgs(0),
RunE: CobraRunE(&vars),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
nodeDB, _ := node.New()
profiles := nodeDB.ListAllProfiles()
return profiles, cobra.ShellCompDirectiveNoFileComp
},
}
vars.profileConf.CreateFlags(baseCmd)
vars.profileDel.CreateDelFlags(baseCmd)
vars.profileAdd.CreateAddFlags(baseCmd)
baseCmd.PersistentFlags().BoolVarP(&vars.setYes, "yes", "y", false, "Set 'yes' to all questions asked")
// register the command line completions
if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, _ := container.ListSources()
return list, cobra.ShellCompDirectiveNoFileComp
}); err != nil {
log.Println(err)
}
if err := baseCmd.RegisterFlagCompletionFunc("kerneloverride", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, _ := kernel.ListKernels()
return list, cobra.ShellCompDirectiveNoFileComp
}); err != nil {
log.Println(err)
}
if err := baseCmd.RegisterFlagCompletionFunc("runtime", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
}); err != nil {
log.Println(err)
}
if err := baseCmd.RegisterFlagCompletionFunc("wwinit", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
}); err != nil {
log.Println(err)
}
return baseCmd
}