Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/juanfont/headscale into main
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Oct 13, 2021
2 parents 9a6ac6e + 809a5b8 commit 2ddca36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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
9 changes: 9 additions & 0 deletions cmd/headscale/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,12 @@ func JsonOutput(result interface{}, errResult error, outputFormat string) {
}
fmt.Println(string(j))
}

func HasJsonOutputFlag() bool {
for _, arg := range os.Args {
if arg == "json" || arg == "json-line" {
return true
}
}
return false
}
3 changes: 2 additions & 1 deletion cmd/headscale/headscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}

if !viper.GetBool("disable_check_updates") {
jsonOutput := cli.HasJsonOutputFlag()
if !viper.GetBool("disable_check_updates") && !jsonOutput {
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && cli.Version != "dev" {
githubTag := &latest.GithubTag{
Owner: "juanfont",
Expand Down

0 comments on commit 2ddca36

Please sign in to comment.