Added --force flag on node delete (fixes #164)

This commit is contained in:
Juan Font Alonso 2021-10-16 12:30:52 +02:00
parent 52511af8e4
commit be3a379d10
2 changed files with 11 additions and 7 deletions

View file

@ -144,6 +144,8 @@ var deleteNodeCmd = &cobra.Command{
} }
confirm := false confirm := false
force, _ := cmd.Flags().GetBool("force")
if !force {
prompt := &survey.Confirm{ prompt := &survey.Confirm{
Message: fmt.Sprintf("Do you want to remove the node %s?", m.Name), Message: fmt.Sprintf("Do you want to remove the node %s?", m.Name),
} }
@ -151,8 +153,9 @@ var deleteNodeCmd = &cobra.Command{
if err != nil { if err != nil {
return return
} }
}
if confirm { if confirm || force {
err = h.DeleteMachine(m) err = h.DeleteMachine(m)
if strings.HasPrefix(output, "json") { if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node deleted"}, err, output) JsonOutput(map[string]string{"Result": "Node deleted"}, err, output)

View file

@ -9,6 +9,7 @@ import (
func init() { func init() {
rootCmd.PersistentFlags().StringP("output", "o", "", "Output format. Empty for human-readable, 'json' or 'json-line'") rootCmd.PersistentFlags().StringP("output", "o", "", "Output format. Empty for human-readable, 'json' or 'json-line'")
rootCmd.PersistentFlags().Bool("force", false, "Disable prompts and forces the execution")
} }
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{