This commit is contained in:
Juan Font Alonso 2021-10-13 23:23:12 +02:00
commit 2ddca366f2
3 changed files with 20 additions and 1 deletions

View file

@ -129,6 +129,7 @@ var deleteNodeCmd = &cobra.Command{
return nil return nil
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")
h, err := getHeadscaleApp() h, err := getHeadscaleApp()
if err != nil { if err != nil {
log.Fatalf("Error initializing: %s", err) log.Fatalf("Error initializing: %s", err)
@ -153,11 +154,19 @@ var deleteNodeCmd = &cobra.Command{
if confirm { if confirm {
err = h.DeleteMachine(m) err = h.DeleteMachine(m)
if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node deleted"}, err, output)
return
}
if err != nil { if err != nil {
log.Fatalf("Error deleting node: %s", err) log.Fatalf("Error deleting node: %s", err)
} }
fmt.Printf("Node deleted\n") fmt.Printf("Node deleted\n")
} else { } else {
if strings.HasPrefix(output, "json") {
JsonOutput(map[string]string{"Result": "Node not deleted"}, err, output)
return
}
fmt.Printf("Node not deleted\n") fmt.Printf("Node not deleted\n")
} }
}, },

View file

@ -262,3 +262,12 @@ func JsonOutput(result interface{}, errResult error, outputFormat string) {
} }
fmt.Println(string(j)) fmt.Println(string(j))
} }
func HasJsonOutputFlag() bool {
for _, arg := range os.Args {
if arg == "json" || arg == "json-line" {
return true
}
}
return false
}

View file

@ -62,7 +62,8 @@ func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel) 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" { if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && cli.Version != "dev" {
githubTag := &latest.GithubTag{ githubTag := &latest.GithubTag{
Owner: "juanfont", Owner: "juanfont",