afws_client: extract get_argparser() for modular arg parsing

This commit is contained in:
Florian Agbuya 2024-07-18 12:45:32 +08:00 committed by Sébastien Bourdeauducq
parent 5dbf870e68
commit c05b109d5f
1 changed files with 5 additions and 1 deletions

View File

@ -168,7 +168,7 @@ class Client:
return "OK", json_str return "OK", json_str
async def main_async(): def get_argparser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--server", default="afws.m-labs.hk", help="server to connect to (default: %(default)s)") parser.add_argument("--server", default="afws.m-labs.hk", help="server to connect to (default: %(default)s)")
parser.add_argument("--port", default=80, type=int, help="port to connect to (default: %(default)d)") parser.add_argument("--port", default=80, type=int, help="port to connect to (default: %(default)d)")
@ -190,7 +190,11 @@ async def main_async():
act_get_json.add_argument("-o", "--out", default=None, help="output JSON file") act_get_json.add_argument("-o", "--out", default=None, help="output JSON file")
act_get_json.add_argument("-f", "--force", action="store_true", help="overwrite file if it already exists") act_get_json.add_argument("-f", "--force", action="store_true", help="overwrite file if it already exists")
args = parser.parse_args() args = parser.parse_args()
return parser
async def main_async():
args = get_argparser().parse_args()
client = Client(args.server, args.port, args.cert) client = Client(args.server, args.port, args.cert)
await client.connect() await client.connect()
try: try: