nmhive.py: Add --debug option
[nmhive.git] / nmhive.py
index 06c2cd0c90889d0d876292969e703c5f7e54502f..b05aa89d7f100f2779cd724f53aa0d419dbef177 100755 (executable)
--- a/nmhive.py
+++ b/nmhive.py
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 
+"""Serve a JSON API for getting/setting notmuch tags with nmbug commits."""
+
 import json
 import mailbox
 import os
@@ -45,6 +47,8 @@ def _message_tags(message):
 def message_id_tags(message_id):
     if flask.request.method == 'POST':
         changes = flask.request.get_json()
+        if not changes:
+            return flask.Response(status=400)
         database = notmuch.Database(
             path=NOTMUCH_PATH,
             mode=notmuch.Database.MODE.READ_WRITE)
@@ -99,4 +103,20 @@ def gmane_message_id(group, article):
 
 
 if __name__ == '__main__':
-    app.run(host='0.0.0.0')
+    import argparse
+
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument(
+        '-H', '--host', default='127.0.0.1',
+        help='The hostname to listen on.')
+    parser.add_argument(
+        '-p', '--port', type=int, default=5000,
+        help='The port to listen on.')
+    parser.add_argument(
+        '-d', '--debug', type=bool, default=False,
+        help='Run Flask in debug mode (e.g. show errors).')
+
+    args = parser.parse_args()
+
+    app.debug = args.debug
+    app.run(host=args.host, port=args.port)