Compare commits

...

1 Commits

Author SHA1 Message Date
Courtney Holcomb
6829f216e2 Psuedocode: Add MF commands to CLI 2023-03-30 16:43:20 -07:00
2 changed files with 33 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
import click
from typing import Optional
import importlib
from dbt.cli.main import cli as dbt
@@ -13,4 +14,23 @@ def make_context(args, command=dbt) -> Optional[click.Context]:
ctx.invoked_subcommand = ctx.protected_args[0] if ctx.protected_args else None
ctx.obj = {}
# Build MetricFlowClient if metricflow is installed (could move this to a click.option)
ctx.obj["mf_client"] = None
if importlib.util.find_spec("metricflow") is not None:
from metricflow.api.metricflow_client import MetricFlowClient
from metricflow.model.objects.user_configured_model import UserConfiguredModel
from metricflow.sql_clients.sql_utils import make_sql_client
# Fetch manifest and pull out what's needed to build UserConfiguredModel
user_configured_model = UserConfiguredModel()
# Parse profiles file to get DW connection details (url, pw, schema)
sql_client = make_sql_client(url="", password="")
ctx.obj["mf_client"] = MetricFlowClient(
user_configured_model=user_configured_model,
sql_client=sql_client,
system_schema="",
)
return ctx

View File

@@ -622,6 +622,19 @@ snapshot_freshness.hidden = True
cli.commands["source"].add_command(snapshot_freshness, "snapshot-freshness") # type: ignore
@cli.command("list-metrics")
def list_metrics(ctx, **kwargs):
"""Lists metrics defined in YAML files."""
mf_client = ctx.obj["mf_client"]
if mf_client is not None:
return mf_client.list_metrics()
else:
raise Exception("Please install `metricflow` to use this command.")
# Other possible commands to add: list-dimensions, get-dimension-values, query, validate-configs
# dbt test
@cli.command("test")
@click.pass_context