forked from platformio/platformio-core
Improve output of pio lib list
and pio lib search
commands
This commit is contained in:
2
docs
2
docs
Submodule docs updated: 47c714cad7...19fe267062
@ -118,46 +118,33 @@ def lib_update(lm, libraries, only_check):
|
|||||||
lm.update(library, only_check=only_check)
|
lm.update(library, only_check=only_check)
|
||||||
|
|
||||||
|
|
||||||
#######
|
def print_lib_item(item):
|
||||||
|
click.secho(item['name'], fg="cyan")
|
||||||
|
click.echo("=" * len(item['name']))
|
||||||
|
if "id" in item:
|
||||||
|
click.secho("#ID: %d" % item['id'], bold=True)
|
||||||
|
click.echo(item.get("description", item.get("url", "")).encode("utf-8"))
|
||||||
|
click.echo()
|
||||||
|
|
||||||
LIBLIST_TPL = ("[{id:^15}] {name:<25} {compatibility:<30} "
|
for key in ("homepage", "license", "keywords"):
|
||||||
"\"{authornames}\": {description}")
|
if key not in item or not item[key]:
|
||||||
|
continue
|
||||||
|
if isinstance(item[key], list):
|
||||||
|
click.echo("%s: %s" % (key.title(), ", ".join(item[key])))
|
||||||
|
else:
|
||||||
|
click.echo("%s: %s" % (key.title(), item[key]))
|
||||||
|
|
||||||
|
for key in ("frameworks", "platforms"):
|
||||||
|
if key not in item:
|
||||||
|
continue
|
||||||
|
click.echo("Compatible %s: %s" % (key, ", ".join(
|
||||||
|
[i['title'] if isinstance(i, dict) else i for i in item[key]])))
|
||||||
|
|
||||||
def echo_liblist_header():
|
if "authors" in item or "authornames" in item:
|
||||||
click.echo(
|
click.echo("Authors: %s" % ", ".join(
|
||||||
LIBLIST_TPL.format(
|
item.get("authornames",
|
||||||
id=click.style(
|
[a.get("name", "") for a in item.get("authors", [])])))
|
||||||
"ID", fg="green"),
|
click.echo()
|
||||||
name=click.style(
|
|
||||||
"Name", fg="cyan"),
|
|
||||||
compatibility=click.style(
|
|
||||||
"Compatibility", fg="yellow"),
|
|
||||||
authornames="Authors",
|
|
||||||
description="Description"))
|
|
||||||
|
|
||||||
terminal_width, _ = click.get_terminal_size()
|
|
||||||
click.echo("-" * terminal_width)
|
|
||||||
|
|
||||||
|
|
||||||
def echo_liblist_item(item):
|
|
||||||
description = item.get("description", item.get("url", "")).encode("utf-8")
|
|
||||||
if "version" in item:
|
|
||||||
description += " | @" + click.style(item['version'], fg="yellow")
|
|
||||||
|
|
||||||
click.echo(
|
|
||||||
LIBLIST_TPL.format(
|
|
||||||
id=click.style(
|
|
||||||
str(item.get("id", "-")), fg="green"),
|
|
||||||
name=click.style(
|
|
||||||
item['name'], fg="cyan"),
|
|
||||||
compatibility=click.style(
|
|
||||||
", ".join(
|
|
||||||
item.get("frameworks", ["-"]) + item.get("platforms", [])),
|
|
||||||
fg="yellow"),
|
|
||||||
authornames=", ".join(item.get("authornames", ["Unknown"])).encode(
|
|
||||||
"utf-8"),
|
|
||||||
description=description))
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("search", short_help="Search for a library")
|
@cli.command("search", short_help="Search for a library")
|
||||||
@ -185,7 +172,7 @@ def lib_search(query, json_output, page, noninteractive, **filters):
|
|||||||
query.append('%s:"%s"' % (key, value))
|
query.append('%s:"%s"' % (key, value))
|
||||||
|
|
||||||
result = get_api_result(
|
result = get_api_result(
|
||||||
"/lib/search",
|
"/v2/lib/search",
|
||||||
dict(
|
dict(
|
||||||
query=" ".join(query), page=page),
|
query=" ".join(query), page=page),
|
||||||
cache_valid="3d")
|
cache_valid="3d")
|
||||||
@ -214,12 +201,9 @@ def lib_search(query, json_output, page, noninteractive, **filters):
|
|||||||
"Found %d libraries:\n" % result['total'],
|
"Found %d libraries:\n" % result['total'],
|
||||||
fg="green" if result['total'] else "yellow")
|
fg="green" if result['total'] else "yellow")
|
||||||
|
|
||||||
if result['total']:
|
|
||||||
echo_liblist_header()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for item in result['items']:
|
for item in result['items']:
|
||||||
echo_liblist_item(item)
|
print_lib_item(item)
|
||||||
|
|
||||||
if (int(result['page']) * int(result['perpage']) >=
|
if (int(result['page']) * int(result['perpage']) >=
|
||||||
int(result['total'])):
|
int(result['total'])):
|
||||||
@ -236,7 +220,7 @@ def lib_search(query, json_output, page, noninteractive, **filters):
|
|||||||
elif not click.confirm("Show next libraries?"):
|
elif not click.confirm("Show next libraries?"):
|
||||||
break
|
break
|
||||||
result = get_api_result(
|
result = get_api_result(
|
||||||
"/lib/search",
|
"/v2/lib/search",
|
||||||
dict(
|
dict(
|
||||||
query=" ".join(query), page=int(result['page']) + 1),
|
query=" ".join(query), page=int(result['page']) + 1),
|
||||||
cache_valid="3d")
|
cache_valid="3d")
|
||||||
@ -254,11 +238,8 @@ def lib_list(lm, json_output):
|
|||||||
if not items:
|
if not items:
|
||||||
return
|
return
|
||||||
|
|
||||||
echo_liblist_header()
|
|
||||||
for item in sorted(items, key=lambda i: i['name']):
|
for item in sorted(items, key=lambda i: i['name']):
|
||||||
if "authors" in item:
|
print_lib_item(item)
|
||||||
item['authornames'] = [i['name'] for i in item['authors']]
|
|
||||||
echo_liblist_item(item)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("show", short_help="Show detailed info about a library")
|
@cli.command("show", short_help="Show detailed info about a library")
|
||||||
@ -275,13 +256,13 @@ def lib_show(library, json_output):
|
|||||||
|
|
||||||
click.secho(lib['name'], fg="cyan")
|
click.secho(lib['name'], fg="cyan")
|
||||||
click.echo("=" * len(lib['name']))
|
click.echo("=" * len(lib['name']))
|
||||||
|
click.secho("#ID: %d" % lib['id'], bold=True)
|
||||||
click.echo(lib['description'])
|
click.echo(lib['description'])
|
||||||
click.echo()
|
click.echo()
|
||||||
|
|
||||||
click.echo("Version: %s, released %s" %
|
click.echo("Version: %s, released %s" %
|
||||||
(lib['version']['name'],
|
(lib['version']['name'],
|
||||||
arrow.get(lib['version']['released']).humanize()))
|
arrow.get(lib['version']['released']).humanize()))
|
||||||
click.echo("Registry ID: %d" % lib['id'])
|
|
||||||
click.echo("Manifest: %s" % lib['confurl'])
|
click.echo("Manifest: %s" % lib['confurl'])
|
||||||
for key in ("homepage", "repository", "license"):
|
for key in ("homepage", "repository", "license"):
|
||||||
if key not in lib or not lib[key]:
|
if key not in lib or not lib[key]:
|
||||||
@ -310,10 +291,10 @@ def lib_show(library, json_output):
|
|||||||
blocks.append(("Authors", _authors))
|
blocks.append(("Authors", _authors))
|
||||||
|
|
||||||
blocks.append(("Keywords", lib['keywords']))
|
blocks.append(("Keywords", lib['keywords']))
|
||||||
if lib['frameworks']:
|
for key in ("frameworks", "platforms"):
|
||||||
blocks.append(("Compatible Frameworks", lib['frameworks']))
|
if key not in lib or not lib[key]:
|
||||||
if lib['platforms']:
|
continue
|
||||||
blocks.append(("Compatible Platforms", lib['platforms']))
|
blocks.append(("Compatible %s" % key, [i['title'] for i in lib[key]]))
|
||||||
blocks.append(("Headers", lib['headers']))
|
blocks.append(("Headers", lib['headers']))
|
||||||
blocks.append(("Examples", lib['examples']))
|
blocks.append(("Examples", lib['examples']))
|
||||||
blocks.append(("Versions", [
|
blocks.append(("Versions", [
|
||||||
|
@ -291,7 +291,7 @@ class LibraryManager(BasePkgManager):
|
|||||||
|
|
||||||
lib_info = None
|
lib_info = None
|
||||||
result = util.get_api_result(
|
result = util.get_api_result(
|
||||||
"/lib/search", dict(query=" ".join(query)), cache_valid="3d")
|
"/v2/lib/search", dict(query=" ".join(query)), cache_valid="3d")
|
||||||
if result['total'] == 1:
|
if result['total'] == 1:
|
||||||
lib_info = result['items'][0]
|
lib_info = result['items'][0]
|
||||||
elif result['total'] > 1:
|
elif result['total'] > 1:
|
||||||
@ -303,9 +303,8 @@ class LibraryManager(BasePkgManager):
|
|||||||
"by request %s:" % json.dumps(filters),
|
"by request %s:" % json.dumps(filters),
|
||||||
fg="red",
|
fg="red",
|
||||||
err=True)
|
err=True)
|
||||||
commands.lib.echo_liblist_header()
|
|
||||||
for item in result['items']:
|
for item in result['items']:
|
||||||
commands.lib.echo_liblist_item(item)
|
commands.lib.print_lib_item(item)
|
||||||
|
|
||||||
if not interactive:
|
if not interactive:
|
||||||
click.secho(
|
click.secho(
|
||||||
|
@ -125,7 +125,7 @@ def test_lib_show(clirunner, validate_cliresult, isolated_pio_home):
|
|||||||
result = clirunner.invoke(cmd_lib, ["show", "64"])
|
result = clirunner.invoke(cmd_lib, ["show", "64"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert all([
|
assert all([
|
||||||
s in result.output for s in ("ArduinoJson", "arduino", "atmelavr")
|
s in result.output for s in ("ArduinoJson", "Arduino", "Atmel AVR")
|
||||||
])
|
])
|
||||||
result = clirunner.invoke(cmd_lib, ["show", "OneWire"])
|
result = clirunner.invoke(cmd_lib, ["show", "OneWire"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
Reference in New Issue
Block a user