Implement --keyword and --author options for library search command

This commit is contained in:
Ivan Kravets
2014-09-06 12:12:13 +03:00
parent 46fb576c9d
commit a98dc5bc29

View File

@ -1,8 +1,6 @@
# Copyright (C) Ivan Kravets <me@ikravets.com> # Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details. # See LICENSE for details.
from urllib import quote
from click import argument, echo, group, option, secho, style from click import argument, echo, group, option, secho, style
from platformio.exception import LibAlreadyInstalledError from platformio.exception import LibAlreadyInstalledError
@ -16,9 +14,15 @@ def cli():
@cli.command("search", short_help="Search for library") @cli.command("search", short_help="Search for library")
@option("-a", "--author", multiple=True)
@option("-k", "--keyword", multiple=True)
@argument("query") @argument("query")
def lib_search(query): def lib_search(query, author, keyword):
result = get_api_result("/lib/search", dict(query=quote(query))) for key, values in dict(author=author, keyword=keyword).iteritems():
for value in values:
query += ' %s:"%s"' % (key, value)
result = get_api_result("/lib/search", dict(query=query))
secho("Found %d libraries:" % result['total'], secho("Found %d libraries:" % result['total'],
fg="green" if result['total'] else "yellow") fg="green" if result['total'] else "yellow")
for item in result['items']: for item in result['items']: