all repos — nifty @ 65ae39f4204471e2bd1d9e2d71a1061cac830310

A tiny (pseudo) package manager and script runner.

Implemented remove command for files as well.
h3rald h3rald@h3rald.com
Thu, 16 Feb 2017 20:27:52 +0100
commit

65ae39f4204471e2bd1d9e2d71a1061cac830310

parent

58b959c66daf67e446129653fd9bb37f76439c4a

2 files changed, 20 insertions(+), 8 deletions(-)

jump to
M lib/project.nimlib/project.nim

@@ -30,18 +30,19 @@ createDir(prj.dir/prj.storage)

var o = newJObject() o["storage"] = %prj.storage o["commands"] = newJObject() - o["commands"]["get"] = newJObject() - o["commands"]["get"]["curl+src+name"] = newJObject() - o["commands"]["get"]["curl+src+name"]["cmd"] = %"curl {{src}} -o {{name}}" 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() prj.configFile.writeFile(o.pretty)
M nifty.nimnifty.nim

@@ -47,13 +47,24 @@ for o in opts:

result[o.key] = o.val proc confirmAndRemoveDir(dir: string) = - if not dirExists(dir): - warn "Directory '$1' does not exist - nothing to do." % dir - return warn "Delete directory '$1' and all its contents? [y/n]" % dir let answer = stdin.readLine.toLowerAscii[0] if answer == 'y': dir.removeDir() + +proc confirmAndRemoveFile(file: string) = + warn "Delete file '$1'? [y/n]" % file + let answer = stdin.readLine.toLowerAscii[0] + if answer == 'y': + file.removeFile() + +proc confirmAndRemovePackage(pkg: string) = + if pkg.fileExists(): + pkg.confirmAndRemoveFile() + elif pkg.dirExists(): + pkg.confirmAndRemoveDir() + else: + warn "Package '$1' not found." % pkg for kind, key, val in getopt(): case kind:

@@ -112,9 +123,9 @@ if packages.len == 0:

warn "No packages defined - nothing to do." else: for key, val in prj.packages.pairs: - confirmAndRemoveDir(prj.storage/key) + confirmAndRemovePackage(prj.storage/key) else: - confirmAndRemoveDir(prj.storage/args[1]) + confirmAndRemovePackage(prj.storage/args[1]) else: if args.len < 1: echo usage