add confirmation for wwctl container delete

close #606

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2022-12-22 15:00:12 +01:00
parent 9539e20a4e
commit 718064e671
2 changed files with 16 additions and 6 deletions

View File

@@ -1,15 +1,24 @@
package delete
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/api/container"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/api/util"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
cdp := &wwapiv1.ContainerDeleteParameter{
ContainerNames: args,
}
if !SetYes {
yes := util.ConfirmationPrompt(fmt.Sprintf("Are you sure you want to container %s", args))
if !yes {
return
}
}
return container.ContainerDelete(cdp)
}

View File

@@ -8,10 +8,10 @@ import (
var (
baseCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Use: "delete [OPTIONS] CONTAINER [...]",
Short: "Delete an imported container",
Long: "This command will delete CONTAINERs that have been imported into Warewulf.",
RunE: CobraRunE,
Use: "delete [OPTIONS] CONTAINER [...]",
Short: "Delete an imported container",
Long: "This command will delete CONTAINERs that have been imported into Warewulf.",
RunE: CobraRunE,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
@@ -20,10 +20,11 @@ var (
return list, cobra.ShellCompDirectiveNoFileComp
},
}
SetYes bool
)
func init() {
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
}
// GetRootCommand returns the root cobra.Command for the application.