feat(cli): enhance search and list commands to show all registry applets and support remote discovery
This commit is contained in:
+18
-10
@@ -50,17 +50,15 @@ def print_help() -> None:
|
||||
|
||||
|
||||
def cmd_search(args: List[str]) -> int:
|
||||
if not args:
|
||||
print(catalog.get("commands.search.missing_query"))
|
||||
print(catalog.get("commands.search.usage"))
|
||||
return 1
|
||||
force_refresh = "--refresh" in args
|
||||
filtered_args = [a for a in args if a != "--refresh"]
|
||||
query = " ".join(filtered_args) if filtered_args else ""
|
||||
|
||||
query = " ".join(args)
|
||||
client = RegistryClient()
|
||||
results = client.search(query)
|
||||
results = client.search(query, force_refresh=force_refresh)
|
||||
|
||||
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
|
||||
|
||||
print(catalog.format("commands.search.results_header", count=len(results)))
|
||||
@@ -121,18 +119,23 @@ def cmd_remove(args: List[str]) -> int:
|
||||
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()
|
||||
applets = discovery.discover_all()
|
||||
|
||||
if not applets:
|
||||
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
|
||||
|
||||
if applets:
|
||||
print(catalog.format("commands.list.installed_header", count=len(applets)))
|
||||
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
|
||||
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
|
||||
@@ -160,6 +163,11 @@ def cmd_list() -> int:
|
||||
f"{applet.description}"
|
||||
)
|
||||
|
||||
if show_remote:
|
||||
print()
|
||||
print("Available Remote Registry Applets:")
|
||||
cmd_search(["--refresh"])
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
@@ -431,7 +439,7 @@ def run_cli(args: Optional[List[str]] = None) -> int:
|
||||
elif command == "remove":
|
||||
return cmd_remove(sub_args)
|
||||
elif command == "list":
|
||||
return cmd_list()
|
||||
return cmd_list(sub_args)
|
||||
elif command == "run":
|
||||
return cmd_run(sub_args)
|
||||
elif command == "info":
|
||||
|
||||
@@ -69,14 +69,15 @@ class RegistryClient:
|
||||
|
||||
return {}
|
||||
|
||||
def search(self, query: str) -> List[Dict[str, Any]]:
|
||||
"""Searches across applet id, name, description, tags, and author."""
|
||||
def search(self, query: str = "", force_refresh: bool = False) -> List[Dict[str, Any]]:
|
||||
"""Searches across applet id, name, description, tags, and author. Empty query returns all."""
|
||||
clean_q = query.strip().lower()
|
||||
if not clean_q:
|
||||
return []
|
||||
|
||||
index = self.fetch_index()
|
||||
index = self.fetch_index(force_refresh=force_refresh)
|
||||
applets = index.get("applets", {})
|
||||
|
||||
if not clean_q or clean_q in ["all", "*", "--all", "-a"]:
|
||||
return list(applets.values())
|
||||
|
||||
results: List[Dict[str, Any]] = []
|
||||
|
||||
for applet_id, info in applets.items():
|
||||
@@ -96,9 +97,13 @@ class RegistryClient:
|
||||
|
||||
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."""
|
||||
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", {})
|
||||
return applets.get(clean_id)
|
||||
|
||||
Reference in New Issue
Block a user