diff options
Diffstat (limited to 'lib/bisect.nim')
-rw-r--r-- | lib/bisect.nim | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/lib/bisect.nim b/lib/bisect.nim index 55d5a60..ea4063c 100644 --- a/lib/bisect.nim +++ b/lib/bisect.nim @@ -1,4 +1,4 @@ -import future, os, osproc, re, strutils +import future, osproc, strutils {.passL: "-lalpm".} @@ -14,36 +14,33 @@ proc getSourceVersion(relativePath: string): seq[string] = else: @[] -let params = commandLineParams() -let compareMethod = params[0] -let relativePath = params[1] -let compareVersion = params[2] +proc handleBisect*(params: seq[string]): int = + let compareMethod = params[0] + let relativePath = params[1] + let compareVersion = params[2] -let (currentVersion, supported) = if compareMethod == "source": - (getSourceVersion(relativePath), true) - else: - (@[], false) - -if not supported: - programResult = 255 -elif currentVersion.len != 3: - programResult = 125 -else: - let epoch = currentVersion[0].strip - let pkgver = currentVersion[1].strip - let pkgrel = currentVersion[2].strip - - if pkgver.len == 0 or pkgrel.len == 0: - programResult = 125 + let (currentVersion, supported) = if compareMethod == "source": + (getSourceVersion(relativePath), true) + else: + (@[], false) + + if not supported: + 255 + elif currentVersion.len != 3: + 125 else: - let version = if epoch.len > 0: - epoch & ":" & pkgver & "-" & pkgrel - else: - pkgver & "-" & pkgrel - - # this output is required by main program - echo(version) - if vercmp(compareVersion, version) > 0: - programResult = 0 + let epoch = currentVersion[0].strip + let pkgver = currentVersion[1].strip + let pkgrel = currentVersion[2].strip + + if pkgver.len == 0 or pkgrel.len == 0: + 125 else: - programResult = 1 + let version = if epoch.len > 0: + epoch & ":" & pkgver & "-" & pkgrel + else: + pkgver & "-" & pkgrel + + # this output is required by main program + echo(version) + if vercmp(compareVersion, version) > 0: 0 else: 1 |