~kungtotte/dtt

2116941db311ce390784e4e97681432c67e173e9 — Thomas Landin 4 months ago 7409928
Add -f/--force switch to dtt init

Now it won't init in a non-empty directory unless you force it to by
using the switches. Also fixed the bug where it wouldn't actually create
the directory you supplied via [DIR]...
2 files changed, 25 insertions(+), 6 deletions(-)

M dtt.nimble
M src/dtt.nim
M dtt.nimble => dtt.nimble +1 -1
@@ 1,6 1,6 @@
# Package

version       = "0.1.0"
version       = "0.1.1"
author        = "Thomas Landin"
description   = "A straight-forward Markdown/Html static site generator."
license       = "GPL-3.0"

M src/dtt.nim => src/dtt.nim +24 -5
@@ 15,13 15,31 @@ const
  output_dir = "output"

let
  version = "0.1.0"
  version = "0.1.1"


proc initCmd(dir: string) =
proc initCmd(dir: string, force: bool = false) =
  var wd: string = dir
  if dir == "nil":
    wd = os.getCurrentDir()
  else:
    os.createDir(os.getCurrentDir() / dir)

  if not force:
    if os.existsDir(wd):
      for f in walkDirRec(wd, {pcFile, pcDir}, relative = true):
        case getFileInfo(wd / f).kind:
          of pcDir:
            if os.existsDir(wd / f):
              stderr.writeLine(fmt"{bin}: working directory not empty, add -f/--force to overwrite")
              quit(4)
          of pcFile:
            if os.existsFile(wd / f):
              stderr.writeLine(fmt"{bin}: working directory not empty, add -f/--force to overwrite")
              quit(4)
          else:
            stderr.writeLine(fmt"Unknown error occurred: {f} is neither file nor directory")
            quit(3)

  if os.existsDir(wd):
    try:


@@ 120,11 138,12 @@ Markdown files into html and publish them along with any static content
content from any host.

usage:
  dtt init [DIR]
  dtt build
  dtt init [options] [DIR]
  dtt build [options]
  dtt clean

Options:
  -f --force  Force init to overwrite existing files (if any)
  -h --help   Show this screen.
  --version   Show version.
"""


@@ 132,7 151,7 @@ when isMainModule:
  let args = docopt(doc, version=fmt"{bin} {version}")

  if args["init"]:
    initCmd($args["DIR"])
    initCmd($args["DIR"], args["--force"])
  elif args["clean"]:
    cleanCmd()
  elif args["build"]: