weather-cli/cmd/menu.go

72 lines
1.6 KiB
Go
Raw Normal View History

2022-08-02 22:15:35 -04:00
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
2022-08-02 23:26:28 -04:00
func mainMenu(app *Application) {
2022-08-02 22:15:35 -04:00
// Display main menu
fmt.Println("\n=====================================================")
fmt.Printf("| Welcome to the OpenWeatherMap-gRPC Client! v%s |\n", app.Version)
fmt.Println("=====================================================")
fmt.Printf("New in version %s:\n", app.Version)
2022-08-06 22:23:13 -04:00
fmt.Println(" - Advanced option: 'Get historical data' fully functional")
fmt.Println("New in version 0.2.0")
fmt.Println(" - Added gRPC back end for historical data")
fmt.Println(" - Option to search historical data added to UI")
2022-08-02 22:15:35 -04:00
mainMenuLoop(app)
}
// Display main menu and get user input
func mainMenuLoop(app *Application) {
2022-08-02 22:15:35 -04:00
var option string
for option != "0" {
fmt.Print("\nMain Menu\n---------\n\n")
fmt.Println("1. Use current location (default)")
fmt.Println("2. Search by zip code")
fmt.Println("3. Search by city")
fmt.Println("4. Advanced options")
2022-08-02 22:15:35 -04:00
fmt.Print("0. Exit\n\n")
// Read user input
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Println(err)
}
option = strings.TrimSuffix(input, "\n")
switch option {
case "":
getLocation(app)
getCurrent(app)
printWeather(app)
case "1":
2022-08-02 22:15:35 -04:00
getLocation(app)
getCurrent(app)
printWeather(app)
case "2":
getZip(app)
getCurrentByLoc(app)
printWeather(app)
case "3":
getCity(app)
getCurrentByLoc(app)
printWeather(app)
case "4":
2022-08-02 22:15:35 -04:00
advancedMenu(app)
case "0":
2022-08-02 22:15:35 -04:00
return
default:
2022-08-02 22:15:35 -04:00
fmt.Print("\nOops! An error occurred, please choose a valid option.\n\n")
}
}
}