-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of the
init
command. Test cases added.
- Loading branch information
1 parent
b9ae8e3
commit 7a14261
Showing
15 changed files
with
516 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Implementation of the init command.""" | ||
# dem/cli/command/init_cmd.py | ||
|
||
import os, typer | ||
from dem.core.platform import Platform | ||
from dem.core.dev_env import DevEnv | ||
from dem.core.exceptions import PlatformError | ||
from dem.cli.console import stderr, stdout | ||
|
||
def execute(platform: Platform, project_path: str) -> None: | ||
""" Initialize a project at the given path. | ||
Args: | ||
platform -- the platform | ||
project_path -- the path to the project to initialize | ||
""" | ||
if not os.path.isdir(project_path): | ||
stderr.print(f"[red]Error: The {project_path} path does not exist.[/]") | ||
return | ||
|
||
try: | ||
dev_env = DevEnv(descriptor_path=f"{project_path}/.axem/dev_env_descriptor.json") | ||
except FileNotFoundError as e: | ||
stderr.print(f"[red]Error: No Dev Env is assigned to this project. You can assign one with `dem assign`.") | ||
return | ||
|
||
for local_dev_env in platform.local_dev_envs: | ||
if local_dev_env.name == dev_env.name: | ||
stdout.print(f"[yellow]Warning: The {dev_env.name} Development Environment is already initialized.[/]") | ||
typer.confirm("Would you like to re-init the Dev Env? All local changes will be lost!", abort=True) | ||
|
||
if local_dev_env.is_installed: | ||
typer.confirm("The Development Environment is installed, so it can't be deleted. Do you want to uninstall it first?", | ||
abort=True) | ||
|
||
try: | ||
platform.uninstall_dev_env(local_dev_env) | ||
except PlatformError as e: | ||
stderr.print(f"[red]Error: The Dev Env can't be uninstalled. {str(e)}") | ||
return | ||
|
||
platform.local_dev_envs.remove(local_dev_env) | ||
break | ||
|
||
platform.local_dev_envs.append(dev_env) | ||
platform.flush_descriptors() | ||
stdout.print(f"[green]Successfully initialized the {dev_env.name} Dev Env for the project at {project_path}![/]") | ||
stdout.print(f"\nNow you can install the Dev Env with the `dem install {dev_env.name}` command.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.