~siegfriedehret/brrr

91de52f695b2a67c1e1a34fd31c1431af5e88055 — Siegfried Ehret 3 years ago 6925af1
🎁 allow to check if installed packages are outdated
3 files changed, 19 insertions(+), 6 deletions(-)

A src/commands/outdated.nim
M src/lib/repository.nim
M src/options.nim
A src/commands/outdated.nim => src/commands/outdated.nim +8 -0
@@ 0,0 1,8 @@
import ../lib/[common, repository, stash, types, utils]

proc outdated*() =
  for pkg in getInstalledPackages():
    let (url, pkgDef) = downloadPackageDefinition(pkg, true)
    let lastVersion = getLastVersion(pkgDef.get_tags)
    if semverCmp(pkg.ver, lastVersion) == -1:
      log($pkg.name & " is outdated (" & pkg.ver & " => " & lastVersion & ")")

M src/lib/repository.nim => src/lib/repository.nim +3 -2
@@ 4,9 4,10 @@ import ./common, ./types, ./utils

const baseUrl = "https://nyrst.github.io/freezer/{brrr_package_name}.yaml"

proc downloadPackageDefinition*(pkg: PkgTuple): (string, BrrrFile) =
proc downloadPackageDefinition*(pkg: PkgTuple, quiet = false): (string, BrrrFile) =
  let url = baseUrl.replace("{brrr_package_name}", pkg.name)
  log("Fetching package definition: " & url)
  if quiet == false:
    log("Fetching package definition: " & url)
  var client = newHttpClient()
  var s = newStringStream(client.getContent(url))
  var brrrFile: BrrrFile

M src/options.nim => src/options.nim +8 -4
@@ 1,14 1,14 @@
import std/[parseopt, strutils]
import commands/[freezer, help, install, uninstall, upgrade, version], lib/types
import commands/[freezer, help, install, outdated, uninstall, upgrade, version], lib/types

# Many lines come from nimble.

type
  ActionType* = enum
    actionNil, actionFreezer, actionHelp, actionInstall, actionUninstall, actionUpgrade, actionVersion
    actionNil, actionFreezer, actionHelp, actionInstall, actionOutdated, actionUninstall, actionUpgrade, actionVersion
  Action* = object
    case typ*: ActionType
    of actionNil, actionHelp, actionVersion: nil
    of actionNil, actionHelp, actionOutdated, actionVersion: nil
    of actionFreezer:
      sub*: string
    of actionInstall, actionUninstall, actionUpgrade:


@@ 24,6 24,8 @@ proc parseActionType*(action: string): ActionType =
    result = actionHelp
  of "install":
    result = actionInstall
  of "outdated":
    result = actionOutdated
  of "uninstall":
    result = actionUninstall
  of "upgrade":


@@ 40,7 42,7 @@ proc parseArgument*(key: string, result: var Options) =
  case result.action.typ
  of actionNil:
    assert false
  of actionHelp, actionVersion:
  of actionHelp, actionOutdated, actionVersion:
    discard
  of actionFreezer:
    result.action.sub = key


@@ 60,6 62,8 @@ proc doAction*(options: var Options) =
      freezer(options.action.sub)
    of actionInstall:
      install(options.action.packages)
    of actionOutdated:
      outdated()
    of actionUninstall:
      uninstall(options.action.packages)
    of actionUpgrade: