MCPcopy
hub / github.com/ChristianLempa/boilerplates / search_templates

Function search_templates

cli/core/module/base_commands.py:128–169  ·  view source on GitHub ↗

Search for templates by ID containing the search string.

(module_instance, query: str)

Source from the content-addressed store, hash-verified

126
127
128def search_templates(module_instance, query: str) -> list:
129 """Search for templates by ID containing the search string."""
130 logger.debug(f"Searching templates for module '{module_instance.name}' with query='{query}'")
131
132 # Load templates with search filter using centralized helper
133 filtered_templates = module_instance._load_all_templates(lambda t: query.lower() in t.id.lower())
134
135 if filtered_templates:
136 logger.info(f"Found {len(filtered_templates)} templates matching '{query}' for module '{module_instance.name}'")
137
138 def format_template_row(template):
139 name = template.metadata.name or "Unnamed Template"
140 tags_list = template.metadata.tags or []
141 tags = ", ".join(tags_list) if tags_list else "-"
142 version = template.metadata.version.name if template.metadata.version else ""
143 library_name = template.metadata.library or ""
144 library_type = template.metadata.library_type or "git"
145 # Format library with icon and color
146 icon = IconManager.UI_LIBRARY_STATIC if library_type == "static" else IconManager.UI_LIBRARY_GIT
147 color = "yellow" if library_type == "static" else "blue"
148 library_display = f"[{color}]{icon} {library_name}[/{color}]"
149 return (template.id, name, tags, version, library_display)
150
151 module_instance.display.data_table(
152 columns=[
153 {"name": "ID", "style": "bold", "no_wrap": True},
154 {"name": "Name"},
155 {"name": "Tags"},
156 {"name": "Version", "no_wrap": True},
157 {"name": "Library", "no_wrap": True},
158 ],
159 rows=filtered_templates,
160 row_formatter=format_template_row,
161 )
162 else:
163 logger.info(f"No templates found matching '{query}' for module '{module_instance.name}'")
164 module_instance.display.warning(
165 f"No templates found matching '{query}'",
166 context=f"module '{module_instance.name}'",
167 )
168
169 return filtered_templates
170
171
172def show_template(module_instance, id: str, var: list[str] | None = None, var_file: str | None = None) -> None:

Callers 1

searchMethod · 0.85

Calls 4

_load_all_templatesMethod · 0.80
infoMethod · 0.45
data_tableMethod · 0.45
warningMethod · 0.45

Tested by

no test coverage detected