about summary refs log tree commit diff
path: root/strike.py
diff options
context:
space:
mode:
Diffstat (limited to 'strike.py')
-rwxr-xr-xstrike.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/strike.py b/strike.py
index 93c62f4..dfcb2ed 100755
--- a/strike.py
+++ b/strike.py
@@ -1,33 +1,32 @@
 #!/usr/bin/env python3
 from os import listdir, mkdir
 from sys import exit
-import argparse
+from argparse import ArgumentParser
+
+def handle_args():
+    parser = ArgumentParser()
+    parser.add_argument('--input', '-i', help='input directory (default "blog")', default='blog')
+    parser.add_argument('--output', '-o', help='output directory (default "output")', default='output')
+    parser.add_argument('--template', '-t', help='template to use (default "template")', default='template')
+    return parser.parse_args()
 
 def get_output(content, template="{content}"):
     return template.format(content = content)
 
 def main():
-    parser = argparse.ArgumentParser()
-    parser.add_argument('--input', '-i', help='input directory (default "blog")', default='blog')
-    parser.add_argument('--output', '-o', help='output directory (default "output")', default='output')
-    parser.add_argument('--template', '-t', help='template to use (default "template"', default='template')
-    args = parser.parse_args()
-
-    src = args.input
+    args = handle_args()
 
-    dest = args.output
-    try: mkdir(dest)
+    try: mkdir(args.output)
     except FileExistsError: pass
 
-    template = args.template
-    with open(template) as t:
+    with open(args.template) as t:
         template_contents = t.read()
 
-    for file in listdir(src):
-        with open(src + '/' + file, 'r') as fin:
+    for file in listdir(args.input):
+        with open(args.input + '/' + file, 'r') as fin:
             file_contents = fin.read()
         output = get_output(file_contents, template=template_contents)
-        with open(dest + '/' + file, 'w') as fout:
+        with open(args.output + '/' + file, 'w') as fout:
             fout.write(output)
 
 if __name__ == '__main__':