Implemented recursive commands.
h3rald h3rald@h3rald.com
Wed, 15 Feb 2017 19:06:46 +0100
4 files changed,
19 insertions(+),
11 deletions(-)
M
lib/config.nim
→
lib/config.nim
@@ -6,7 +6,7 @@ strutils,
logging import - logger + styled_console_logger const cfgfile = "../nifty.nimble".slurp@@ -43,4 +43,4 @@ discard
close(p) else: fatal("Cannot process configuration file.") - quit(2)+ quit(2)
M
lib/logger.nim
→
lib/styled_console_logger.nim
@@ -13,7 +13,7 @@ case level:
of lvlDebug: return ("---", fgMagenta) of lvlInfo: - return ("(i) ", fgCyan) + return ("(i)", fgCyan) of lvlNotice: return ("---", fgGreen) of lvlWarn:@@ -23,7 +23,7 @@ return ("(!)", fgRed)
of lvlFatal: return ("(x)", fgRed) else: - return ("", fgWhite) + return (" ", fgWhite) method log*(logger: StyledConsoleLogger; level: Level; args: varargs[string, `$`]) = var f = stdout
M
lib/project.nim
→
lib/project.nim
@@ -99,10 +99,10 @@ score = params.len
cmd = val return score > 0 -proc execute*(prj: var NiftyProject, command, alias: string) = +proc execute*(prj: var NiftyProject, command, alias: string): int = prj.load if not prj.packages.hasKey alias: - warn "Package definition '$1' not found. Nothing to do." % alias + warn "Package definition '$1' not found within $2. Nothing to do." % [alias, prj.dir] return notice "$1: $2" % [command, alias] let package = prj.packages[alias]@@ -122,8 +122,17 @@ pwd = prj.storage/pwd
notice "Executing: $1" % cmd pwd.createDir() pwd.setCurrentDir() - discard execShellCmd cmd + result = execShellCmd cmd else: warn "Command '$1' not available for package '$2'" % [command, alias] setCurrentDir(prj.dir) +proc executeRec*(prj: var NiftyProject, command, alias: string) = + if (execute(prj, command, alias) != 0): + return + var pwd = getCurrentDir(); + var childProj = newNiftyProject(pwd/prj.storage/alias) + if childProj.configured: + childProj.load() + for key, val in childProj.packages.pairs: + childProj.executeRec(command, key)
M
nifty.nim
→
nifty.nim
@@ -7,7 +7,7 @@ strutils,
sequtils import - lib/logger + lib/styled_console_logger newStyledConsoleLogger().addHandler() setLogFilter(lvlInfo)@@ -36,7 +36,6 @@ --version, -h Displays the version of the application.
--storage, -s Specifies what directory to use for storing packages. """ % [appname, version, appdesc] -var command: string var storage = "packages" var args = newSeq[string](0)@@ -127,6 +126,6 @@ if packages.len == 0:
warn "No packages defined - nothing to do." else: for key, val in prj.packages.pairs: - prj.execute(args[0], key) + prj.executeRec(args[0], key) else: - prj.execute(args[0], args[1]) + prj.executeRec(args[0], args[1])