import os

from cleo import Application as BaseApplication

from poetry.poetry import Poetry
from poetry.utils.venv import Venv

from .commands import AboutCommand
from .commands import AddCommand
from .commands import BuildCommand
from .commands import ConfigCommand
from .commands import InstallCommand
from .commands import LockCommand
from .commands import NewCommand
from .commands import PublishCommand
from .commands import RemoveCommand
from .commands import ShowCommand
from .commands import UpdateCommand


class Application(BaseApplication):

    def __init__(self):
        super().__init__('Poetry', Poetry.VERSION)

        self._poetry = None

    @property
    def poetry(self) -> Poetry:
        if self._poetry is not None:
            return self._poetry

        self._poetry = Poetry.create(os.getcwd())

        return self._poetry

    def reset_poetry(self) -> None:
        self._poetry = None

    def get_default_commands(self) -> list:
        commands = super(Application, self).get_default_commands()

        return commands + [
            AboutCommand(),
            AddCommand(),
            BuildCommand(),
            ConfigCommand(),
            InstallCommand(),
            LockCommand(),
            NewCommand(),
            PublishCommand(),
            RemoveCommand(),
            ShowCommand(),
            UpdateCommand(),
        ]
