2023-08-24 14:58:22 +00:00
|
|
|
import argparse
|
2023-09-02 16:37:40 +00:00
|
|
|
import shutil
|
2023-08-24 14:58:22 +00:00
|
|
|
|
2024-05-30 17:51:53 +00:00
|
|
|
from ..completions import add_dynamic_completer, complete_machines
|
2023-10-24 14:54:10 +00:00
|
|
|
from ..dirs import specific_machine_dir
|
2023-08-24 14:58:22 +00:00
|
|
|
from ..errors import ClanError
|
|
|
|
|
|
|
|
|
|
|
|
def delete_command(args: argparse.Namespace) -> None:
|
2023-10-24 14:54:10 +00:00
|
|
|
folder = specific_machine_dir(args.flake, args.host)
|
2023-08-24 14:58:22 +00:00
|
|
|
if folder.exists():
|
2023-09-02 16:37:40 +00:00
|
|
|
shutil.rmtree(folder)
|
2023-08-24 14:58:22 +00:00
|
|
|
else:
|
|
|
|
raise ClanError(f"Machine {args.host} does not exist")
|
|
|
|
|
|
|
|
|
|
|
|
def register_delete_parser(parser: argparse.ArgumentParser) -> None:
|
2024-05-30 17:51:53 +00:00
|
|
|
machines_parser = parser.add_argument("host", type=str)
|
|
|
|
add_dynamic_completer(machines_parser, complete_machines)
|
|
|
|
|
2023-08-24 14:58:22 +00:00
|
|
|
parser.set_defaults(func=delete_command)
|