Skip to content

Commit

Permalink
first pass: dbt.cli.main.handle_and_check
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Dec 5, 2022
1 parent 44b457c commit b608756
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
from dbt.tracking import initialize_from_flags, track_run
from dbt.config.runtime import load_project
from dbt.task.deps import DepsTask
from typing import Optional


def make_context(args, command) -> Optional[click.Context]:
ctx = command.make_context(command.name, args)

ctx.invoked_subcommand = ctx.protected_args[0] if ctx.protected_args else None
return ctx

def handle_and_check(args):
ctx = make_context(args, cli)
res, success = cli.invoke(ctx)
return res, success

def cli_runner():
# Alias "list" to "ls"
ls = copy(cli.commands["list"])
Expand Down Expand Up @@ -130,6 +142,7 @@ def clean(ctx, **kwargs):
"""Delete all folders in the clean-targets list (usually the dbt_packages and target directories.)"""
flags = Flags()
click.echo(f"`{inspect.stack()[0][3]}` called\n flags: {flags}")
return None, True


# dbt docs
Expand Down Expand Up @@ -200,6 +213,7 @@ def compile(ctx, **kwargs):
"""Generates executable SQL from source, model, test, and analysis files. Compiled SQL files are written to the target/ directory."""
flags = Flags()
click.echo(f"`{inspect.stack()[0][3]}` called\n flags: {flags}")
return None, True


# dbt debug
Expand Down Expand Up @@ -316,6 +330,7 @@ def run(ctx, **kwargs):
"""Compile SQL and execute against the current target database."""
flags = Flags()
click.echo(f"`{inspect.stack()[0][3]}` called\n flags: {flags}")
return None, True


# dbt run operation
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"--log-path",
envvar="DBT_LOG_PATH",
help="Configure the 'log-path'. Only applies this setting for the current run. Overrides the 'DBT_LOG_PATH' if it is set.",
default=Path.cwd() / "logs",
default=lambda: Path.cwd() / "logs",
type=click.Path(resolve_path=True, path_type=Path),
)

Expand Down Expand Up @@ -222,15 +222,15 @@
"--profiles-dir",
envvar="DBT_PROFILES_DIR",
help="Which directory to look in for the profiles.yml file. If not set, dbt will look in the current working directory first, then HOME/.dbt/",
default=default_profiles_dir(),
default=lambda: default_profiles_dir(),
type=click.Path(exists=True),
)

project_dir = click.option(
"--project-dir",
envvar=None,
help="Which directory to look in for the dbt_project.yml file. Default is the current working directory and its parents.",
default=default_project_dir(),
default=lambda: default_project_dir(),
type=click.Path(exists=True),
)

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from contextlib import contextmanager
from dbt.adapters.factory import Adapter

from dbt.main import handle_and_check
from dbt.cli.main import handle_and_check
from dbt.logger import log_manager
from dbt.contracts.graph.manifest import Manifest
from dbt.events.functions import fire_event, capture_stdout_logs, stop_capture_stdout_logs, reset_metadata_vars
Expand Down

0 comments on commit b608756

Please sign in to comment.