you can search rocks now
This commit is contained in:
@@ -22,6 +22,7 @@ neb install packageName@1.0.0
|
|||||||
### 1.1.0
|
### 1.1.0
|
||||||
- Switched from getting the latest commit of packages to getting the latest release
|
- Switched from getting the latest commit of packages to getting the latest release
|
||||||
- Added the `uninstall` subcommand
|
- Added the `uninstall` subcommand
|
||||||
|
- Added the `search` subcommand
|
||||||
|
|
||||||
### 1.0.1
|
### 1.0.1
|
||||||
- Fix long description hopefully
|
- Fix long description hopefully
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def list_packages(args) -> None:
|
|||||||
console.print("No rocks are installed.")
|
console.print("No rocks are installed.")
|
||||||
return
|
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:
|
for name in installed:
|
||||||
lib_data_dir = os.path.join(data_path, name)
|
lib_data_dir = os.path.join(data_path, name)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from .install import install
|
|||||||
from .pull import pull
|
from .pull import pull
|
||||||
from .list import list_packages
|
from .list import list_packages
|
||||||
from .uninstall import uninstall
|
from .uninstall import uninstall
|
||||||
|
from .search import search
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
@@ -19,7 +20,6 @@ def main() -> int:
|
|||||||
# install command
|
# install command
|
||||||
install_cmd = sub_parsers.add_parser(name="install", description="install a rock (package)")
|
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("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 command
|
||||||
pull_cmd = sub_parsers.add_parser(name="pull", description="pull rock index")
|
pull_cmd = sub_parsers.add_parser(name="pull", description="pull rock index")
|
||||||
@@ -31,6 +31,12 @@ def main() -> int:
|
|||||||
uninstall_cmd = sub_parsers.add_parser(name="uninstall", description="uninstall an installed rock(s)")
|
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="+")
|
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()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
# do different things based on args
|
# do different things based on args
|
||||||
@@ -47,6 +53,8 @@ def main() -> int:
|
|||||||
list_packages(args)
|
list_packages(args)
|
||||||
case "uninstall":
|
case "uninstall":
|
||||||
uninstall(args)
|
uninstall(args)
|
||||||
|
case "search":
|
||||||
|
search(args)
|
||||||
|
|
||||||
# really feeling like a C programmer lmao
|
# really feeling like a C programmer lmao
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
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