2024-09-29 17:20:59 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2024-10-03 16:53:14 +00:00
|
|
|
"git.sr.ht/~timharek/yr/cmd/flags"
|
2024-09-29 17:20:59 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "yr",
|
|
|
|
Short: "Get the weather for your desired location.",
|
|
|
|
Long: `Get the weather for your desired location.`,
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2024-10-02 13:47:49 +00:00
|
|
|
rootCmd.PersistentFlags().Bool(flags.JSON, false, "Result in JSON")
|
2024-10-04 21:19:20 +00:00
|
|
|
rootCmd.PersistentFlags().Bool(flags.DEBUG, false, "Display debug info")
|
2024-10-02 18:54:36 +00:00
|
|
|
rootCmd.PersistentFlags().Bool(flags.UTC, false, "Result times in UTC")
|
2024-10-03 14:05:18 +00:00
|
|
|
rootCmd.PersistentFlags().Bool(flags.WEB, false, "Open result in browser")
|
2024-10-02 13:47:49 +00:00
|
|
|
rootCmd.PersistentFlags().Float64P(flags.LON, "x", 0, "Longitude coordinate")
|
|
|
|
rootCmd.PersistentFlags().Float64P(flags.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) {
|
|
|
|
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)
|
|
|
|
}
|