| 27 | |
| 28 | |
| 29 | def init(argv): |
| 30 | arg_parser = ArgumentParser( |
| 31 | prog="aiohttp.web ...", description="Application CLI", add_help=False |
| 32 | ) |
| 33 | |
| 34 | # Positional argument |
| 35 | arg_parser.add_argument("message", help="message to print") |
| 36 | |
| 37 | # Optional argument |
| 38 | arg_parser.add_argument( |
| 39 | "--repeat", help="number of times to repeat message", type=int, default="1" |
| 40 | ) |
| 41 | |
| 42 | # Avoid conflict with -h from `aiohttp.web` CLI parser |
| 43 | arg_parser.add_argument( |
| 44 | "--app-help", help="show this message and exit", action="help" |
| 45 | ) |
| 46 | |
| 47 | args = arg_parser.parse_args(argv) |
| 48 | |
| 49 | app = web.Application() |
| 50 | app[args_key] = args |
| 51 | app.router.add_get("/", display_message) |
| 52 | |
| 53 | return app |