Coverage for src/ui/help_formatter.py: 3%
89 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"""
2Help text formatter for the TUI interface.
4This module provides functions to format help text for the TUI interface
5based on the registered commands in the command registry.
6"""
8from typing import Dict
9from src.command_registry import CommandDefinition
12def format_help_text(
13 commands: Dict[str, CommandDefinition], tui_map: Dict[str, str]
14) -> str:
15 """
16 Format help text for TUI display based on available commands.
18 Args:
19 commands: Dictionary of command definitions from the registry
20 tui_map: Mapping of TUI commands to registry commands
22 Returns:
23 Formatted help text as a string
24 """
25 # Create reverse mapping of registry names to TUI aliases for easy lookup
26 registry_to_tui = {}
27 for tui_cmd, registry_name in tui_map.items():
28 if registry_name in registry_to_tui:
29 registry_to_tui[registry_name].append(tui_cmd)
30 else:
31 registry_to_tui[registry_name] = [tui_cmd]
33 # Create a mapping for TUI alias lookup (without slash prefix)
34 # This allows us to look up commands by their TUI name without the slash
35 tui_to_registry = {}
36 for tui_cmd, registry_name in tui_map.items():
37 # Store both with and without slash prefix for flexibility
38 clean_name = tui_cmd[1:] if tui_cmd.startswith("/") else tui_cmd
39 tui_to_registry[clean_name] = registry_name
41 # Group commands by category as per new format
42 categories = {
43 "Authentication & Workspace": [
44 "workspace-selection",
45 "select-workspace",
46 "databricks-login",
47 "amperity-login",
48 "logout",
49 "status",
50 "setup_wizard",
51 ],
52 "Catalog & Schema Management": [
53 "list_catalogs",
54 "catalog",
55 "list_schemas",
56 "schema",
57 "list_tables",
58 "table",
59 "catalog-selection",
60 "set-catalog",
61 "schema-selection",
62 "set-schema",
63 ],
64 "Model & Endpoint Management": [
65 "models",
66 "detailed-models",
67 "list_models",
68 "model-selection",
69 "select-model",
70 ],
71 "SQL Warehouse Management": [
72 "list_warehouses",
73 "warehouse",
74 "warehouse-selection",
75 "select-warehouse",
76 "create_warehouse",
77 "run-sql",
78 ],
79 "Volume Management": [
80 "list_volumes",
81 "create-volume",
82 "upload-file",
83 ],
84 "PII & Data Management": [
85 "scan-schema-for-pii",
86 "tag-pii-columns",
87 "setup_stitch",
88 "add_stitch_report",
89 ],
90 "Job Management": [
91 "launch-job",
92 "job-status",
93 ],
94 "Utilities": [
95 "help",
96 "bug",
97 "agent",
98 "exit",
99 ],
100 }
102 # Format each command with proper spacing
103 def format_command(cmd_name: str) -> str:
104 # First, try to look up the command by its name directly
105 cmd = commands.get(cmd_name)
107 # If not found, try to look it up by TUI alias (without slash)
108 if not cmd and cmd_name in tui_to_registry:
109 registry_name = tui_to_registry[cmd_name]
110 cmd = commands.get(registry_name)
112 # If still not found, return empty string
113 if not cmd:
114 return ""
116 # Get TUI aliases for this command
117 tui_aliases = registry_to_tui.get(cmd.name, [])
118 if not tui_aliases:
119 # Use the command name with a slash if no aliases defined
120 tui_aliases = [f"/{cmd.name}"]
122 # Select the first alias (primary command)
123 alias = tui_aliases[0]
125 # Add parameter placeholder if applicable
126 if cmd_name == "workspace-selection" or cmd.name == "workspace-selection":
127 alias = f"{alias} <url>"
128 elif cmd_name == "select-workspace" or cmd.name == "select-workspace":
129 alias = f"{alias} <workspace_name>"
130 elif cmd_name == "databricks-login" or cmd.name == "databricks-login":
131 alias = f"{alias} <token>"
132 elif cmd_name == "amperity-login" or cmd.name == "amperity-login":
133 alias = f"{alias} <token>"
134 elif cmd_name == "catalog" or cmd.name == "catalog":
135 alias = f"{alias} <catalog_name>"
136 elif cmd_name == "schema" or cmd.name == "schema":
137 alias = f"{alias} <schema_name>"
138 elif cmd_name == "table" or cmd.name == "table":
139 alias = f"{alias} <table_name>"
140 elif cmd_name == "catalog-selection" or cmd.name == "catalog-selection":
141 alias = f"{alias} <catalog_name>"
142 elif cmd_name == "set-catalog" or cmd.name == "set-catalog":
143 alias = f"{alias} <catalog_name>"
144 elif cmd_name == "schema-selection" or cmd.name == "schema-selection":
145 alias = f"{alias} <schema_name>"
146 elif cmd_name == "set-schema" or cmd.name == "set-schema":
147 alias = f"{alias} <schema_name>"
148 elif cmd_name == "model-selection" or cmd.name == "model-selection":
149 alias = f"{alias} <model_name>"
150 elif cmd_name == "select-model" or cmd.name == "select-model":
151 alias = f"{alias} <model_name>"
152 elif cmd_name == "warehouse-selection" or cmd.name == "warehouse-selection":
153 alias = f"{alias} <warehouse_id>"
154 elif cmd_name == "select-warehouse" or cmd.name == "select-warehouse":
155 alias = f"{alias} <warehouse_id>"
156 elif cmd_name == "warehouse" or cmd.name == "warehouse":
157 alias = f"{alias} <warehouse_id>"
158 elif cmd_name == "agent" or cmd.name == "agent":
159 alias = f"{alias} <query>"
160 elif cmd_name == "scan-schema-for-pii" or cmd.name == "scan-schema-for-pii":
161 alias = f"{alias} <table_name>"
162 elif cmd_name == "tag-pii-columns" or cmd.name == "tag-pii-columns":
163 alias = f"{alias} <table_name>"
164 elif cmd_name == "create-volume" or cmd.name == "create-volume":
165 alias = f"{alias} --name <volume_name> [--catalog_name <catalog>] [--schema_name <schema>] [--volume_type MANAGED|EXTERNAL]"
166 elif cmd_name == "upload-file" or cmd.name == "upload-file":
167 alias = f"{alias} <file_path> <volume_path>"
168 elif cmd_name == "launch-job" or cmd.name == "launch-job":
169 alias = f"{alias} [--filter <filter>]"
170 elif cmd_name == "job-status" or cmd.name == "job-status":
171 alias = f"{alias} <run_id>"
172 elif cmd_name == "run-sql" or cmd.name == "run-sql":
173 alias = f"{alias} <query>"
174 elif cmd_name == "bug" or cmd.name == "bug":
175 alias = f"{alias} <description>"
177 # Format the command with its description
178 return f"{alias:<30} - {cmd.description}"
180 # Start with Chuck Data CLI Commands header
181 help_lines = ["", "Chuck Data CLI Commands:"]
183 # Build help text with sections
184 for category, cmd_list in categories.items():
185 category_commands = []
186 for cmd_name in cmd_list:
187 cmd_help = format_command(cmd_name)
188 if cmd_help:
189 category_commands.append(cmd_help)
191 if category_commands:
192 help_lines.append("") # Add spacing
193 help_lines.append(f" [bold]{category}:[/bold]")
194 for cmd in category_commands:
195 help_lines.append(f" {cmd}")
197 # Add extra spacing for readability
198 help_lines.append("")
200 # Join all lines
201 return "\n".join(help_lines)