parser.py (parse_route, ArgSpec, Route).
Route syntax
- Tokens wrapped in
<>are required;[]makes the argument optional. - If no type is provided (
<name>or[name]), the parser defaults tostr. - Whitespace separates tokens; put multi-word help text in docstrings instead.
Type resolution pipeline
When a command runs, Runegraft follows this order:- Custom route types registered via
CLI.type("name")take precedence. - Built-in converters from
types.BUILTIN_TYPEShandle known tokens such asint,url, orjson. - If no route token is found, the function’s type hints decide how to coerce option values. For example, an option annotated as
Pathusestype_name_for_py()to map to thepathconverter. - When none of the above apply, the raw string value is passed through.
ValueError or TypeErrorValue raised during conversion is surfaced to the user as a friendly error message.
Built-in converters
| Token | Converts to | Notes |
|---|---|---|
str, string, text | str | No transformation beyond trimming quotes. |
int | int | Raises if the input is not numeric. |
float | float | Accepts decimal input. |
bool | bool | Handles values like true/false, yes/no, 1/0. |
path | pathlib.Path | Expands ~ on load. |
url | str | Requires a scheme; enforces host unless file://. |
json | Any | Parses JSON strings into Python objects. |
uuid | uuid.UUID | Validates canonical UUID text. |
date | datetime.date | ISO YYYY-MM-DD. |
datetime | datetime.datetime | ISO 8601 timestamp. |
runegraft.types, you can import BUILTIN_TYPES and extend or override entries before wiring CLI commands if necessary.
Usage strings and help
Theusage_for_route helper composes readable usage strings (install <url:url> [target:path] [--force]). These strings end up in the help table and are also used by the shell validator to offer precise error messages while the user types.
If you add new option converters or custom route tokens, the type_name_for_py helper ensures that help text reflects the human-friendly token name rather than the internal Python class.