Files
warewulf/internal/app/wwctl/node/delete/main.go
Christian Goll 0e6223b6f8 do not confirm deleting zero nodes
close #603

Signed-off-by: Christian Goll <cgoll@suse.de>
2022-12-22 14:48:58 +01:00

38 lines
881 B
Go

package delete
import (
"fmt"
apiNode "github.com/hpcng/warewulf/internal/pkg/api/node"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/api/util"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
ndp := wwapiv1.NodeDeleteParameter{
Force: SetForce,
NodeNames: args,
}
if !SetYes {
var nodeList []node.NodeInfo
// The checks run twice in the prompt case.
// Avoiding putting in a blocking prompt in an API.
nodeList, err = apiNode.NodeDeleteParameterCheck(&ndp, false)
if err != nil {
return
}
if len(nodeList) == 0 {
return
}
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to delete %d nodes(s)", len(nodeList)))
if !yes {
return
}
}
return apiNode.NodeDelete(&ndp)
}