2024-09-29 17:20:59 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "yr",
|
2024-10-18 07:28:18 +00:00
|
|
|
Short: "yr is CLI tool for weather forecasts",
|
2024-10-04 21:26:35 +00:00
|
|
|
Run: root,
|
2024-09-29 17:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Execute() {
|
|
|
|
err := rootCmd.Execute()
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-17 14:36:54 +00:00
|
|
|
var (
|
|
|
|
isJson bool
|
|
|
|
isDebug bool
|
|
|
|
isUTC bool
|
|
|
|
isWeb bool
|
|
|
|
lon float64
|
|
|
|
lat float64
|
|
|
|
)
|
|
|
|
|
2024-09-29 17:20:59 +00:00
|
|
|
func init() {
|
2024-10-17 14:36:54 +00:00
|
|
|
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")
|
2024-09-29 17:20:59 +00:00
|
|
|
}
|
2024-10-04 21:26:35 +00:00
|
|
|
|
|
|
|
func root(cmd *cobra.Command, args []string) {
|
|
|
|
if isWeb {
|
|
|
|
openBrowser("https://www.yr.no/en", nil)
|
|
|
|
}
|
|
|
|
|
2024-10-17 14:36:54 +00:00
|
|
|
err := cmd.Help()
|
2024-10-04 21:26:35 +00:00
|
|
|
cobra.CheckErr(err)
|
|
|
|
}
|