you can search rocks now
This commit is contained in:
26
neb/src/search.py
Normal file
26
neb/src/search.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user