Unverified Commit 41490c37 authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Add search command

parent ed104cd0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

- Added support for Python 2.7.
- Added a fallback mechanism (opt-in) for missing dependencies.
- Added `search` command.

### Changes

+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ from .commands import PublishCommand
from .commands import RemoveCommand
from .commands import RunCommand
from .commands import ScriptCommand
from .commands import SearchCommand
from .commands import ShowCommand
from .commands import UpdateCommand
from .commands import VersionCommand
@@ -100,6 +101,7 @@ class Application(BaseApplication):
            RemoveCommand(),
            RunCommand(),
            ScriptCommand(),
            SearchCommand(),
            ShowCommand(),
            UpdateCommand(),
            VersionCommand(),
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ from .publish import PublishCommand
from .remove import RemoveCommand
from .run import RunCommand
from .script import ScriptCommand
from .search import SearchCommand
from .show import ShowCommand
from .update import UpdateCommand
from .version import VersionCommand
+35 −0
Original line number Diff line number Diff line
from .command import Command


class SearchCommand(Command):
    """
    Searches for packages on remote repositories.

    search
        { tokens* : The tokens to search for. }
        { --N|only-name : Search only in name. }
    """

    def handle(self):
        from poetry.repositories.base_repository import BaseRepository

        flags = BaseRepository.SEARCH_FULLTEXT
        if self.option('only-name'):
            flags = BaseRepository.SEARCH_FULLTEXT

        results = self.poetry.pool.search(self.argument('tokens'), flags)

        for result in results:
            self.line('')
            name = '<info>{}</>'.format(
                result.name
            )

            name += ' (<comment>{}</>)'.format(result.version)

            self.line(name)

            if result.description:
                self.line(
                    ' {}'.format(result.description)
                )
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ class LegacyRepository(PyPiRepository):
            }
        })

    @property
    def name(self):
        return self._name

    def find_packages(self, name, constraint=None, extras=None):
        packages = []

Loading