More use of the cli module.

This commit is contained in:
Dominik Picheta 2016-12-22 16:30:24 +01:00
commit c0f2bd03b1
3 changed files with 28 additions and 18 deletions

View file

@ -321,8 +321,8 @@ proc buildFromDir(pkgInfo: PackageInfo, paths: seq[string], forRelease: bool) =
for path in paths: args.add("--path:\"" & path & "\" ") for path in paths: args.add("--path:\"" & path & "\" ")
for bin in pkgInfo.bin: for bin in pkgInfo.bin:
let outputOpt = "-o:\"" & pkgInfo.getOutputDir(bin) & "\"" let outputOpt = "-o:\"" & pkgInfo.getOutputDir(bin) & "\""
echo("Building ", pkginfo.name, "/", bin, " using ", pkgInfo.backend, display("Building", "$1/$2 using $3 backend" %
" backend...") [pkginfo.name, bin, pkgInfo.backend], priority = HighPriority)
let outputDir = pkgInfo.getOutputDir("") let outputDir = pkgInfo.getOutputDir("")
if not existsDir(outputDir): if not existsDir(outputDir):
@ -362,13 +362,14 @@ proc removePkgDir(dir: string, options: Options) =
if toSeq(walkDirRec(dir)).len == 0: if toSeq(walkDirRec(dir)).len == 0:
removeDir(dir) removeDir(dir)
else: else:
echo("WARNING: Cannot completely remove " & dir & display("Warning:", ("Cannot completely remove $1. Files not installed " &
". Files not installed by nimble are present.") "by nimble are present.") % dir, Warning, HighPriority)
except OSError, JsonParsingError: except OSError, JsonParsingError:
echo("Error: Unable to read nimblemeta.json: ", getCurrentExceptionMsg()) display("Warning", "Unable to read nimblemeta.json: " &
getCurrentExceptionMsg(), Warning, HighPriority)
if not options.prompt("Would you like to COMPLETELY remove ALL files " & if not options.prompt("Would you like to COMPLETELY remove ALL files " &
"in " & dir & "?"): "in " & dir & "?"):
quit(QuitSuccess) raise NimbleQuit(msg: "")
removeDir(dir) removeDir(dir)
proc vcsRevisionInDir(dir: string): string = proc vcsRevisionInDir(dir: string): string =
@ -955,7 +956,8 @@ proc doAction(options: Options) =
createDir(options.getPkgsDir) createDir(options.getPkgsDir)
if not execHook(options, true): if not execHook(options, true):
echo("Pre-hook prevented further execution.") display("Warning", "Pre-hook prevented further execution.", Warning,
HighPriority)
return return
case options.action.typ case options.action.typ
of actionRefresh: of actionRefresh:
@ -996,14 +998,19 @@ proc doAction(options: Options) =
let execResult = execTask(nimbleFile, options.action.command, options) let execResult = execTask(nimbleFile, options.action.command, options)
if not execResult.success: if not execResult.success:
echo("FAILURE: Could not find task ", options.action.command, " in ", writeHelp(false)
nimbleFile)
writeHelp() raise newException(NimbleError, "Could not find task $1 in $2" %
[options.action.command, nimbleFile])
if execResult.command.normalize == "nop": if execResult.command.normalize == "nop":
echo("WARNING: Using `setCommand 'nop'` is not necessary.") display("Warning:", "Using `setCommand 'nop'` is not necessary.", Warning,
HighPriority)
return return
if not execHook(options, false): if not execHook(options, false):
return return
if execResult.hasTaskRequestedCommand(): if execResult.hasTaskRequestedCommand():
var newOptions = initOptions() var newOptions = initOptions()
newOptions.config = options.config newOptions.config = options.config

View file

@ -15,7 +15,7 @@ from compiler/scriptconfig import setupVM
from compiler/astalgo import strTableGet from compiler/astalgo import strTableGet
import compiler/options as compiler_options import compiler/options as compiler_options
import common, version, options, packageinfo import common, version, options, packageinfo, cli
import os, strutils, strtabs, times, osproc, sets import os, strutils, strtabs, times, osproc, sets
when not declared(resetAllModulesHard): when not declared(resetAllModulesHard):
@ -291,7 +291,7 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
if msgs.gErrorCounter > 0: if msgs.gErrorCounter > 0:
raise newException(NimbleError, previousMsg) raise newException(NimbleError, previousMsg)
elif previousMsg.len > 0: elif previousMsg.len > 0:
echo(previousMsg) display("Info", previousMsg, priority = HighPriority)
if output.normalize.startsWith("error"): if output.normalize.startsWith("error"):
raise newException(NimbleError, output) raise newException(NimbleError, output)
previousMsg = output previousMsg = output
@ -367,7 +367,8 @@ proc execTask*(scriptName, taskName: string,
result.success = true result.success = true
result.flags = newStringTable() result.flags = newStringTable()
compiler_options.command = internalCmd compiler_options.command = internalCmd
echo("Executing task ", taskName, " in ", scriptName) display("Executing", "task $# in $#" % [taskName, scriptName],
priority = HighPriority)
let thisModule = execScript(scriptName, result.flags, options) let thisModule = execScript(scriptName, result.flags, options)
let prc = thisModule.tab.strTableGet(getIdent(taskName & "Task")) let prc = thisModule.tab.strTableGet(getIdent(taskName & "Task"))
@ -397,7 +398,8 @@ proc execHook*(scriptName, actionName: string, before: bool,
let hookName = let hookName =
if before: actionName.toLowerAscii & "Before" if before: actionName.toLowerAscii & "Before"
else: actionName.toLowerAscii & "After" else: actionName.toLowerAscii & "After"
echo("Attempting to execute hook ", hookName, " in ", scriptName) display("Attempting", "to execute hook $# in $#" % [hookName, scriptName],
priority = MediumPriority)
let thisModule = execScript(scriptName, result.flags, options) let thisModule = execScript(scriptName, result.flags, options)
# Explicitly execute the task procedure, instead of relying on hack. # Explicitly execute the task procedure, instead of relying on hack.

View file

@ -91,14 +91,15 @@ For more information read the Github readme:
https://github.com/nim-lang/nimble#readme https://github.com/nim-lang/nimble#readme
""" """
proc writeHelp*() = proc writeHelp*(quit=true) =
echo(help) echo(help)
quit(QuitSuccess) if quit:
raise NimbleQuit(msg: "")
proc writeVersion() = proc writeVersion() =
echo("nimble v$# compiled at $# $#" % echo("nimble v$# compiled at $# $#" %
[nimbleVersion, CompileDate, CompileTime]) [nimbleVersion, CompileDate, CompileTime])
quit(QuitSuccess) raise NimbleQuit(msg: "")
proc parseActionType*(action: string): ActionType = proc parseActionType*(action: string): ActionType =
case action.normalize() case action.normalize()