Skip to content

Commit

Permalink
feat: Add support for a --version flag. Assuming manual control 🤖
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyager committed Mar 23, 2024
1 parent 55eebc1 commit 154cd51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dbt_meshify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def owner(func):

@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
if kwargs.get('owner_name') is None and kwargs.get('owner_email') is None:
if kwargs.get("owner_name") is None and kwargs.get("owner_email") is None:
raise click.UsageError(
"Groups require an Owner to be defined using --owner-name and/or --owner-email."
)
Expand All @@ -136,3 +136,10 @@ def format_usage(self, ctx: Context, formatter: HelpFormatter) -> None:
pieces = self.collect_usage_pieces(ctx)
pieces = pieces[1:] + [pieces[0]]
formatter.write_usage(ctx.command_path, " ".join(pieces))


def get_version() -> str:
"""Get the current package version number."""
import importlib.metadata

return importlib.metadata.version("dbt-meshify")
17 changes: 15 additions & 2 deletions dbt_meshify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
create_path,
exclude,
exclude_projects,
get_version,
group_yml_path,
latest,
owner,
Expand Down Expand Up @@ -72,15 +73,27 @@ def logger_operation_level_filter(record):


# define cli group
@click.group()
@click.group(invoke_without_command=True)
@click.option("--dry-run", is_flag=True)
@click.option("--debug", is_flag=True)
def cli(dry_run: bool, debug: bool):
@click.option("--version", is_flag=True, help="Show version information and exit")
@click.pass_context
def cli(ctx, dry_run: bool, debug: bool, version: bool):
log_level = "DEBUG" if debug else "INFO"

logger.add(sys.stdout, format=log_format, filter=logger_log_level_filter, level=log_level)
logger.add(sys.stdout, format=operation_format, filter=logger_operation_level_filter)

# If the --version flag has been provided, print the version number and exit.
if version:
print(get_version())
exit(0)

# If a command has not been provided, print the help text and exit.
if ctx.invoked_subcommand is None:
print(ctx.get_help())
exit(0)


@cli.result_callback()
def handle_change_sets(change_sets=List[ChangeSet], dry_run=False, **kwargs):
Expand Down

0 comments on commit 154cd51

Please sign in to comment.