Use CLI in packageparser.

This commit is contained in:
Dominik Picheta 2016-12-20 23:25:56 +01:00
commit c16c0b8864

View file

@ -1,7 +1,7 @@
# Copyright (C) Dominik Picheta. All rights reserved. # Copyright (C) Dominik Picheta. All rights reserved.
# BSD License. Look at license.txt for more info. # BSD License. Look at license.txt for more info.
import parsecfg, json, streams, strutils, parseutils, os, tables import parsecfg, json, streams, strutils, parseutils, os, tables
import version, tools, common, nimscriptsupport, options, packageinfo import version, tools, common, nimscriptsupport, options, packageinfo, cli
## Contains procedures for parsing .nimble files. Moved here from ``packageinfo`` ## Contains procedures for parsing .nimble files. Moved here from ``packageinfo``
## because it depends on ``nimscriptsupport`` (``nimscriptsupport`` also ## because it depends on ``nimscriptsupport`` (``nimscriptsupport`` also
@ -20,11 +20,7 @@ proc newValidationError(msg: string, warnInstalled: bool): ref ValidationError =
result.warnInstalled = warnInstalled result.warnInstalled = warnInstalled
proc raiseNewValidationError(msg: string, warnInstalled: bool) = proc raiseNewValidationError(msg: string, warnInstalled: bool) =
if warnInstalled: raise newValidationError(msg, warnInstalled)
# TODO: We warn everywhere for now. Raise the error in the next version.
echo("WARNING: ", msg, ". Will be an error in next version!")
else:
raise newValidationError(msg, warnInstalled)
proc validatePackageName*(name: string) = proc validatePackageName*(name: string) =
## Raises an error if specified package name contains invalid characters. ## Raises an error if specified package name contains invalid characters.
@ -242,6 +238,14 @@ proc getInstalledPkgs*(libsDir: string, options: Options):
## Gets a list of installed packages. ## Gets a list of installed packages.
## ##
## ``libsDir`` is in most cases: ~/.nimble/pkgs/ ## ``libsDir`` is in most cases: ~/.nimble/pkgs/
const
readErrorMsg = "Package installation for $1 v$2 is outdated or corrupt."
validationErrorMsg = readErrorMsg & "\nPackage did not pass validation: $3"
proc createErrorMsg(tmplt, path, msg: string): string =
let (name, version) = getNameVersion(path)
return tmplt % [name, version, msg]
result = @[] result = @[]
for kind, path in walkDir(libsDir): for kind, path in walkDir(libsDir):
if kind == pcDir: if kind == pcDir:
@ -254,17 +258,15 @@ proc getInstalledPkgs*(libsDir: string, options: Options):
result.add((pkg, meta)) result.add((pkg, meta))
except ValidationError: except ValidationError:
let exc = (ref ValidationError)(getCurrentException()) let exc = (ref ValidationError)(getCurrentException())
exc.msg = createErrorMsg(validationErrorMsg, path, exc.msg)
if exc.warnInstalled: if exc.warnInstalled:
echo("WARNING: Unable to read package info for " & path & "\n" & display("Warning", exc.msg, Warning, HighPriority)
" Package did not pass validation: " & exc.msg)
else: else:
exc.msg = "Unable to read package info for " & path & "\n" &
" Package did not pass validation: " & exc.msg
raise exc raise exc
except: except:
let exc = getCurrentException() let exc = getCurrentException()
exc.msg = "Unable to read package info for " & path & "\n" & let tmplt = readErrorMsg & "\nMore info: $3"
" Error: " & exc.msg exc.msg = createErrorMsg(tmplt, path, exc.msg)
raise exc raise exc
proc isNimScript*(nf: string, options: Options): bool = proc isNimScript*(nf: string, options: Options): bool =