76f8b580ce6dc534bc9a02b76e3367cf514a1804 — Thomas Landin 11 months ago f851115
Switch from docopt to argparse

docopt 0.6.8 had several issues compiling under --gc:arc and I don't
want to spend a whole bunch of time fixing issues in my dependencies.
argparse seems like the best alternative in that it compiles fine with
ARC and also makes for some decently clean code.

The one issue is you can't have empty strings as the default value so we
work around that by defaulting [dir] to "nil".
2 files changed, 24 insertions(+), 22 deletions(-)

M dtt.nimble
M src/dtt.nim
M dtt.nimble => dtt.nimble +1 -0
@@ 13,6 13,7 @@ binDir        = "bin"
# Dependencies

requires "nim >= 1.0.4"
requires "argparse"
requires "https://github.com/soasme/nim-markdown >= 0.8"
requires "https://github.com/docopt/docopt.nim >= 0.6"
requires "https://github.com/soasme/nim-mustache >= 0.2"

M src/dtt.nim => src/dtt.nim +23 -22
@@ 3,6 3,7 @@ import unicode, algorithm

import docopt
import mustache
import argparse

import tmpl
import utils

@@ 32,7 33,7 @@ type
    tmpl: string
    title: string

proc initCmd(dir: string, force: bool = false) =
proc init(force: bool = false, dir: string) =
  let wd = if dir == "nil": getCurrentDir() else: getCurrentDir() / dir
  if not existsDir(wd):

@@ 75,7 76,7 @@ proc initCmd(dir: string, force: bool = false) =
  writeFile(wd / output_dir / css_dir / "style.css", tmpl.style)
  setFilePermissions(wd / output_dir / css_dir / "style.css", outFilePerms)

proc buildCmd(posts_per_page: int = 5) =
proc build(posts_per_page: int = 5) =
  var working_dir: string
    working_dir = findBaseDir(os.getCurrentDir())

@@ 137,29 138,29 @@ proc buildCmd(posts_per_page: int = 5) =
      output_file = page.out_path / page.filename
    writeFile(output_file, rendered)

let doc = """

dtt (Do The Thing)

const doc = """
An extremely straight-forward static site generator that will convert
Markdown files into html and publish them along with any static content
(images, CSS, html files, etc.) to an output dir to be served as static
content from any host.

  dtt init [options] [DIR]
  dtt build [options] [POSTS]

  -f --force  Force init to overwrite existing files (if any)
  -h --help   Show this screen.
  --version   Show version.
when isMainModule:
  let args = docopt(doc, version=fmt"{bin} {version}")

  if args["init"]:
    initCmd($args["DIR"], args["--force"])
  elif args["build"]:
    let posts = if args["POSTS"].kind == vkNone: 5 else: parseInt($args["POSTS"])
when isMainModule:
  var argp = newParser(bin):
    flag("-v", "--version")
      if opts.version:
        echo fmt"{bin} {version}"
      help("Initialize a dtt project in the current directory, or [dir] if passed.")
      arg("dir", default="nil")
      flag("-f", "--force")
        init(opts.force, opts.dir)
      help("Construct the site inside the ./output/ directory.")
      arg("posts", default="5")