Skip to content

Commit

Permalink
Added --force flag on node delete (fixes #164)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Oct 16, 2021
1 parent 52511af commit be3a379
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,18 @@ var deleteNodeCmd = &cobra.Command{
}

confirm := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("Do you want to remove the node %s?", m.Name),
}
err = survey.AskOne(prompt, &confirm)
if err != nil {
return
force, _ := cmd.Flags().GetBool("force")
if !force {
prompt := &survey.Confirm{
Message: fmt.Sprintf("Do you want to remove the node %s?", m.Name),
}
err = survey.AskOne(prompt, &confirm)
if err != nil {
return
}
}

if confirm {
if confirm || force {
err = h.DeleteMachine(m)
if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node deleted"}, err, output)
Expand Down
1 change: 1 addition & 0 deletions cmd/headscale/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func init() {
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{
Expand Down

0 comments on commit be3a379

Please sign in to comment.