feat(cli): enhance search and list commands to show all registry applets and support remote discovery

This commit is contained in:
Gravitiny Team
2026-10-03 06:07:52 +03:00
parent 07739ae279
commit 4628fa3b87
2 changed files with 58 additions and 45 deletions
+18 -10
View File
@@ -50,17 +50,15 @@ def print_help() -> None:
def cmd_search(args: List[str]) -> int: def cmd_search(args: List[str]) -> int:
if not args: force_refresh = "--refresh" in args
print(catalog.get("commands.search.missing_query")) filtered_args = [a for a in args if a != "--refresh"]
print(catalog.get("commands.search.usage")) query = " ".join(filtered_args) if filtered_args else ""
return 1
query = " ".join(args)
client = RegistryClient() client = RegistryClient()
results = client.search(query) results = client.search(query, force_refresh=force_refresh)
if not results: if not results:
print(catalog.format("commands.search.no_results", query=query)) print(catalog.format("commands.search.no_results", query=query or "all"))
return 0 return 0
print(catalog.format("commands.search.results_header", count=len(results))) print(catalog.format("commands.search.results_header", count=len(results)))
@@ -121,18 +119,23 @@ def cmd_remove(args: List[str]) -> int:
return 1 return 1
def cmd_list() -> int: def cmd_list(args: Optional[List[str]] = None) -> int:
raw_args = args or []
show_remote = "-a" in raw_args or "--all" in raw_args or "-r" in raw_args or "--remote" in raw_args
discovery = AppletDiscovery() discovery = AppletDiscovery()
applets = discovery.discover_all() applets = discovery.discover_all()
if not applets: if not applets:
print(catalog.get("commands.list.no_applets_found")) print(catalog.get("commands.list.no_applets_found"))
if not show_remote:
print("\nRun 'gravitiny search' or 'gravitiny list --all' to discover available applets in the registry.")
return 0 return 0
if applets:
print(catalog.format("commands.list.installed_header", count=len(applets))) print(catalog.format("commands.list.installed_header", count=len(applets)))
print() print()
# Calculate column widths
id_w = max(len(catalog.get("commands.list.table_col_id")), max(len(a.id) for a in applets.values())) + 2 id_w = max(len(catalog.get("commands.list.table_col_id")), max(len(a.id) for a in applets.values())) + 2
name_w = max(len(catalog.get("commands.list.table_col_name")), max(len(a.name) for a in applets.values())) + 2 name_w = max(len(catalog.get("commands.list.table_col_name")), max(len(a.name) for a in applets.values())) + 2
ver_w = max(len(catalog.get("commands.list.table_col_version")), max(len(a.version) for a in applets.values())) + 2 ver_w = max(len(catalog.get("commands.list.table_col_version")), max(len(a.version) for a in applets.values())) + 2
@@ -160,6 +163,11 @@ def cmd_list() -> int:
f"{applet.description}" f"{applet.description}"
) )
if show_remote:
print()
print("Available Remote Registry Applets:")
cmd_search(["--refresh"])
return 0 return 0
@@ -431,7 +439,7 @@ def run_cli(args: Optional[List[str]] = None) -> int:
elif command == "remove": elif command == "remove":
return cmd_remove(sub_args) return cmd_remove(sub_args)
elif command == "list": elif command == "list":
return cmd_list() return cmd_list(sub_args)
elif command == "run": elif command == "run":
return cmd_run(sub_args) return cmd_run(sub_args)
elif command == "info": elif command == "info":
+13 -8
View File
@@ -69,14 +69,15 @@ class RegistryClient:
return {} return {}
def search(self, query: str) -> List[Dict[str, Any]]: def search(self, query: str = "", force_refresh: bool = False) -> List[Dict[str, Any]]:
"""Searches across applet id, name, description, tags, and author.""" """Searches across applet id, name, description, tags, and author. Empty query returns all."""
clean_q = query.strip().lower() clean_q = query.strip().lower()
if not clean_q: index = self.fetch_index(force_refresh=force_refresh)
return []
index = self.fetch_index()
applets = index.get("applets", {}) applets = index.get("applets", {})
if not clean_q or clean_q in ["all", "*", "--all", "-a"]:
return list(applets.values())
results: List[Dict[str, Any]] = [] results: List[Dict[str, Any]] = []
for applet_id, info in applets.items(): for applet_id, info in applets.items():
@@ -96,9 +97,13 @@ class RegistryClient:
return results return results
def get_applet(self, applet_id: str) -> Optional[Dict[str, Any]]: def get_applet(self, applet_id: str, force_refresh: bool = False) -> Optional[Dict[str, Any]]:
"""Retrieves metadata for a specific remote applet.""" """Retrieves metadata for a specific remote applet."""
clean_id = applet_id.strip().lower() clean_id = applet_id.strip().lower()
index = self.fetch_index() index = self.fetch_index(force_refresh=force_refresh)
applets = index.get("applets", {})
if clean_id not in applets and not force_refresh:
# Retry with force refresh once
index = self.fetch_index(force_refresh=True)
applets = index.get("applets", {}) applets = index.get("applets", {})
return applets.get(clean_id) return applets.get(clean_id)