mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Added basic and some advanced menu options
This commit is contained in:
parent
089c69c642
commit
9e8e00e915
3 changed files with 91 additions and 11 deletions
40
cmd/client/advancedMenu.go
Normal file
40
cmd/client/advancedMenu.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func advancedMenu(wg *sync.WaitGroup) {
|
||||
|
||||
var option string
|
||||
|
||||
for option != "0" {
|
||||
|
||||
fmt.Print("\nAdvanced Menu\n-------------\n\n")
|
||||
|
||||
fmt.Println("1. Change units (Fahrenheit/Celsius)")
|
||||
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.Fatal(err)
|
||||
}
|
||||
|
||||
option = strings.TrimSuffix(input, "\n")
|
||||
|
||||
if option == "1" {
|
||||
fmt.Print("\nChanged units...\n\n")
|
||||
} else if option == "2" {
|
||||
fmt.Print("Precise location selected...\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}
|
51
cmd/client/main.go
Normal file
51
cmd/client/main.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var option string
|
||||
var wg sync.WaitGroup
|
||||
|
||||
fmt.Println("\n==============================================")
|
||||
fmt.Println("| Welcome to the OpenWeatherMap-gRPC Client! |")
|
||||
fmt.Print("==============================================\n")
|
||||
|
||||
for option != "0" {
|
||||
|
||||
fmt.Print("\nMain Menu\n---------\n\n")
|
||||
|
||||
fmt.Println("1. Today's forecast (use current location)")
|
||||
fmt.Println("2. Advanced options")
|
||||
fmt.Print("0. Exit\n\n")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
input, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
option = strings.TrimSuffix(input, "\n")
|
||||
|
||||
if option == "1" {
|
||||
fmt.Println("Option 1 selected...")
|
||||
} else if option == "2" {
|
||||
wg.Add(1)
|
||||
go advancedMenu(&wg)
|
||||
wg.Wait()
|
||||
} else if option == "0" {
|
||||
return
|
||||
} else {
|
||||
fmt.Print("\nOops! An error occurred, please choose a valid option.\n\n")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package main
|
||||
|
||||
import "flag"
|
||||
|
||||
func main() {
|
||||
|
||||
var mode string
|
||||
flag.StringVar(&mode, "mode", "client", "Specify \"client\" or \"server\" mode")
|
||||
flag.Parse()
|
||||
|
||||
}
|
Loading…
Reference in a new issue