Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make aiidalab-launch profile remove accept multiple profiles #190

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,46 @@ def add_profile(ctx, app_state, port, home_mount, image, profile):


@profile.command("remove")
@click.argument("profile")
@click.argument("profile", nargs=-1, required=True)
@click.option("--yes", is_flag=True, help="Do not ask for confirmation.")
@click.option("-f", "--force", is_flag=True, help="Proceed, ignoring any warnings.")
@click.option("--purge", is_flag=True, help="Remove all data associated with profile.")
@pass_app_state
def remove_profile(app_state, profile, yes, force):
@click.pass_context
def remove_profile(ctx, app_state, profile, yes, force, purge):
"""Remove an AiiDAlab profile from the configuration."""
try:
profile = app_state.config.get_profile(profile)
except ValueError:
raise click.ClickException(f"Profile with name '{profile}' does not exist.")
else:
if not force:
instance = AiidaLabInstance(client=app_state.docker_client, profile=profile)
status = asyncio.run(instance.status())
if status not in (
instance.AiidaLabInstanceStatus.DOWN,
instance.AiidaLabInstanceStatus.CREATED,
instance.AiidaLabInstanceStatus.EXITED,
):
raise click.ClickException(
f"The instance associated with profile '{profile.name}' "
"is still running. Use the -f/--force option to remove the "
"profile anyways."
)
profile_lst = profile
for prof in profile_lst:
try:
profile = app_state.config.get_profile(prof)
except ValueError:
raise click.ClickException(f"Profile with name '{prof}' does not exist.")
else:
if purge:
ctx.invoke(reset, profile=profile, yes=yes)

if yes or click.confirm(
f"Are you sure you want to remove profile '{profile.name}'?"
):
app_state.config.profiles.remove(profile)
app_state.save_config()
click.echo(f"Removed profile with name '{profile.name}'.")
if not force:
instance = AiidaLabInstance(
client=app_state.docker_client, profile=profile
)
status = asyncio.run(instance.status())
if status not in (
instance.AiidaLabInstanceStatus.DOWN,
instance.AiidaLabInstanceStatus.CREATED,
instance.AiidaLabInstanceStatus.EXITED,
):
raise click.ClickException(
f"The instance associated with profile '{profile.name}' "
"is still running. Use the -f/--force option to remove the "
"profile anyways."
)

if yes or click.confirm(
f"Are you sure you want to remove profile '{profile.name}'?"
):
app_state.config.profiles.remove(profile)
app_state.save_config()
click.echo(f"Removed profile with name '{profile.name}'.")


@profile.command("edit")
Expand Down