Utility Functions
Angreal provides utility functions for common operations when working with projects and commands.
Overview
Section titled “Overview”These utilities help with:
- Project Structure - Locating the project root directory
- Context Access - Retrieving template variables from project initialization
- Version Checking - Ensuring the right Angreal version is used
- Command Aliasing - Creating custom command names for white-labeling
Key Functions
Section titled “Key Functions”| Function | Description | Documentation |
|---|---|---|
get_root |
Get the root directory of the Angreal project | API Reference |
get_context |
Get the context from angreal.toml used to render the template | API Reference |
required_version |
Check for minimum required Angreal version | API Reference |
register_entrypoint |
Create a command alias for angreal (white-labeling) | API Reference |
list_entrypoints |
List all registered command aliases | API Reference |
unregister_entrypoint |
Remove a command alias | API Reference |
cleanup_entrypoints |
Remove all registered command aliases | API Reference |
Examples
Section titled “Examples”Basic Project Operations
Section titled “Basic Project Operations”import angrealimport os
# Check for required versionangreal.required_version("2.0.0")
# Get the project rootroot_dir = angreal.get_root()templates_dir = os.path.join(root_dir, "templates")
print(f"Project root: {root_dir}")print(f"Templates directory: {templates_dir}")Context Access
Section titled “Context Access”import angreal
# Get the context from angreal.tomlcontext = angreal.get_context()
if context: print("Project name:", context.get("project_name", "Not set")) print("Version:", context.get("version", "Not set"))else: print("No context found (not in an angreal project)")Command Aliasing
Section titled “Command Aliasing”import angreal
# Create a command alias for white-labelingangreal.register_entrypoint("mycompany-tool")
# List all registered aliasesaliases = angreal.list_entrypoints()print("Registered aliases:", aliases)
# Remove an aliasangreal.unregister_entrypoint("mycompany-tool")
# Clean up all aliasesangreal.cleanup_entrypoints()