Coverage for src/commands/catalog.py: 42%
19 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-06-05 22:56 -0700
« prev ^ index » next coverage.py v7.8.0, created at 2025-06-05 22:56 -0700
1"""
2Command for showing details of a specific Unity Catalog catalog.
3"""
5from typing import Optional, Any
6from src.clients.databricks import DatabricksAPIClient
7from src.commands.base import CommandResult
8from src.catalogs import get_catalog as get_catalog_details
9from src.command_registry import CommandDefinition
10import logging
13def handle_command(
14 client: Optional[DatabricksAPIClient], **kwargs: Any
15) -> CommandResult:
16 """
17 Get details of a specific catalog from Unity Catalog.
19 Args:
20 client: DatabricksAPIClient instance for API calls
21 **kwargs: Command parameters
22 - name: Name of the catalog to get details for
24 Returns:
25 CommandResult with catalog details if successful
26 """
27 if not client:
28 return CommandResult(
29 False,
30 message="No Databricks client available. Please set up your workspace first.",
31 )
33 # Extract parameters
34 catalog_name = kwargs.get("name")
36 try:
37 # Get catalog details
38 catalog = get_catalog_details(client, catalog_name)
40 if not catalog:
41 return CommandResult(False, message=f"Catalog '{catalog_name}' not found.")
43 return CommandResult(
44 True,
45 data=catalog,
46 message=f"Catalog details for '{catalog_name}' (Type: {catalog.get('type', 'Unknown')}).",
47 )
48 except Exception as e:
49 logging.error(f"Error getting catalog details: {str(e)}")
50 return CommandResult(
51 False, message=f"Failed to get catalog details: {str(e)}", error=e
52 )
55DEFINITION = CommandDefinition(
56 name="catalog",
57 description="Show details of a specific Unity Catalog catalog.",
58 handler=handle_command,
59 parameters={
60 "name": {
61 "type": "string",
62 "description": "Name of the catalog to get details for.",
63 }
64 },
65 required_params=["name"],
66 tui_aliases=["/catalog"],
67 needs_api_client=True,
68 visible_to_user=True,
69 visible_to_agent=True,
70 agent_display="full", # Show full catalog details to agents
71 usage_hint="Usage: /catalog --name <catalog_name>",
72)