package cmd import ( "fmt" "io" "log" "net/http" "github.com/spf13/cobra" ) var moonCmd = &cobra.Command{ Use: "moon", Short: "Check out the current moon phase", Run: func(cmd *cobra.Command, args []string) { query := "https://wttr.in/" + "moon" + "?" + format resp, err := http.Get(query) if err != nil { log.Fatal(err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s", body) }, } func init() { rootCmd.AddCommand(moonCmd) }