50 lines
996 B
Go
50 lines
996 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
helper "github.com/home-assistant/cli/client"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var dnsLogsCmd = &cobra.Command{
|
|
Use: "logs",
|
|
Aliases: []string{"log", "lg"},
|
|
Short: "View the log output of the Home Assistant DNS server",
|
|
Long: `
|
|
Allowing you to look at the log output generated by the Home Assistant DNS server.
|
|
`,
|
|
Example: `
|
|
ha dns logs
|
|
`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
log.WithField("args", args).Debug("dns logs")
|
|
|
|
section := "dns"
|
|
command := "logs"
|
|
base := viper.GetString("endpoint")
|
|
|
|
url, err := helper.URLHelper(base, section, command)
|
|
if err != nil {
|
|
fmt.Printf("Error: %v", err)
|
|
return
|
|
}
|
|
|
|
request := helper.GetRequest()
|
|
resp, err := request.SetHeader("Accept", "text/plain").Get(url)
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
ExitWithError = true
|
|
} else {
|
|
fmt.Println(resp.String())
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
dnsCmd.AddCommand(dnsLogsCmd)
|
|
}
|