forked from SQLMesh/sqlmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.py
More file actions
25 lines (18 loc) · 737 Bytes
/
options.py
File metadata and controls
25 lines (18 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import typing as t
import click
from click.core import Context, Parameter
class YamlParamType(click.ParamType):
name = "yaml"
def convert(
self, value: t.Any, param: t.Optional[Parameter], ctx: t.Optional[Context]
) -> t.Any:
if not isinstance(value, str):
self.fail(f"Input value '{value}' should be a string", param, ctx)
from sqlmesh.utils import yaml
try:
parsed = yaml.load(source=value, render_jinja=False)
except:
self.fail(f"String '{value}' is not valid YAML", param, ctx)
if not isinstance(parsed, dict):
self.fail(f"String '{value}' did not evaluate to a dict, got: {parsed}", param, ctx)
return parsed