Commits

James Ascroft-Leigh  committed 2ae21a0

Add command line options

  • Participants
  • Parent commits 9111044

Comments (0)

Files changed (1)

File mockserver.py

 
 """
 from flask import Flask, request, json, jsonify, make_response
+import optparse
+import sys
 
 app = Flask(__name__)
 
     return response
 
 
+def main(argv):
+    parser = optparse.OptionParser(__doc__)
+    parser.add_option("--debug", dest="debug", action="store_const",
+                      const=True, default=True)
+    parser.add_option("--no-debug", dest="debug", action="store_const",
+                      const=False, default=True)
+    parser.add_option("--host", dest="host", default="127.0.0.1")
+    parser.add_option("--port", dest="port", type=int, default="5000")
+    options, args = parser.parse_args(argv)
+    if len(args) > 0:
+        parser.error("Unexpected: %r" % (args,))
+    options = eval(str(options))
+    app.run(**options)
+
 if __name__ == "__main__":
-    app.run(debug=True)
+    sys.exit(main(sys.argv[1:]))