yr/cmd/root.go
Tim Hårek Andreassen df389705a0
chore: Shorter descriptions
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
2024-10-18 09:29:07 +02:00

47 lines
1,000 B
Go

package cmd
import (
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "yr",
Short: "yr is CLI tool for weather forecasts",
Run: root,
}
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
var (
isJson bool
isDebug bool
isUTC bool
isWeb bool
lon float64
lat float64
)
func init() {
rootCmd.PersistentFlags().BoolVar(&isJson, "json", false, "Result in JSON")
rootCmd.PersistentFlags().BoolVar(&isDebug, "debug", false, "Display debug info")
rootCmd.PersistentFlags().BoolVar(&isUTC, "utc", false, "Result times in UTC")
rootCmd.PersistentFlags().BoolVar(&isWeb, "web", false, "Open result in browser")
rootCmd.PersistentFlags().Float64VarP(&lon, "lon", "x", 0, "Longitude coordinate")
rootCmd.PersistentFlags().Float64VarP(&lat, "lat", "y", 0, "Latitude coordinate")
}
func root(cmd *cobra.Command, args []string) {
if isWeb {
openBrowser("https://www.yr.no/en", nil)
}
err := cmd.Help()
cobra.CheckErr(err)
}