feat: Open yr.no on yr --web

Implements: https://todo.sr.ht/~timharek/yr/3
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-10-04 23:26:35 +02:00
parent 437f7f5f9a
commit 687d3e8be7
No known key found for this signature in database
GPG key ID: E59C7734F0E10EB5
2 changed files with 17 additions and 1 deletions

View file

@ -66,7 +66,10 @@ func forecastHelper(cmd *cobra.Command, args []string) *forecastH {
// Opens u in browser with added coordinates and exits
func openBrowser(u string, f *yr.ForecastResult) {
url := fmt.Sprintf(u, f.Coordinates.Latitude, f.Coordinates.Longitude)
url := u
if f != nil {
url = fmt.Sprintf(u, f.Coordinates.Latitude, f.Coordinates.Longitude)
}
err := browser.OpenURL(url)
cobra.CheckErr(err)
os.Exit(0)

View file

@ -11,6 +11,7 @@ var rootCmd = &cobra.Command{
Use: "yr",
Short: "Get the weather for your desired location.",
Long: `Get the weather for your desired location.`,
Run: root,
}
func Execute() {
@ -28,3 +29,15 @@ func init() {
rootCmd.PersistentFlags().Float64P(flags.LON, "x", 0, "Longitude coordinate")
rootCmd.PersistentFlags().Float64P(flags.LAT, "y", 0, "Latitude coordinate")
}
func root(cmd *cobra.Command, args []string) {
isWeb, err := cmd.Flags().GetBool(flags.WEB)
cobra.CheckErr(err)
if isWeb {
openBrowser("https://www.yr.no/en", nil)
}
err = cmd.Help()
cobra.CheckErr(err)
}