Skip to content

Commit

Permalink
Add min_version option
Browse files Browse the repository at this point in the history
  • Loading branch information
A.A.Abroskin committed Jul 12, 2019
1 parent 93ec8a5 commit af087b0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -57,6 +58,7 @@ const (
tagsConfigKey string = "tags"
pipedConfigKey string = "piped"
excludeTagsConfigKey string = "exclude_tags"
minVersionConfigKey string = "min_version"
execMode os.FileMode = 0751
)

Expand Down Expand Up @@ -88,6 +90,10 @@ func RunCmdExecutor(args []string, fs afero.Fs) error {
if os.Getenv("LEFTHOOK") == "0" {
return nil
}
if !isVersionOk() {
log.Println(au.Brown("Config error! Current Lefhook version lower than config version or 'min_version' incorrect, check format: '0.6.0'"))
return errors.New("Current Lefhook version lower than config version or 'min_version' incorrect")
}
if tags := os.Getenv("LEFTHOOK_EXCLUDE"); tags != "" {
envExcludeTags = append(envExcludeTags, strings.Split(tags, ",")[:]...)
}
Expand Down Expand Up @@ -503,3 +509,29 @@ func makeExecutable(path string) {
log.Fatal(err)
}
}

func isVersionOk() bool {
if !viper.IsSet(minVersionConfigKey) {
return true
}

configVersion := viper.GetString(minVersionConfigKey)

configVersionSplited := strings.Split(configVersion, ".")
if len(configVersionSplited) != 3 {
VerbosePrint("Config min_version option have incorrect format")
return false
}

currentVersionSplited := strings.Split(version, ".")

for i, value := range currentVersionSplited {
currentNum, _ := strconv.ParseInt(value, 0, 64)
configNum, _ := strconv.ParseInt(configVersionSplited[i], 0, 64)
if currentNum < configNum {
return false
}
}

return true
}

0 comments on commit af087b0

Please sign in to comment.