From fd8aa149ca16571fd25a418d531f5088e3897dec Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Sat, 20 Jun 2026 17:24:12 +1000 Subject: [PATCH] you can search rocks now --- neb/README.md | 1 + neb/src/list.py | 2 +- neb/src/main.py | 10 +++++++++- neb/src/search.py | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 neb/src/search.py diff --git a/neb/README.md b/neb/README.md index 9f2d49b..1fcc016 100644 --- a/neb/README.md +++ b/neb/README.md @@ -22,6 +22,7 @@ neb install packageName@1.0.0 ### 1.1.0 - Switched from getting the latest commit of packages to getting the latest release - Added the `uninstall` subcommand +- Added the `search` subcommand ### 1.0.1 - Fix long description hopefully diff --git a/neb/src/list.py b/neb/src/list.py index bd65152..5263769 100644 --- a/neb/src/list.py +++ b/neb/src/list.py @@ -16,7 +16,7 @@ def list_packages(args) -> None: console.print("No rocks are installed.") return - packages_table = Table("Name", "Version", "Description", "Author", box=ROUNDED, header_style="bold blue", ) + packages_table = Table("Name", "Version", "Description", "Author", box=ROUNDED, header_style="bold blue", title="Installed Rocks") for name in installed: lib_data_dir = os.path.join(data_path, name) diff --git a/neb/src/main.py b/neb/src/main.py index 80470ff..611ffd9 100644 --- a/neb/src/main.py +++ b/neb/src/main.py @@ -6,6 +6,7 @@ from .install import install from .pull import pull from .list import list_packages from .uninstall import uninstall +from .search import search def main() -> int: @@ -19,7 +20,6 @@ def main() -> int: # install command install_cmd = sub_parsers.add_parser(name="install", description="install a rock (package)") install_cmd.add_argument("names", help="name of the rocks to install", nargs="+") - install_cmd.add_argument("--max-retries", help="max number of download retries before giving up", type=int, default=3) # pull command pull_cmd = sub_parsers.add_parser(name="pull", description="pull rock index") @@ -30,6 +30,12 @@ def main() -> int: # uninstall command uninstall_cmd = sub_parsers.add_parser(name="uninstall", description="uninstall an installed rock(s)") uninstall_cmd.add_argument("names", help="name of the rocks to uninstall", nargs="+") + + # search command + search_cmd = sub_parsers.add_parser(name="search", description="search for rocks") + search_cmd.add_argument("query", help="search query") + search_cmd.add_argument("-s", "--show-installed", help="show rocks even if they're already installed", action="store_true") + search_cmd.add_argument("-l", "--limit", help="max number of search results. set this to -1 to show all results", type=int, default=-1) args = arg_parser.parse_args() @@ -47,6 +53,8 @@ def main() -> int: list_packages(args) case "uninstall": uninstall(args) + case "search": + search(args) # really feeling like a C programmer lmao return 0 diff --git a/neb/src/search.py b/neb/src/search.py new file mode 100644 index 0000000..d6c7373 --- /dev/null +++ b/neb/src/search.py @@ -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", "")) + + console.print(table) \ No newline at end of file