687d3e8be7
Implements: https://todo.sr.ht/~timharek/yr/3 Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
43 lines
1,023 B
Go
43 lines
1,023 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.sr.ht/~timharek/yr/cmd/flags"
|
|
"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.`,
|
|
Run: root,
|
|
}
|
|
|
|
func Execute() {
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.PersistentFlags().Bool(flags.JSON, false, "Result in JSON")
|
|
rootCmd.PersistentFlags().Bool(flags.DEBUG, false, "Display debug info")
|
|
rootCmd.PersistentFlags().Bool(flags.UTC, false, "Result times in UTC")
|
|
rootCmd.PersistentFlags().Bool(flags.WEB, false, "Open result in browser")
|
|
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)
|
|
}
|