diff --git a/aiohttp/web.py b/aiohttp/web.py index 27149cb2052..3c4cf5fc859 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -349,7 +349,7 @@ def main(argv): type=int, default="8080" ) - args, extra_args = arg_parser.parse_known_args(argv) + args, extra_argv = arg_parser.parse_known_args(argv) # Import logic mod_str, _, func_str = args.entry_func.partition(":") @@ -368,9 +368,9 @@ def main(argv): except AttributeError: arg_parser.error("module %r has no attribute %r" % (mod_str, func_str)) - app = func(extra_args) + app = func(extra_argv) run_app(app, host=args.hostname, port=args.port) arg_parser.exit(message="Stopped\n") if __name__ == "__main__": - main(sys.argv) + main(sys.argv[1:]) diff --git a/docs/web.rst b/docs/web.rst index cbf877f7c6c..1286af81d66 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -52,13 +52,13 @@ Command Line Interface (CLI) :mod:`aiohttp.web` implements a basic CLI for quickly serving an :class:`Application` in *development* over TCP/IP:: - $ python -m aiohttp.web -H localhost -P 8080 package.module.init_func + $ python -m aiohttp.web -H localhost -P 8080 package.module:init_func ``package.module.init_func`` should be an importable :term:`callable` that accepts a list of any non-parsed command-line arguments and returns an :class:`Application` instance after setting it up:: - def init_function(args): + def init_function(argv): app = web.Application() app.router.add_route("GET", "/", index_handler) return app diff --git a/examples/web_app.py b/examples/cli_app.py similarity index 84% rename from examples/web_app.py rename to examples/cli_app.py index 8eeebaf5cd5..a853e9c6840 100644 --- a/examples/web_app.py +++ b/examples/cli_app.py @@ -3,13 +3,13 @@ Serve this app using:: - $ python -m aiohttp.web -H localhost -P 8080 --repeat 10 web_app.init \ + $ python -m aiohttp.web -H localhost -P 8080 --repeat 10 cli_app:init \ > "Hello World" Here ``--repeat`` & ``"Hello World"`` are application specific command-line arguments. `aiohttp.web` only parses & consumes the command-line arguments it needs (i.e. ``-H``, ``-P`` & ``entry-func``) and passes on any additional -arguments to the `web_app.init` function for processing. +arguments to the `cli_app:init` function for processing. """ from aiohttp.web import Application, Response @@ -22,7 +22,7 @@ def display_message(req): return Response(text=text) -def init(args): +def init(argv): arg_parser = ArgumentParser( prog="aiohttp.web ...", description="Application CLI", add_help=False ) @@ -45,10 +45,10 @@ def init(args): help="show this message and exit", action="help" ) - parsed_args = arg_parser.parse_args(args) + args = arg_parser.parse_args(argv) app = Application() - app["args"] = parsed_args + app["args"] = args app.router.add_route('GET', '/', display_message) return app