Files
warewulf/internal/app/wwctl/node/delete/main.go
Ian Kaneshiro 846b45524c Tidy up
- Ran goimports to format code and imports
- Removed unused module from go.mod
- Added .editorconfig to keep formatting standard across contributors
2021-02-16 11:54:12 -08:00

53 lines
924 B
Go

package delete
import (
"fmt"
"os"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
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 {
err := nodeDB.DelNode(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
}