from .base import Base
from loguru import logger
from git import Repo
from shutil import rmtree


class Remove(Base):
    """Remove

    Removes a repository from the package list and also deletes the files
    locally.

    Usage: gitget remove <package_name> [options] [global options]

    Options:
        --soft  Local files will not be deleted

    Examples:
        gitget remove awesmubarak/gitget
        gitget remove awesmubarak/gitget --soft
    """

    def run(self):
        package_list = self.get_package_list()
        package_name = self.options["<package_name>"]
        soft_remove = self.options["--soft"]

        # check if package exists
        if not package_name in package_list:
            logger.error("Package name not in package list")
            exit(1)
        else:
            logger.debug("Package in package list")

        # remove package from package list
        package_location = package_list[package_name]
        package_list.pop(package_name, None)
        self.write_package_list(package_list)
        logger.info("Saved package information")

        # delete the package
        if soft_remove:
            logger.debug("Soft remove - not deleting files")
            return

        if (
            input(
                f"Are you sure you want to delete every file in {package_location}? [yes/NO]"
            )
            != "yes"
        ):
            logging.info("Exiting")
            exit(0)

        logger.info("Deleting files")
        try:
            rmtree(package_location)
        except:
            exception("Could not delete the files")

@@ -25,49 +25,86 @@
 rom 
-loguru import logger%0Afrom git import Repo
+distutils.util import strtobool%0Afrom git import Repo%0Afrom loguru import logger
 %0Afro
@@ -888,52 +888,8 @@
 st%22)
-%0A%0A        # remove package from package list
 %0A   
@@ -938,16 +938,774 @@
 ge_name%5D
+%0A%0A        # conifrm deleting files if asked to do so%0A        if not soft_remove:%0A            # prompt user wether to delete or not%0A            delete_prompt_input = input(%0A                f%22Are you sure you want to delete %7Bpackage_location%7D? %5By/N%5D%22%0A            )%0A            # try to convert to a true/false value, except invalid responses%0A            try:%0A                delete_file = strtobool(delete_prompt_input)%0A            except ValueError:%0A                logger.error(%22Not a valid response%22)%0A                exit(1)%0A            # respnse%0A            if delete_file:%0A                logger.debug(%22Going ahead with deletion%22)%0A            else:%0A                logger.info(%22Exiting%22)%0A                exit(0)%0A%0A        # remove package from package list
 %0A       
@@ -1859,23 +1859,21 @@
 ete the 
-package
+files
 %0A       
@@ -1972,237 +1972,10 @@
 turn
-%0A%0A        if (%0A            input(%0A                f%22Are you sure you want to delete every file in %7Bpackage_location%7D? %5Byes/NO%5D%22%0A            )%0A            != %22yes%22%0A        ):%0A            logging.info(%22Exiting%22)%0A            exit(0)
+ 0
 %0A%0A  

Change order of remove operations