Skip to content

Commit

Permalink
feat(cli): Changed CLI parameters for Ownership to be explicit
Browse files Browse the repository at this point in the history
I've updated how CLI arguments for owners work. Specifically, I've changed to arguments to no longer use user input to know the field name. Instad, there are new `--owner-name`, `--owner-email`, and `--owner-properties` fields. The `--owner-properties` field is used to supply a YML string that is parsed for extra properities in the object.

BREAKING CHANGE: Creates a breaking change in CLI arguments relative to current version
Resolves: dbt-labs#65
  • Loading branch information
nicholasyager committed Jun 25, 2023
1 parent a4efdc5 commit 9c760c7
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions dbt_meshify/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import functools
import os
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

import click
import yaml
from dbt.contracts.graph.unparsed import Owner

from .dbt_projects import DbtProject, DbtProjectHolder, DbtSubProject
Expand Down Expand Up @@ -36,12 +38,19 @@
help="The dbt selection syntax specifying the resources to include in the operation",
)

owner = click.option(
"--owner",
nargs=2,
multiple=True,
type=click.Tuple([str, str]),
help="A tuple of Owner information for the group. For example " "`--owner name example`",
owner_name = click.option(
"--owner-name",
help="The group Owner's name.",
)

owner_email = click.option(
"--owner-email",
help="The group Owner's email address.",
)

owner_properties = click.option(
"--owner-properties",
help="Additional properties to assign to a group Owner.",
)

selector = click.option(
Expand All @@ -51,6 +60,20 @@
)


def owner(func):
"""Add click options and argument validation for creating Owner objects."""

@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
print("Validating owner configs.")
# Do something before
value = func(*args, **kwargs)
# Do something after
return value

return wrapper_decorator


# define cli group
@click.group()
def cli():
Expand Down Expand Up @@ -187,14 +210,19 @@ def add_version(select, exclude, project_path, selector, prerelease, defined_in)
@select
@selector
@click.argument("name")
@owner_name
@owner_email
@owner_properties
@owner
@group_yml_path
def create_group(
name,
project_path: os.PathLike,
owner: List[Tuple[str, str]],
group_yml_path: os.PathLike,
select: str,
owner_name: Optional[str] = None,
owner_email: Optional[str] = None,
owner_properties: str = '{}',
exclude: Optional[str] = None,
selector: Optional[str] = None,
):
Expand All @@ -216,7 +244,9 @@ def create_group(
"The provided group-yml-path is not contained within the provided dbt project."
)

owner: Owner = Owner(**{key: value for key, value in owner})
owner: Owner = Owner(
name=owner_name, email=owner_email, _extra=yaml.safe_load(owner_properties)
)

grouper = ResourceGrouper(project)
grouper.add_group(
Expand All @@ -235,16 +265,20 @@ def create_group(
@select
@selector
@click.argument("name")
@owner
@owner_name
@owner_email
@owner_properties
@group_yml_path
@click.pass_context
def group(
ctx,
name,
project_path: os.PathLike,
owner: List[Tuple[str, str]],
group_yml_path: os.PathLike,
select: str,
owner_name: Optional[str] = None,
owner_email: Optional[str] = None,
owner_properties: Optional[str] = None,
exclude: Optional[str] = None,
selector: Optional[str] = None,
):
Expand Down

0 comments on commit 9c760c7

Please sign in to comment.