Skip to content

Commit 54ea301

Browse files
authored
Update the CLI to be executed async (#704)
1 parent 69c2723 commit 54ea301

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

backend/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
import asyncio
34
import os
45

56
from dataclasses import dataclass
@@ -14,7 +15,6 @@
1415
from backend import console, get_version
1516
from backend.common.exception.errors import BaseExceptionMixin
1617
from backend.core.conf import settings
17-
from backend.utils._await import run_await
1818
from backend.utils.file_ops import install_git_plugin, install_zip_plugin
1919

2020

@@ -44,7 +44,7 @@ def run(host: str, port: int, reload: bool, workers: int | None) -> None:
4444
)
4545

4646

47-
def install_plugin(path: str, repo_url: str) -> None:
47+
async def install_plugin(path: str, repo_url: str) -> None:
4848
if not path and not repo_url:
4949
raise cappa.Exit('path 或 repo_url 必须指定其中一项', code=1)
5050
if path and repo_url:
@@ -55,9 +55,9 @@ def install_plugin(path: str, repo_url: str) -> None:
5555

5656
try:
5757
if path:
58-
plugin_name = run_await(install_zip_plugin)(file=path)
58+
plugin_name = await install_zip_plugin(file=path)
5959
if repo_url:
60-
plugin_name = run_await(install_git_plugin)(repo_url=repo_url)
60+
plugin_name = await install_git_plugin(repo_url=repo_url)
6161
except Exception as e:
6262
raise cappa.Exit(e.msg if isinstance(e, BaseExceptionMixin) else str(e), code=1)
6363

@@ -105,8 +105,8 @@ class Add:
105105
cappa.Arg(long=True, help='Git 插件的仓库地址'),
106106
]
107107

108-
def __call__(self):
109-
install_plugin(path=self.path, repo_url=self.repo_url)
108+
async def __call__(self):
109+
await install_plugin(path=self.path, repo_url=self.repo_url)
110110

111111

112112
@dataclass
@@ -124,4 +124,4 @@ def __call__(self):
124124

125125
def main() -> None:
126126
output = cappa.Output(error_format='[red]Error[/]: {message}\n\n更多信息,尝试 "[cyan]--help[/]"')
127-
cappa.invoke(FbaCli, output=output)
127+
asyncio.run(cappa.invoke_async(FbaCli, output=output))

0 commit comments

Comments
 (0)