Implemented remove command for files as well.
h3rald h3rald@h3rald.com
Thu, 16 Feb 2017 20:27:52 +0100
2 files changed,
20 insertions(+),
8 deletions(-)
M
lib/project.nim
→
lib/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.nim
→
nifty.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