feat(cli): enhance search and list commands to show all registry applets and support remote discovery
This commit is contained in:
+45
-37
@@ -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,44 +119,54 @@ 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"))
|
||||||
return 0
|
if not show_remote:
|
||||||
|
print("\nRun 'gravitiny search' or 'gravitiny list --all' to discover available applets in the registry.")
|
||||||
|
return 0
|
||||||
|
|
||||||
print(catalog.format("commands.list.installed_header", count=len(applets)))
|
if applets:
|
||||||
print()
|
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
|
||||||
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
|
shims_w = max(len(catalog.get("commands.list.table_col_shims")), max(len(", ".join(a.shims)) for a in applets.values())) + 2
|
||||||
shims_w = max(len(catalog.get("commands.list.table_col_shims")), max(len(", ".join(a.shims)) for a in applets.values())) + 2
|
|
||||||
|
|
||||||
header = (
|
header = (
|
||||||
f"{catalog.get('commands.list.table_col_id'):<{id_w}} "
|
f"{catalog.get('commands.list.table_col_id'):<{id_w}} "
|
||||||
f"{catalog.get('commands.list.table_col_name'):<{name_w}} "
|
f"{catalog.get('commands.list.table_col_name'):<{name_w}} "
|
||||||
f"{catalog.get('commands.list.table_col_version'):<{ver_w}} "
|
f"{catalog.get('commands.list.table_col_version'):<{ver_w}} "
|
||||||
f"{catalog.get('commands.list.table_col_shims'):<{shims_w}} "
|
f"{catalog.get('commands.list.table_col_shims'):<{shims_w}} "
|
||||||
f"{catalog.get('commands.list.table_col_description')}"
|
f"{catalog.get('commands.list.table_col_description')}"
|
||||||
)
|
|
||||||
separator = "-" * max(len(header), 70)
|
|
||||||
|
|
||||||
print(header)
|
|
||||||
print(separator)
|
|
||||||
|
|
||||||
for applet in sorted(applets.values(), key=lambda x: x.id):
|
|
||||||
shims_str = ", ".join(applet.shims) if applet.shims else applet.id
|
|
||||||
print(
|
|
||||||
f"{applet.id:<{id_w}} "
|
|
||||||
f"{applet.name:<{name_w}} "
|
|
||||||
f"{applet.version:<{ver_w}} "
|
|
||||||
f"{shims_str:<{shims_w}} "
|
|
||||||
f"{applet.description}"
|
|
||||||
)
|
)
|
||||||
|
separator = "-" * max(len(header), 70)
|
||||||
|
|
||||||
|
print(header)
|
||||||
|
print(separator)
|
||||||
|
|
||||||
|
for applet in sorted(applets.values(), key=lambda x: x.id):
|
||||||
|
shims_str = ", ".join(applet.shims) if applet.shims else applet.id
|
||||||
|
print(
|
||||||
|
f"{applet.id:<{id_w}} "
|
||||||
|
f"{applet.name:<{name_w}} "
|
||||||
|
f"{applet.version:<{ver_w}} "
|
||||||
|
f"{shims_str:<{shims_w}} "
|
||||||
|
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":
|
||||||
|
|||||||
@@ -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", {})
|
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)
|
return applets.get(clean_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user