diff options
author | kitsunyan | 2018-06-09 21:52:58 +0000 |
---|---|---|
committer | kitsunyan | 2018-06-09 21:52:58 +0000 |
commit | 4e6a207ce3d764f73ce3294723c263e38d9b68d3 (patch) | |
tree | 4ce825423e15ad74cd3a29fbfca119c6ab8d2b3e /lib/bisect.nim | |
parent | 7accdb6dab38f0ecb49669b7ddc04dc4f5facd14 (diff) |
Refactor tools
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 |