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:
parent
437f7f5f9a
commit
687d3e8be7
2 changed files with 17 additions and 1 deletions
|
@ -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)
|
||||
|
|
13
cmd/root.go
13
cmd/root.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue