More replacements of 'echo' to CLI's 'display'.

This commit is contained in:
Dominik Picheta 2016-12-21 00:08:42 +01:00
commit e3f833d61c
2 changed files with 18 additions and 15 deletions

View file

@ -469,12 +469,13 @@ proc installFromDir(dir: string, latest: bool, options: Options,
# TODO: Verify that we are removing an old bin of this package, not # TODO: Verify that we are removing an old bin of this package, not
# some other package's binary! # some other package's binary!
if existsFile(binDir / cleanBin): removeFile(binDir / cleanBin) if existsFile(binDir / cleanBin): removeFile(binDir / cleanBin)
echo("Creating symlink: ", pkgDestDir / bin, " -> ", binDir / cleanBin) display("Creating", "symlink: $1 -> $2" %
[pkgDestDir / bin, binDir / cleanBin], priority = MediumPriority)
createSymlink(pkgDestDir / bin, binDir / cleanBin) createSymlink(pkgDestDir / bin, binDir / cleanBin)
elif defined(windows): elif defined(windows):
# There is a bug on XP, described here: # There is a bug on XP, described here:
# http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called # http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called
# But this workaround brokes code page on newer systems, so we need to detect OS version # But this workaround brakes code page on newer systems, so we need to detect OS version
var osver = OSVERSIONINFO() var osver = OSVERSIONINFO()
osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO)) osver.dwOSVersionInfoSize = cast[DWORD](sizeof(OSVERSIONINFO))
if GetVersionExA(osver) == WINBOOL(0): if GetVersionExA(osver) == WINBOOL(0):
@ -483,7 +484,8 @@ proc installFromDir(dir: string, latest: bool, options: Options,
let fixChcp = osver.dwMajorVersion <= 5 let fixChcp = osver.dwMajorVersion <= 5
let dest = binDir / cleanBin.changeFileExt("cmd") let dest = binDir / cleanBin.changeFileExt("cmd")
echo("Creating stub: ", pkgDestDir / bin, " -> ", dest) display("Creating", "stub: $1 -> $2" % [pkgDestDir / bin, dest],
priority = MediumPriority)
var contents = "@" var contents = "@"
if options.config.chcp: if options.config.chcp:
if fixChcp: if fixChcp:
@ -493,7 +495,8 @@ proc installFromDir(dir: string, latest: bool, options: Options,
writeFile(dest, contents) writeFile(dest, contents)
# For bash on Windows (Cygwin/Git bash). # For bash on Windows (Cygwin/Git bash).
let bashDest = dest.changeFileExt("") let bashDest = dest.changeFileExt("")
echo("Creating Cygwin stub: ", pkgDestDir / bin, " -> ", bashDest) display("Creating", "Cygwin stub: $1 -> $2" %
[pkgDestDir / bin, bashDest], priority = MediumPriority)
writeFile(bashDest, "\"" & pkgDestDir / bin & "\" \"$@\"\n") writeFile(bashDest, "\"" & pkgDestDir / bin & "\" \"$@\"\n")
else: else:
{.error: "Sorry, your platform is not supported.".} {.error: "Sorry, your platform is not supported.".}
@ -514,7 +517,7 @@ proc installFromDir(dir: string, latest: bool, options: Options,
result.paths.add pkgDestDir result.paths.add pkgDestDir
result.pkg = pkgInfo result.pkg = pkgInfo
echo(pkgInfo.name & " installed successfully.") display(pkgInfo.name, " installed successfully.", priority = HighPriority)
proc getNimbleTempDir(): string = proc getNimbleTempDir(): string =
## Returns a path to a temporary directory. ## Returns a path to a temporary directory.
@ -552,8 +555,8 @@ proc downloadPkg(url: string, verRange: VersionRange,
if modUrl.contains("github.com") and modUrl.endswith("/"): if modUrl.contains("github.com") and modUrl.endswith("/"):
modUrl = modUrl[0 .. ^2] modUrl = modUrl[0 .. ^2]
echo("Downloading ", modUrl, " into ", downloadDir, " using ", display("Downloading", "$1 using $2" % [modUrl, $downMethod],
downMethod, "...") priority = HighPriority)
result = ( result = (
downloadDir, downloadDir,
doDownload(modUrl, downloadDir, verRange, downMethod, options) doDownload(modUrl, downloadDir, verRange, downMethod, options)
@ -595,7 +598,7 @@ proc install(packages: seq[PkgTuple],
"internet?"): "internet?"):
refresh(options) refresh(options)
else: else:
quit("Please run nimble refresh.", QuitFailure) raise newException(NimbleError, "Please run nimble refresh.")
# Install each package. # Install each package.
for pv in packages: for pv in packages:
@ -650,8 +653,8 @@ proc compile(options: Options) =
if bin == "": if bin == "":
raise newException(NimbleError, "You need to specify a file to compile.") raise newException(NimbleError, "You need to specify a file to compile.")
echo("Compiling ", bin, " (", pkgInfo.name, ") using ", backend, display("Compiling", "$1 ($2) using $3 backend" % [bin, pkgInfo.name, backend],
" backend...") priority = HighPriority)
doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# \"$#\"" % doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# \"$#\"" %
[backend, args, bin]) [backend, args, bin])
@ -686,7 +689,7 @@ proc search(options: Options) =
onFound() onFound()
if not found: if not found:
echo("No package found.") display("Error", "No package found.", Error, HighPriority)
proc list(options: Options) = proc list(options: Options) =
if needsRefresh(options): if needsRefresh(options):

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, sets, tables import parsecfg, json, streams, strutils, parseutils, os, sets, tables
import version, tools, common, options import version, tools, common, options, cli
type type
Package* = object Package* = object
@ -138,7 +138,7 @@ proc getPackage*(pkg: string, options: Options,
## convenience the proc returns a boolean specifying if the ``resPkg`` was ## convenience the proc returns a boolean specifying if the ``resPkg`` was
## successfully filled with good data. ## successfully filled with good data.
for name, list in options.config.packageLists: for name, list in options.config.packageLists:
echo("Searching in \"", name, "\" package list...") display("Reading", "$1 package list" % name, priority = LowPriority)
let packages = parseFile(options.getNimbleDir() / let packages = parseFile(options.getNimbleDir() /
"packages_" & name.toLowerAscii() & ".json") "packages_" & name.toLowerAscii() & ".json")
for p in packages: for p in packages:
@ -178,8 +178,8 @@ proc findNimbleFile*(dir: string; error: bool): string =
raise newException(NimbleError, raise newException(NimbleError,
"Specified directory does not contain a .nimble file.") "Specified directory does not contain a .nimble file.")
else: else:
# TODO: Abstract logging. display("Warning", "No .nimble file found for " & dir, Warning,
echo("WARNING: No .nimble file found for ", dir) HighPriority)
proc getInstalledPkgsMin*(libsDir: string, options: Options): proc getInstalledPkgsMin*(libsDir: string, options: Options):
seq[tuple[pkginfo: PackageInfo, meta: MetaData]] = seq[tuple[pkginfo: PackageInfo, meta: MetaData]] =