|
19 | 19 | __version__ = '0.14-dev' |
20 | 20 | __license__ = 'MIT' |
21 | 21 |
|
22 | | -############################################################################### |
23 | | -# Command-line interface ###################################################### |
24 | | -############################################################################### |
25 | | -# INFO: Some server adapters need to monkey-patch std-lib modules before they |
26 | | -# are imported. This is why some of the command-line handling is done here, but |
27 | | -# the actual call to _main() is at the end of the file. |
28 | | - |
29 | | - |
30 | | -def _cli_parse(args): # pragma: no coverage |
31 | | - from argparse import ArgumentParser |
32 | | - |
33 | | - parser = ArgumentParser(prog=args[0], usage="%(prog)s [options] package.module:app") |
34 | | - opt = parser.add_argument |
35 | | - opt("--version", action="store_true", help="show version number.") |
36 | | - opt("-b", "--bind", metavar="ADDRESS", help="bind socket to ADDRESS.") |
37 | | - opt("-s", "--server", default='wsgiref', help="use SERVER as backend.") |
38 | | - opt("-p", "--plugin", action="append", help="install additional plugin/s.") |
39 | | - opt("-c", "--conf", action="append", metavar="FILE", |
40 | | - help="load config values from FILE.") |
41 | | - opt("-C", "--param", action="append", metavar="NAME=VALUE", |
42 | | - help="override config values.") |
43 | | - opt("--debug", action="store_true", help="start server in debug mode.") |
44 | | - opt("--reload", action="store_true", help="auto-reload on file changes.") |
45 | | - opt('app', help='WSGI app entry point.', nargs='?') |
46 | | - |
47 | | - cli_args = parser.parse_args(args[1:]) |
48 | | - |
49 | | - return cli_args, parser |
50 | | - |
51 | | - |
52 | | -def _cli_patch(cli_args): # pragma: no coverage |
53 | | - parsed_args, _ = _cli_parse(cli_args) |
54 | | - opts = parsed_args |
55 | | - if opts.server: |
56 | | - if opts.server.startswith('gevent'): |
57 | | - import gevent.monkey |
58 | | - gevent.monkey.patch_all() |
59 | | - elif opts.server.startswith('eventlet'): |
60 | | - import eventlet |
61 | | - eventlet.monkey_patch() |
62 | | - |
63 | | - |
64 | | -if __name__ == '__main__': |
65 | | - _cli_patch(sys.argv) |
66 | | - |
67 | 22 | ############################################################################### |
68 | 23 | # Imports and Helpers used everywhere else ##################################### |
69 | 24 | ############################################################################### |
@@ -4526,6 +4481,31 @@ def wrapper(*args, **kwargs): |
4526 | 4481 | ext = _ImportRedirect('bottle.ext' if __name__ == '__main__' else |
4527 | 4482 | __name__ + ".ext", 'bottle_%s').module |
4528 | 4483 |
|
| 4484 | +############################################################################### |
| 4485 | +# Command-line interface ###################################################### |
| 4486 | +############################################################################### |
| 4487 | + |
| 4488 | +def _cli_parse(args): # pragma: no coverage |
| 4489 | + from argparse import ArgumentParser |
| 4490 | + |
| 4491 | + parser = ArgumentParser(prog=args[0], usage="%(prog)s [options] package.module:app") |
| 4492 | + opt = parser.add_argument |
| 4493 | + opt("--version", action="store_true", help="show version number.") |
| 4494 | + opt("-b", "--bind", metavar="ADDRESS", help="bind socket to ADDRESS.") |
| 4495 | + opt("-s", "--server", default='wsgiref', help="use SERVER as backend.") |
| 4496 | + opt("-p", "--plugin", action="append", help="install additional plugin/s.") |
| 4497 | + opt("-c", "--conf", action="append", metavar="FILE", |
| 4498 | + help="load config values from FILE.") |
| 4499 | + opt("-C", "--param", action="append", metavar="NAME=VALUE", |
| 4500 | + help="override config values.") |
| 4501 | + opt("--debug", action="store_true", help="start server in debug mode.") |
| 4502 | + opt("--reload", action="store_true", help="auto-reload on file changes.") |
| 4503 | + opt('app', help='WSGI app entry point.', nargs='?') |
| 4504 | + |
| 4505 | + cli_args = parser.parse_args(args[1:]) |
| 4506 | + |
| 4507 | + return cli_args, parser |
| 4508 | + |
4529 | 4509 |
|
4530 | 4510 | def _main(argv): # pragma: no coverage |
4531 | 4511 | args, parser = _cli_parse(argv) |
|
0 commit comments