Implemented list command.
h3rald h3rald@h3rald.com
Sun, 18 Mar 2018 10:26:30 +0100
2 files changed,
30 insertions(+),
18 deletions(-)
M
lib/project.nim
→
lib/project.nim
@@ -13,6 +13,9 @@ storage*: string
commands*: JsonNode packages*: JsonNode + +const niftyTpl = "nifty.json".slurp + let placeholder = peg"'{{' {[^}]+} '}}'" proc newNiftyProject*(dir: string): NiftyProject =@@ -27,23 +30,7 @@
proc init*(prj: var NiftyProject, storage: string) = prj.storage = storage createDir(prj.dir/prj.storage) - var o = newJObject() - o["storage"] = %prj.storage - o["commands"] = newJObject() - o["commands"]["install"] = newJObject() - o["commands"]["install"]["git+src"] = newJObject() - o["commands"]["install"]["git+src"]["cmd"] = %"git clone {{src}} --depth 1" - o["commands"]["install"]["git+src+tag"] = newJObject() - o["commands"]["install"]["git+src+tag"]["cmd"] = %"git clone --branch {{tag}} {{src}} --depth 1" - o["commands"]["install"]["curl+src+name"] = newJObject() - o["commands"]["install"]["curl+src+name"]["cmd"] = %"curl {{src}} -o {{name}}" - o["commands"]["update"] = newJObject() - o["commands"]["update"]["git+name"] = newJObject() - o["commands"]["update"]["git+name"]["cmd"] = %"git pull" - o["commands"]["update"]["git+name"]["pwd"] = %"{{name}}" - o["commands"]["update"]["curl+src+name"] = newJObject() - o["commands"]["update"]["curl+src+name"]["cmd"] = %"curl {{src}} -o {{name}}" - o["packages"] = newJObject() + var o = %*(niftyTpl % [prj.storage]) prj.configFile.writeFile(o.pretty) proc load*(prj: var NiftyProject) =
M
nifty.nim
→
nifty.nim
@@ -1,7 +1,8 @@
import json, os, - parseopt2, + ospaths, + parseopt, logging, strutils, sequtils@@ -21,7 +22,15 @@ NiftyOption = object
key: string val: JsonNode +when defined(windows): + proc putchr*(c: cint): cint {.discardable, header: "<conio.h>", importc: "_putch".} +else: + proc putchr*(c: cint) = + stdout.write(c.chr) + + let usage* = """ $1 v$2 - $3 + (c) 2017-2018 Fabio Cevasco Commands: init [--storage:<dir>] Initializes a project in the current directory. map <package> [--<property>:<value>] Defines <package> with the specified properties.@@ -93,6 +102,16 @@ opts.add NiftyOption(key: key, val: v)
else: discard +proc walkPkgs(prj: NiftyProject, dir: string, level = 1) = + for k, v in prj.packages.pairs: + echo " ".repeat(level*2) & "-" & " " & k + var d = dir / prj.storage / k + var p = newNiftyProject(d) + if p.configured: + p.load + walkPkgs(p, d, level+1) + + var prj = newNiftyProject(getCurrentDir()) if args.len == 0:@@ -126,6 +145,12 @@ for key, val in prj.packages.pairs:
confirmAndRemovePackage(prj.storage/key) else: confirmAndRemovePackage(prj.storage/args[1]) + of "list": + prj.load + let pwd = getCurrentDir() + let parts = pwd.split(DirSep) + echo parts[parts.len-1] + walkPkgs(prj, pwd) else: if args.len < 1: echo usage