mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-11-08 05:50:51 -05:00
Move main menu to separate file
This commit is contained in:
parent
0cea4f3e5c
commit
5dd913e1ec
1 changed files with 55 additions and 0 deletions
55
cmd/menu.go
Normal file
55
cmd/menu.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func mainMenu(app *application) {
|
||||
|
||||
// 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)
|
||||
fmt.Println(" - Advanced option: Get historical data back to 1972")
|
||||
fmt.Println("New in version 0.1.0")
|
||||
fmt.Println(" - Default option: Automatically determine location")
|
||||
fmt.Println(" - Advanced option: Enter exact location for anywhere in the world")
|
||||
fmt.Println(" - Advanced option: Change back and forth between imperial and metric units of measurement")
|
||||
|
||||
var option string
|
||||
// Menu loop
|
||||
for option != "0" {
|
||||
fmt.Print("\nMain Menu\n---------\n\n")
|
||||
fmt.Println("1. Today's forecast (use current location, default)")
|
||||
fmt.Println("2. Advanced options (Change units, precise location, etc.)")
|
||||
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")
|
||||
|
||||
// Check user input
|
||||
if option == "1" || option == "" {
|
||||
getLocation(app)
|
||||
getCurrent(app)
|
||||
printWeather(app)
|
||||
} else if option == "2" {
|
||||
advancedMenu(app)
|
||||
} else if option == "0" {
|
||||
return
|
||||
} else {
|
||||
fmt.Print("\nOops! An error occurred, please choose a valid option.\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue