From 936e49b4e9acd87a77a2bf75a5f4a0100b4824b0 Mon Sep 17 00:00:00 2001 From: Sergey Chizhik Date: Tue, 6 Oct 2015 17:58:10 +0300 Subject: [PATCH] sys > argparse, fix readme --- README.rst | 2 +- httpbin/core.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index c9d2b10..7e8cb19 100644 --- a/README.rst +++ b/README.rst @@ -189,7 +189,7 @@ Or run it directly: .. code:: bash - $ python -m httpbin.core + $ python -m httpbin.core [--port=PORT] [--host=HOST] Changelog --------- diff --git a/httpbin/core.py b/httpbin/core.py index bbac37d..3f53b77 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -13,7 +13,7 @@ import os import random import time import uuid -import sys +import argparse from flask import Flask, Response, request, render_template, redirect, jsonify as flask_jsonify, make_response, url_for from werkzeug.datastructures import WWWAuthenticate, MultiDict @@ -712,4 +712,8 @@ def xml(): if __name__ == '__main__': - app.run(port=int(sys.argv[1]) if (len(sys.argv) > 1) else 5000, host=sys.argv[2] if (len(sys.argv) > 2) else "127.0.0.1") + parser = argparse.ArgumentParser() + parser.add_argument("--port", type=int) + parser.add_argument("--host") + args = parser.parse_args() + app.run(port=args.port if args.port else 5000, host=args.host if args.host else "127.0.0.1")