package main

import (
	"fmt"

	"github.com/spf13/cobra"
)

// healthCmd checks server health
var healthCmd = &cobra.Command{
	Use:   "health",
	Short: "Check server health",
	Run: func(cmd *cobra.Command, args []string) {
		client := NewClient(cliConfig)
		checkHealth(client)
	},
}

func checkHealth(client *Client) {
	resp, err := client.Get("/health")
	checkError(err)
	defer resp.Body.Close()

	var result map[string]string
	checkError(decodeJSON(resp, &result))

	fmt.Printf("Server status: %s\n", result["status"])
}
