diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index c7815eda..07b69613 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -131,3 +131,12 @@ def lib_update(): lib_uninstall([name]) lib_install([name]) + + +@cli.command("register", short_help="Register new library") +@argument("config_url") +def lib_register(config_url): + result = get_api_result("/lib/register", data=dict(config_url=config_url)) + if "message" in result and result['message']: + secho(result['message'], fg="green" if "successed" in result and + result['successed'] else "red") diff --git a/platformio/util.py b/platformio/util.py index 63a10475..c29347d9 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -8,7 +8,7 @@ from platform import system, uname from subprocess import PIPE, Popen from time import sleep -from requests import get +from requests import get, post from requests.exceptions import ConnectionError, HTTPError from requests.utils import default_user_agent from serial import Serial @@ -114,13 +114,17 @@ def get_serialports(): return[{"port": p, "description": d, "hwid": h} for p, d, h in comports()] -def get_api_result(path, params=None): +def get_api_result(path, params=None, data=None): result = None r = None try: headers = {"User-Agent": "PlatformIO/%s %s" % ( __version__, default_user_agent())} - r = get(__apiurl__ + path, params=params, headers=headers) + if data: + r = post(__apiurl__ + path, params=params, data=data, + headers=headers) + else: + r = get(__apiurl__ + path, params=params, headers=headers) result = r.json() r.raise_for_status() except HTTPError as e: