weather-cli/cmd/client/advanced.go

58 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func advancedMenu(app *application) {
var option string
for option != "0" {
fmt.Print("\nAdvanced Menu\n-------------\n\n")
2022-07-11 19:07:24 -04:00
fmt.Printf("1. Change units (Default: imperial; Current: %s)\n", app.Config.Units)
fmt.Println("2. Enter precise location")
fmt.Print("0. Back\n\n")
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Println(err)
}
option = strings.TrimSuffix(input, "\n")
if option == "1" {
current := app.Config.Units
if current == "imperial" {
app.Config.Units = "metric"
2022-07-07 23:43:16 -04:00
} else {
app.Config.Units = "imperial"
2022-07-07 23:43:16 -04:00
}
fmt.Printf("\nChanged units from %s to %s...\n\n", current, app.Config.Units)
} else if option == "2" {
var validLoc bool
for !validLoc {
getPreciseLocation(app)
getCurrent(app)
if app.Forecast.Main.Temp != 0.00 {
validLoc = true
} else {
fmt.Println("I couldn't get any information for that location.")
fmt.Println("Are you sure the coordinates are valid?")
}
}
2022-07-09 15:33:10 -04:00
printWeather(app)
}
}
}