refactor(self-mgmt): centralize manual file list for install/uninstall
This commit is contained in:
@@ -9,6 +9,15 @@ from pathlib import Path
|
||||
import click
|
||||
|
||||
|
||||
# 手动安装的文件清单(pip 管理范围外,uninstall 时需要额外清理)
|
||||
_MANUAL_FILES: dict[str, list[Path]] = {
|
||||
"completions": [
|
||||
Path.home() / ".local" / "bin" / "completions" / "_mytoolkit",
|
||||
Path.home() / ".local" / "bin" / "completions" / "mytoolkit.bash",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _get_project_root() -> Path:
|
||||
"""Get mytoolkit project root from source tree."""
|
||||
return Path(__file__).parent.parent.parent
|
||||
@@ -78,11 +87,15 @@ def _uninstall() -> None:
|
||||
check=False,
|
||||
)
|
||||
|
||||
comp_dir = Path.home() / ".local" / "bin" / "completions"
|
||||
for f in (comp_dir / "_mytoolkit", comp_dir / "mytoolkit.bash"):
|
||||
if f.exists() or f.is_symlink():
|
||||
f.unlink()
|
||||
click.secho(f"Removed {f}", fg="green")
|
||||
removed = 0
|
||||
for paths in _MANUAL_FILES.values():
|
||||
for f in paths:
|
||||
if f.exists() or f.is_symlink():
|
||||
f.unlink()
|
||||
click.secho(f"Removed {f}", fg="green")
|
||||
removed += 1
|
||||
if removed == 0:
|
||||
click.secho("No manual files to clean up.", fg="cyan")
|
||||
|
||||
|
||||
@click.command(name="update")
|
||||
|
||||
Reference in New Issue
Block a user