* added the additional type flag, which can be bool,IP * UNDEF is recognized for the bool flag * 0.0.0.0 must be used as UNDEF for IP flag Signed-off-by: Christian Goll <cgoll@suse.de>
74 lines
2.7 KiB
Go
74 lines
2.7 KiB
Go
package add
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/hpcng/warewulf/internal/pkg/container"
|
|
"github.com/hpcng/warewulf/internal/pkg/kernel"
|
|
"github.com/hpcng/warewulf/internal/pkg/node"
|
|
"github.com/hpcng/warewulf/internal/pkg/overlay"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Holds the variables which are needed in CobraRunE
|
|
type variables struct {
|
|
netName string
|
|
nodeConf node.NodeConf
|
|
converters []func()
|
|
}
|
|
|
|
// Returns the newly created command
|
|
func GetCommand() *cobra.Command {
|
|
vars := variables{}
|
|
vars.nodeConf = node.NewConf()
|
|
baseCmd := &cobra.Command{
|
|
DisableFlagsInUseLine: true,
|
|
Use: "add [OPTIONS] NODENAME",
|
|
Short: "Add new node to Warewulf",
|
|
Long: "This command will add a new node named NODENAME to Warewulf.",
|
|
RunE: CobraRunE(&vars),
|
|
Args: cobra.MinimumNArgs(1),
|
|
}
|
|
vars.converters = vars.nodeConf.CreateFlags(baseCmd, []string{"tagdel", "nettagdel", "ipmitagdel"})
|
|
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "", "Set network name for network options")
|
|
// 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)
|
|
}
|
|
if err := baseCmd.RegisterFlagCompletionFunc("profile", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
var list []string
|
|
nodeDB, _ := node.New()
|
|
profiles, _ := nodeDB.FindAllProfiles()
|
|
for _, profile := range profiles {
|
|
list = append(list, profile.Id.Get())
|
|
}
|
|
return list, cobra.ShellCompDirectiveNoFileComp
|
|
}); err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
// GetRootCommand returns the root cobra.Command for the application.
|
|
return baseCmd
|
|
}
|