def do_reload(self, arg):
print("API loading...")
with open("xmusic-api.json", "r") as f:
apis = json.load(f)
for api in apis:
method = api["method"].replace(" ", "_").lower()
parser = argparse.ArgumentParser(
prog=method,
description=api["description"])
for param in api["parameters"]:
parser.add_argument(
"--" + param["name"],
type=locate(param["type"]),
default=param["default"] if "default" in param
else None,
choices=param["choices"] if "choices" in param
else None,
required=param["required"],
help=param["description"])
setattr(XMusicShell, "parser_" + method, parser)
setattr(XMusicShell, "do_" + method, self._process)
setattr(XMusicShell, "help_" + method, parser.print_help)
评论列表
文章目录