@@ 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"
@@ 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):
createDir(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
try:
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.
-
-usage:
- dtt init [options] [DIR]
- dtt build [options] [POSTS]
-
-Options:
- -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"])
- buildCmd(posts)
+when isMainModule:
+ var argp = newParser(bin):
+ help(doc)
+ flag("-v", "--version")
+ run:
+ if opts.version:
+ echo fmt"{bin} {version}"
+ command("init"):
+ help("Initialize a dtt project in the current directory, or [dir] if passed.")
+ arg("dir", default="nil")
+ flag("-f", "--force")
+ run:
+ init(opts.force, opts.dir)
+ command("build"):
+ help("Construct the site inside the ./output/ directory.")
+ arg("posts", default="5")
+ run:
+ build(opts.posts.parseInt)
+ argp.run(commandLineParams())