Skip to content

Commit

Permalink
Merge pull request #155 from juanfont/fix-json-delete-node
Browse files Browse the repository at this point in the history
Add JSON output when deleting node
  • Loading branch information
juanfont authored Oct 13, 2021
2 parents dd1e425 + 6924b7b commit 70ae18c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var deleteNodeCmd = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")
h, err := getHeadscaleApp()
if err != nil {
log.Fatalf("Error initializing: %s", err)
Expand All @@ -153,11 +154,19 @@ var deleteNodeCmd = &cobra.Command{

if confirm {
err = h.DeleteMachine(m)
if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node deleted"}, err, output)
return
}
if err != nil {
log.Fatalf("Error deleting node: %s", err)
}
fmt.Printf("Node deleted\n")
} else {
if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node not deleted"}, err, output)
return
}
fmt.Printf("Node not deleted\n")
}
},
Expand Down

0 comments on commit 70ae18c

Please sign in to comment.