Initial upload: Local LLM Prompt Manager CLI tool
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-05 20:56:05 +00:00
parent bffb8d1c8a
commit a9d8992203

48
src/utils/__init__.py Normal file
View File

@@ -0,0 +1,48 @@
"""Utility functions for the prompt manager."""
import re
from pathlib import Path
from typing import Any
def ensure_directory(path: str) -> Path:
"""Create directory if it doesn't exist."""
path = Path(path)
path.mkdir(parents=True, exist_ok=True)
return path
def parse_key_value(key_value: str) -> tuple[str, str]:
"""Parse a key=value string into a tuple."""
if "=" not in key_value:
raise ValueError(f"Invalid key=value format: {key_value}")
key, value = key_value.split("=", 1)
return key.strip(), value.strip()
def validate_yaml_structure(data: dict[str, Any], required_fields: list[str]) -> list[str]:
"""Validate that required fields are present in YAML data."""
missing = []
for field in required_fields:
if field not in data:
missing.append(field)
return missing
def sanitize_filename(name: str) -> str:
"""Sanitize a string to be used as a filename."""
name = re.sub(r"[^\w\s-]", "", name)
name = re.sub(r"[\s-]+", "-", name)
return name.strip("-")
def format_tags(tags: list[str]) -> str:
"""Format tags for display."""
return ", ".join(tags) if tags else "None"
def truncate_text(text: str, max_length: int = 50) -> str:
"""Truncate text for display."""
if len(text) <= max_length:
return text
return text[:max_length - 3] + "..."