Made package mapping more interactive.
h3rald h3rald@h3rald.com
Sun, 18 Mar 2018 13:53:14 +0100
2 files changed,
33 insertions(+),
21 deletions(-)
M
lib/project.nim
→
lib/project.nim
@@ -30,7 +30,7 @@
proc init*(prj: var NiftyProject, storage: string) = prj.storage = storage createDir(prj.dir/prj.storage) - var o = %*(niftyTpl % [prj.storage]) + var o = parseJson(niftyTpl % [prj.storage]) prj.configFile.writeFile(o.pretty) proc load*(prj: var NiftyProject) =@@ -71,7 +71,7 @@ else:
notice "Updating package definition '$1'..." % alias for key, val in props.pairs: prj.packages[alias][key] = val - notice " $1 = $2" % [key, $val] + notice " $1: $2" % [key, $val] prj.save notice "Package definition '$1' saved." % alias
M
nifty.nim
→
nifty.nim
@@ -19,11 +19,6 @@ import
lib/config, lib/project -type - NiftyOption = object - key: string - val: JsonNode - when defined(windows): proc putchr*(c: cint): cint {.discardable, header: "<conio.h>", importc: "_putch".} else:@@ -39,6 +34,29 @@ if answer.match(peg"^ i'y' / i'yes' $"):
return true return false +proc addProperty(): tuple[key: string, value: JsonNode] = + var done = false + while (not done): + stdout.setForegroundColor(fgBlue) + stdout.write(" -> Name: ") + resetAttributes() + result.key = stdin.readLine + stdout.setForegroundColor(fgBlue) + stdout.write(" -> Value: ") + resetAttributes() + try: + result.value = %*stdin.readLine + except: + warn("Invalid value; please enter a valid JSON value.") + done = confirm("OK?") + +proc addProperties(obj: var JsonNode) = + var done = false + while (not done): + let prop = addProperty() + obj[prop.key] = prop.value + done = not confirm("Do you want to add more properties?") + proc changeValue(oldv: tuple[label: string, value: JsonNode], newv: tuple[label: string, value: JsonNode]): bool = if oldv.value != newJNull(): stdout.setForegroundColor(fgRed)@@ -68,12 +86,6 @@ --version, -h Displays the version of the application.
""" % [appname, version, appdesc] var args = newSeq[string](0) -var opts = newSeq[NiftyOption](0) - -proc `%`(opts: seq[NiftyOption]): JsonNode = - result = newJObject() - for o in opts: - result[o.key] = o.val proc confirmAndRemoveDir(dir: string) = warn "Delete directory '$1' and all its contents? [y/n]" % dir@@ -111,12 +123,7 @@ of "version", "v":
echo version quit(0) else: - var v: JsonNode - if val == "true" or val == "": - v = %true - else: - v = %val - opts.add NiftyOption(key: key, val: v) + discard else: discard@@ -184,12 +191,17 @@ of "map":
if args.len < 2: fatal "No package alias specified." quit(3) - prj.map(args[1], %opts) + notice "Mapping package alias: " & args[1] + warn "Specify properties for alias '$1':" % [args[1]] + var props = newJObject() + addProperties(props) + prj.map(args[1], %props) of "unmap": if args.len < 2: fatal "No package alias specified." quit(3) - prj.unmap(args[1]) + if confirm("Remove mapping for package alias '$1'?" % args[1]): + prj.unmap(args[1]) of "remove": prj.load if args.len < 2: