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

feat: move --profile and --target to global config #7920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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-20230622-122252.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Move `--profile` and `--target` to global config, as well as allow these flags
to be set by environment variables (`DBT_TARGET` and `DBT_PROFILE`)
time: 2023-06-22T12:22:52.491092-04:00
custom:
Author: rexledesma
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 @@ -142,11 +142,13 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
@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
@p.use_colors
@p.use_colors_file
@p.use_experimental_parser
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/test_cli_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,40 @@ 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 = []

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

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

cli_params += ["run"]

context = self.make_dbt_context("run", cli_params)

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