package delete import ( "fmt" "github.com/hpcng/warewulf/internal/pkg/node" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/manifoldco/promptui" "github.com/spf13/cobra" "os" ) func CobraRunE(cmd *cobra.Command, args []string) error { var count int nodeDB, err := node.New() if err != nil { wwlog.Printf(wwlog.ERROR, "Failed to open node database: %s\n", err) os.Exit(1) } nodeList, err := nodeDB.SearchByNameList(args) for _, n := range nodeList { if SetGroup != "" && SetGroup != n.Gid.String() { wwlog.Printf(wwlog.DEBUG, "skipping node of different group: %s/%s\n", n.Gid, n.Id) continue } err := nodeDB.DelNode(n.Cid.Get(), n.Gid.Get(), n.Id.Get()) if err != nil { wwlog.Printf(wwlog.ERROR, "%s\n", err) } else { count++ } } if count > 0 { q := fmt.Sprintf("Are you sure you want to delete %d nodes(s)", count) prompt := promptui.Prompt{ Label: q, IsConfirm: true, } result, _ := prompt.Run() if result == "y" || result == "yes" { nodeDB.Persist() } } else { fmt.Printf("No nodes found\n") } return nil }