From 6924b7bf4c4b6b24d697d38a0f35ed244979c12e Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Tue, 12 Oct 2021 23:48:08 +0200 Subject: [PATCH] Output json when deleting node (fixes #152) --- cmd/headscale/cli/nodes.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 5f30dc1..c01bce9 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -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) @@ -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") } },