~siegfriedehret/brrr

6925af163db07d95b7aefd62c8a395c85d3415e1 — Siegfried Ehret 2 years ago b623b3c
🎁 allow to upgrade a package (less stupid version)
3 files changed, 18 insertions(+), 7 deletions(-)

M src/commands/install.nim
M src/commands/uninstall.nim
M src/commands/upgrade.nim
M src/commands/install.nim => src/commands/install.nim +1 -1
@@ 34,7 34,7 @@ proc runScripts(pkgDef: BrrrFile, packageVersion,
    let logs = execCmdEx(runScript, workingDir = getPackageDir(pkgDef.name))
    log(logs[0], 2)

proc installPackage(pkg: PkgTuple, pkgDef: BrrrFile): string =
proc installPackage*(pkg: PkgTuple, pkgDef: BrrrFile): string =
  if pkg.ver != star:
    result = pkg.ver
  else:

M src/commands/uninstall.nim => src/commands/uninstall.nim +1 -1
@@ 13,7 13,7 @@ proc runScripts(pkgDef: BrrrFile, packageVersion,
    let logs = execCmdEx(runScript, workingDir = getPackageDir(pkgDef.name))
    log(logs[0], 2)

proc uninstallPackage(pkg: PkgTuple, pkgDef: BrrrFile,
proc uninstallPackage*(pkg: PkgTuple, pkgDef: BrrrFile,
    installedVersion: string) =
  let hasVersion = pkgDef.versions.hasKey(installedVersion)
  let hasStarVersion = pkgDef.versions.hasKey(star)

M src/commands/upgrade.nim => src/commands/upgrade.nim +16 -5
@@ 1,8 1,19 @@
import ./install, ./uninstall, ../lib/[common, stash, types]
import std/[times]
import ./install, ./uninstall, ../lib/[common, repository, stash, types, utils]

proc upgrade*(packages: seq[PkgTuple]) =
  for pkg in getInstalledPackages():
    # TODO only if new version available
    uninstall(pkg)
    let nextPkg: PkgTuple = (name: pkg.name, ver: star)
    install(nextPkg)
    let (url, pkgDef) = downloadPackageDefinition(pkg)
    let lastVersion = getLastVersion(pkgDef.get_tags)
    if semverCmp(pkg.ver, lastVersion) == -1:
      let timeStart = now()

      uninstallPackage(pkg, pkgDef, pkg.ver)
      let nextPkg: PkgTuple = (name: pkg.name, ver: star)
      let version = installPackage(nextPkg, pkgDef)
      addPackageToConfig(pkg.name, version, url)

      let timeEnd = now()
      let duration = timeEnd - timeStart
      log($pkg.name & "@" & version & " upgraded successfully (" & $duration & ")")