Added version checker on startup

This commit is contained in:
Juan Font Alonso 2021-09-27 16:26:18 +02:00
parent 0bbf343348
commit 2048e9e136
5 changed files with 32 additions and 6 deletions

View file

@ -2,11 +2,12 @@ package cli
import (
"fmt"
"github.com/spf13/cobra"
"strings"
"github.com/spf13/cobra"
)
var version = "dev"
var Version = "dev"
func init() {
rootCmd.AddCommand(versionCmd)
@ -19,9 +20,9 @@ var versionCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
o, _ := cmd.Flags().GetString("output")
if strings.HasPrefix(o, "json") {
JsonOutput(map[string]string{"version": version}, nil, o)
JsonOutput(map[string]string{"version": Version}, nil, o)
return
}
fmt.Println(version)
fmt.Println(Version)
},
}

View file

@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"time"
@ -9,6 +10,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"github.com/tcnksm/go-latest"
)
func main() {
@ -38,6 +40,19 @@ func main() {
NoColor: !colors,
})
githubTag := &latest.GithubTag{
Owner: "juanfont",
Repository: "headscale",
}
if cli.Version != "dev" {
res, _ := latest.Check(githubTag, cli.Version)
if res.Outdated {
fmt.Printf("An updated version of Headscale has been found (%s vs. your current %s). Check it out https://github.com/juanfont/headscale/releases\n",
res.Current, cli.Version)
}
}
err := cli.LoadConfig("")
if err != nil {
log.Fatal().Err(err)