Merge branch 'main' into main

This commit is contained in:
Kristoffer Dalby 2021-09-28 11:20:31 +01:00 committed by GitHub
commit 0393ab524c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 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,7 +1,9 @@
package main
import (
"fmt"
"os"
"runtime"
"time"
"github.com/efekarakus/termcolor"
@ -9,6 +11,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"github.com/tcnksm/go-latest"
)
func main() {
@ -59,5 +62,19 @@ func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if !viper.GetBool("disable_check_updates") {
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && cli.Version != "dev" {
githubTag := &latest.GithubTag{
Owner: "juanfont",
Repository: "headscale",
}
res, err := latest.Check(githubTag, cli.Version)
if err == nil && 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)
}
}
}
cli.Execute()
}