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 bin in pkgInfo.bin:
let outputOpt = "-o:\"" & pkgInfo.getOutputDir(bin) & "\""
echo("Building ", pkginfo.name, "/", bin, " using ", pkgInfo.backend,
" backend...")
display("Building", "$1/$2 using $3 backend" %
[pkginfo.name, bin, pkgInfo.backend], priority = HighPriority)
let outputDir = pkgInfo.getOutputDir("")
if not existsDir(outputDir):
@ -362,13 +362,14 @@ proc removePkgDir(dir: string, options: Options) =
if toSeq(walkDirRec(dir)).len == 0:
removeDir(dir)
else:
echo("WARNING: Cannot completely remove " & dir &
". Files not installed by nimble are present.")
display("Warning:", ("Cannot completely remove $1. Files not installed " &
"by nimble are present.") % dir, Warning, HighPriority)
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 " &
"in " & dir & "?"):
quit(QuitSuccess)
raise NimbleQuit(msg: "")
removeDir(dir)
proc vcsRevisionInDir(dir: string): string =
@ -955,7 +956,8 @@ proc doAction(options: Options) =
createDir(options.getPkgsDir)
if not execHook(options, true):
echo("Pre-hook prevented further execution.")
display("Warning", "Pre-hook prevented further execution.", Warning,
HighPriority)
return
case options.action.typ
of actionRefresh:
@ -996,14 +998,19 @@ proc doAction(options: Options) =
let execResult = execTask(nimbleFile, options.action.command, options)
if not execResult.success:
echo("FAILURE: Could not find task ", options.action.command, " in ",
nimbleFile)
writeHelp()
writeHelp(false)
raise newException(NimbleError, "Could not find task $1 in $2" %
[options.action.command, nimbleFile])
if execResult.command.normalize == "nop":
echo("WARNING: Using `setCommand 'nop'` is not necessary.")
display("Warning:", "Using `setCommand 'nop'` is not necessary.", Warning,
HighPriority)
return
if not execHook(options, false):
return
if execResult.hasTaskRequestedCommand():
var newOptions = initOptions()
newOptions.config = options.config

View file

@ -15,7 +15,7 @@ from compiler/scriptconfig import setupVM
from compiler/astalgo import strTableGet
import compiler/options as compiler_options
import common, version, options, packageinfo
import common, version, options, packageinfo, cli
import os, strutils, strtabs, times, osproc, sets
when not declared(resetAllModulesHard):
@ -291,7 +291,7 @@ proc readPackageInfoFromNims*(scriptName: string, options: Options,
if msgs.gErrorCounter > 0:
raise newException(NimbleError, previousMsg)
elif previousMsg.len > 0:
echo(previousMsg)
display("Info", previousMsg, priority = HighPriority)
if output.normalize.startsWith("error"):
raise newException(NimbleError, output)
previousMsg = output
@ -367,7 +367,8 @@ proc execTask*(scriptName, taskName: string,
result.success = true
result.flags = newStringTable()
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 prc = thisModule.tab.strTableGet(getIdent(taskName & "Task"))
@ -397,7 +398,8 @@ proc execHook*(scriptName, actionName: string, before: bool,
let hookName =
if before: actionName.toLowerAscii & "Before"
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)
# 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
"""
proc writeHelp*() =
proc writeHelp*(quit=true) =
echo(help)
quit(QuitSuccess)
if quit:
raise NimbleQuit(msg: "")
proc writeVersion() =
echo("nimble v$# compiled at $# $#" %
[nimbleVersion, CompileDate, CompileTime])
quit(QuitSuccess)
raise NimbleQuit(msg: "")
proc parseActionType*(action: string): ActionType =
case action.normalize()