forked from platformio/platformio-core
Implement "lib search" command
This commit is contained in:
@@ -14,4 +14,5 @@ __email__ = "me@ikravets.com"
|
||||
__license__ = "MIT Licence"
|
||||
__copyright__ = "Copyright (C) 2014 Ivan Kravets"
|
||||
|
||||
__apiurl__ = "http://api.platformio.ikravets.com"
|
||||
__pkgmanifesturl__ = "http://platformio.ikravets.com/packages/manifest.json"
|
||||
|
41
platformio/commands/lib.py
Normal file
41
platformio/commands/lib.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
from click import argument, group, echo, style, secho
|
||||
from requests import get
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from platformio import __apiurl__
|
||||
from platformio.exception import APIRequestError
|
||||
|
||||
|
||||
def get_api_result(query):
|
||||
result = None
|
||||
r = None
|
||||
try:
|
||||
r = get(__apiurl__ + query)
|
||||
result = r.json()
|
||||
except ConnectionError:
|
||||
raise APIRequestError("Could not connect to PlatformIO API Service")
|
||||
except ValueError:
|
||||
raise APIRequestError("Invalid response: %s" % r.text)
|
||||
finally:
|
||||
if r:
|
||||
r.close()
|
||||
return result
|
||||
|
||||
|
||||
@group(short_help="Library Manager")
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
@cli.command("search", short_help="Search for library")
|
||||
@argument("query")
|
||||
def lib_search(query):
|
||||
result = get_api_result("/lib/search?query=%s" % query)
|
||||
secho("Found [ %d ] libraries:" % result['total'],
|
||||
fg="green" if result['total'] else "yellow")
|
||||
for item in result['items']:
|
||||
echo("{name:<30} {info}".format(name=style(item['name'], fg="cyan"),
|
||||
info=item['description']))
|
@@ -105,3 +105,8 @@ class GetSerialPortsError(PlatformioException):
|
||||
class GetLatestVersionError(PlatformioException):
|
||||
|
||||
MESSAGE = "Can't retrieve latest PlatformIO version"
|
||||
|
||||
|
||||
class APIRequestError(PlatformioException):
|
||||
|
||||
MESSAGE = "[API] %s"
|
||||
|
Reference in New Issue
Block a user