afba81586593

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.
[view raw] [browse files]
author Mattijs Hoitink <mattijs@monkeyandmachine.com>
date Tue, 14 Feb 2012 19:17:30 +0100
parents 5e48c681a070
children fc54225e8b51
branches/tags (none)
files bin/d bin/dc

Changes

--- a/bin/d	Tue Feb 07 21:10:22 2012 +0100
+++ b/bin/d	Tue Feb 14 19:17:30 2012 +0100
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import sys, os
+import sys, os, argparse
 
 # Ugly hack so I can code in peace.
 try:
@@ -10,9 +10,13 @@
     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)
--- a/bin/dc	Tue Feb 07 21:10:22 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#!/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])