Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --target and --profile to global config #9081

Merged
merged 15 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20231115-092005.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Move --target and --profile command line flags to global config. Also, allow
these flags to be set by environment variable (DBT_TARGET, and DBT_PROFILE).
barton996 marked this conversation as resolved.
Show resolved Hide resolved
time: 2023-11-15T09:20:05.12461Z
custom:
Author: barton996
Issue: "7798"
2 changes: 2 additions & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ def global_flags(func):
@p.populate_cache
@p.print
@p.printer_width
@p.profile
@p.quiet
@p.record_timing_info
@p.send_anonymous_usage_stats
@p.single_threaded
@p.static_parser
@p.target
barton996 marked this conversation as resolved.
Show resolved Hide resolved
@p.use_colors
@p.use_colors_file
@p.use_experimental_parser
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@

profile = click.option(
"--profile",
envvar=None,
envvar="DBT_TARGET",
help="Which existing profile to load. Overrides setting in dbt_project.yml.",
)

Expand Down Expand Up @@ -566,7 +566,7 @@
target = click.option(
"--target",
"-t",
envvar=None,
envvar="DBT_PROFILE",
help="Which target to load for the given profile",
)

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_cli_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,38 @@ def test_log_file_settings_from_config(self):
assert flags.USE_COLORS is True
assert flags.USE_COLORS_FILE is False

@pytest.mark.parametrize(
"cli_profile, flag_profile",
[
(None, None),
("profile", "profile"),
],
)
@pytest.mark.parametrize(
"cli_target, flag_target",
[
(None, None),
("target", "target"),
],
)
def test_profile_settings_interaction(
self, cli_profile, cli_target, flag_profile, flag_target
):
cli_params = ["run"]

if cli_profile:
cli_params = ["--profile", cli_profile] + cli_params

if cli_target:
cli_params = ["--target", cli_target] + cli_params

context = self.make_dbt_context("run", cli_params)
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved

flags = Flags(context, None)

assert flags.PROFILE == flag_profile
assert flags.TARGET == flag_target

def test_duplicate_flags_raises_error(self):
parent_context = self.make_dbt_context("parent", ["--version-check"])
context = self.make_dbt_context("child", ["--version-check"], parent_context)
Expand Down
Loading