26 lines
721 B
Python
26 lines
721 B
Python
|
|
from .util import get_package_index
|
||
|
|
from .console import console
|
||
|
|
|
||
|
|
from rich.table import Table
|
||
|
|
from rich.box import ROUNDED
|
||
|
|
|
||
|
|
|
||
|
|
def search(args):
|
||
|
|
index = get_package_index()
|
||
|
|
|
||
|
|
matching_keys = [key for key in index if args.query in key]
|
||
|
|
|
||
|
|
if args.limit >= 0:
|
||
|
|
matching_keys = matching_keys[:args.limit]
|
||
|
|
|
||
|
|
if len(matching_keys) == 0:
|
||
|
|
console.print("Search returned no results.")
|
||
|
|
return
|
||
|
|
|
||
|
|
table = Table("Rock", "Description", header_style="bold blue", box=ROUNDED, title="Search Results")
|
||
|
|
|
||
|
|
for i, key in enumerate(matching_keys):
|
||
|
|
rock = index[key]
|
||
|
|
table.add_row(f"[b]{key}[/]", rock.get("description", "<empty>"))
|
||
|
|
|
||
|
|
console.print(table)
|