|
10 | 10 | from rich.table import Table |
11 | 11 |
|
12 | 12 | from uvlink import __version__ |
| 13 | +from uvlink.path_utils import execute_symlink, path_exists |
13 | 14 | from uvlink.project import Project, Projects, get_uvlink_dir, rm_rf |
14 | 15 |
|
15 | 16 | app = typer.Typer( |
@@ -102,25 +103,23 @@ def link( |
102 | 103 | else: |
103 | 104 | if not proj.project_dir.is_dir(): |
104 | 105 | raise NotADirectoryError(f"{proj.project_dir} is not a directory") |
105 | | - else: |
106 | | - if venv.exists() or venv.is_symlink(): |
107 | | - if typer.confirm(f"'{venv}' already exist, remove?", default=True): |
108 | | - typer.echo("Removing...") |
109 | | - rm_rf(venv.parent) |
110 | | - else: |
111 | | - typer.echo(f"Keep current {venv}") |
112 | | - if symlink.exists() or symlink.is_symlink(): |
113 | | - if typer.confirm( |
114 | | - f"'{symlink}' already exist, overwrite?", default=True |
115 | | - ): |
116 | | - rm_rf(symlink) |
117 | | - else: |
118 | | - typer.echo("Cancelled.") |
119 | | - raise typer.Abort() |
120 | | - venv.mkdir(parents=True, exist_ok=True) |
121 | | - symlink.symlink_to(venv) |
122 | | - proj.save_json_metadata_file() |
123 | | - typer.echo(f"symlink created: {symlink} -> {venv}") |
| 106 | + |
| 107 | + if path_exists(venv): |
| 108 | + if typer.confirm(f"'{venv}' already exists, remove?", default=True): |
| 109 | + typer.echo("Removing...") |
| 110 | + rm_rf(venv.parent) |
| 111 | + else: |
| 112 | + typer.echo(f"Keep current {venv}") |
| 113 | + if path_exists(symlink): |
| 114 | + if typer.confirm(f"'{symlink}' already exists, overwrite?", default=True): |
| 115 | + rm_rf(symlink) |
| 116 | + else: |
| 117 | + typer.echo("Cancelled.") |
| 118 | + raise typer.Abort() |
| 119 | + |
| 120 | + execute_symlink(symlink, venv) |
| 121 | + proj.save_json_metadata_file() |
| 122 | + typer.echo(f"symlink created: {symlink} -> {venv}") |
124 | 123 |
|
125 | 124 |
|
126 | 125 | @app.command("ls") |
|
0 commit comments