Commits

Mattijs Hoitink committed afba815

Added argument parsing to d

d takes two optional arguments to pass in the source and target directories. The bin/dc
executable has been removed.

Comments (0)

Files changed (2)

 #!/usr/bin/env python
 
-import sys, os
+import sys, os, argparse
 
 # Ugly hack so I can code in peace.
 try:
     from d.base import render_files
 
 if __name__ == '__main__':
-    if len(sys.argv) > 1:
-        sys.stderr.write("d doesn't take any arguments.\n")
-        sys.stderr.write("Just cd into your docs/ directory, run d, and move on.\n")
-        sys.exit(1)
-    else:
-        render_files('.', './build')
+
+    # Argument parser
+    parser = argparse.ArgumentParser(description='Markdown files to documentation. Run and get on with your life.')
+    parser.add_argument('-s', dest='source', default='.', help='Documentation source', metavar='SOURCE')
+    parser.add_argument('-t', dest='target', default='./build', help='Documentation output target', metavar='TARGET')
+
+    args = parser.parse_args()
+
+    # Render with arguments
+    render_files(args.source, args.target)

bin/dc

-#!/usr/bin/env python
-#
-# Configurable version of 'd'. This executable takes two arguments: source and destsination
-#
-
-import sys, os
-
-# Ugly hack so I can code in peace.
-try:
-    from d.base import render_files
-except ImportError:
-    sys.path.append(os.path.abspath(os.path.join(__file__, '..', '..')))
-    from d.base import render_files
-
-if __name__ == '__main__':
-    if len(sys.argv) < 3:
-        sys.stderr.write("dc requires 2 arguments: dc SOURCE DESTINATION\n")
-        sys.exit(1)
-    else:
-        render_files(sys.argv[1], sys.argv[2])