Move software version handling to a new package

This commit is contained in:
2021-10-04 12:20:16 +10:30
parent 1812486b19
commit 3a65a60fcb
5 changed files with 40 additions and 30 deletions

View File

@@ -10,7 +10,6 @@ import (
daulog "github.com/tardisx/discord-auto-upload/log"
"github.com/mitchellh/go-homedir"
"golang.org/x/mod/semver"
)
// Config for the application
@@ -23,8 +22,6 @@ var Config struct {
Exclude string
}
const CurrentVersion string = "v1.0.0"
// Load the current config or initialise with defaults
func LoadOrInit() {
configPath := configPath()
@@ -77,22 +74,3 @@ func configPath() string {
homeDir := homeDir()
return homeDir + string(os.PathSeparator) + ".dau.json"
}
func NewVersionAvailable(v string) bool {
if !semver.IsValid(CurrentVersion) {
panic(fmt.Sprintf("my current version '%s' is not valid", CurrentVersion))
}
if !semver.IsValid(v) {
// maybe this should just be a warning
log.Printf("passed in version '%s' is not valid - assuming no new version", v)
return false
}
comp := semver.Compare(v, CurrentVersion)
if comp == 0 {
return false
}
if comp == -1 {
return true
}
return false // they are using a newer one than exists?
}

View File

@@ -1,13 +0,0 @@
package config_test
import (
"testing"
"github.com/tardisx/discord-auto-upload/config"
)
func TestVersioning(t *testing.T) {
if !config.NewVersionAvailable("v0.1.0") {
t.Error("should be a version newer than v0.1.0")
}
}