Skip to content

Commit

Permalink
Add --target and --profile to global config (#9081)
Browse files Browse the repository at this point in the history
* Add @p.profile and @p.target to the list of "global" CLI flags

* Add env vars (DBT_PROFILE, DBT_TARGET) to the params

* Add unit test

* Simplify unit test

* changie

* Update .changes/unreleased/Features-20231115-092005.yaml

Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>

* Fix incorrect envvar names

* Realign environment variable names

* Remove from specific subcommands

* Add test_global_flags_not_on_subcommands

* Remove one unnecessary test case

* Remove other unnecessary test case

---------

Co-authored-by: Doug Beatty <doug.beatty@dbtlabs.com>
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent 461e8e5 commit c6c0c79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20231115-092005.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Global config for --target and --profile CLI flags and DBT_TARGET and DBT_PROFILE environment variables.
time: 2023-11-15T09:20:05.12461Z
custom:
Author: barton996
Issue: "7798"
40 changes: 2 additions & 38 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ 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.state
@p.static_parser
@p.target
@p.use_colors
@p.use_colors_file
@p.use_experimental_parser
Expand Down Expand Up @@ -172,7 +174,6 @@ def cli(ctx, **kwargs):
@p.export_saved_queries
@p.full_refresh
@p.deprecated_include_saved_query
@p.profile
@p.profiles_dir
@p.project_dir
@p.resource_type
Expand All @@ -181,7 +182,6 @@ def cli(ctx, **kwargs):
@p.selector
@p.show
@p.store_failures
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -211,10 +211,8 @@ def build(ctx, **kwargs):
@click.pass_context
@global_flags
@p.clean_project_files_only
@p.profile
@p.profiles_dir
@p.project_dir
@p.target
@p.target_path
@p.vars
@requires.postflight
Expand Down Expand Up @@ -246,14 +244,12 @@ def docs(ctx, **kwargs):
@global_flags
@p.compile_docs
@p.exclude
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.empty_catalog
@p.static
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -284,10 +280,8 @@ def docs_generate(ctx, **kwargs):
@global_flags
@p.browser
@p.port
@p.profile
@p.profiles_dir
@p.project_dir
@p.target
@p.target_path
@p.vars
@requires.postflight
Expand Down Expand Up @@ -317,15 +311,13 @@ def docs_serve(ctx, **kwargs):
@p.full_refresh
@p.show_output_format
@p.introspect
@p.profile
@p.profiles_dir
@p.project_dir
@p.empty
@p.select
@p.selector
@p.inline
@p.compile_inject_ephemeral_ctes
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -360,13 +352,11 @@ def compile(ctx, **kwargs):
@p.show_output_format
@p.show_limit
@p.introspect
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.inline
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -398,10 +388,8 @@ def show(ctx, **kwargs):
@global_flags
@p.debug_connection
@p.config_dir
@p.profile
@p.profiles_dir_exists_false
@p.project_dir
@p.target
@p.vars
@requires.postflight
@requires.preflight
Expand All @@ -423,10 +411,8 @@ def debug(ctx, **kwargs):
@cli.command("deps")
@click.pass_context
@global_flags
@p.profile
@p.profiles_dir_exists_false
@p.project_dir
@p.target
@p.vars
@p.source
@p.lock
Expand Down Expand Up @@ -468,11 +454,9 @@ def deps(ctx, **kwargs):
@global_flags
# for backwards compatibility, accept 'project_name' as an optional positional argument
@click.argument("project_name", required=False)
@p.profile
@p.profiles_dir_exists_false
@p.project_dir
@p.skip_profile_setup
@p.target
@p.vars
@requires.postflight
@requires.preflight
Expand All @@ -495,14 +479,12 @@ def init(ctx, **kwargs):
@p.models
@p.output
@p.output_keys
@p.profile
@p.profiles_dir
@p.project_dir
@p.resource_type
@p.exclude_resource_type
@p.raw_select
@p.selector
@p.target
@p.target_path
@p.vars
@requires.postflight
Expand Down Expand Up @@ -536,10 +518,8 @@ def list(ctx, **kwargs):
@cli.command("parse")
@click.pass_context
@global_flags
@p.profile
@p.profiles_dir
@p.project_dir
@p.target
@p.target_path
@p.threads
@p.vars
Expand All @@ -561,13 +541,11 @@ def parse(ctx, **kwargs):
@global_flags
@p.exclude
@p.full_refresh
@p.profile
@p.profiles_dir
@p.project_dir
@p.empty
@p.select
@p.selector
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -599,8 +577,6 @@ def run(ctx, **kwargs):
@p.project_dir
@p.profiles_dir
@p.vars
@p.profile
@p.target
@p.target_path
@p.threads
@p.full_refresh
Expand Down Expand Up @@ -630,14 +606,12 @@ def retry(ctx, **kwargs):
@global_flags
@p.exclude
@p.full_refresh
@p.profile
@p.profiles_dir
@p.project_dir
@p.resource_type
@p.exclude_resource_type
@p.select
@p.selector
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -668,10 +642,8 @@ def clone(ctx, **kwargs):
@global_flags
@click.argument("macro")
@p.args
@p.profile
@p.profiles_dir
@p.project_dir
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -702,13 +674,11 @@ def run_operation(ctx, **kwargs):
@global_flags
@p.exclude
@p.full_refresh
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.show
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -737,12 +707,10 @@ def seed(ctx, **kwargs):
@click.pass_context
@global_flags
@p.exclude
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -781,12 +749,10 @@ def source(ctx, **kwargs):
@global_flags
@p.exclude
@p.output_path # TODO: Is this ok to re-use? We have three different output params, how much can we consolidate?
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.target
@p.target_path
@p.threads
@p.vars
Expand Down Expand Up @@ -822,13 +788,11 @@ def freshness(ctx, **kwargs):
@click.pass_context
@global_flags
@p.exclude
@p.profile
@p.profiles_dir
@p.project_dir
@p.select
@p.selector
@p.store_failures
@p.target
@p.target_path
@p.threads
@p.vars
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 @@ -342,7 +342,7 @@

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

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

Expand Down

0 comments on commit c6c0c79

Please sign in to comment.