Skip to content

Commit

Permalink
Comments, fail_fast, cleanup argparse Namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Sep 1, 2021
1 parent 7572700 commit 2956b6a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
SEND_ANONYMOUS_USAGE_STATS = None
PRINTER_WIDTH = None

# Global CLI defaults
# Global CLI defaults. These flags are set from three places:
# CLI args, environment variables, and user_config (profiles.yml).
# Environment variables use the pattern 'DBT_{flag name}', like DBT_PROFILES_DIR
flag_defaults = {
"USE_EXPERIMENTAL_PARSER": False,
"WARN_ERROR": False,
Expand Down Expand Up @@ -106,6 +108,7 @@ def get_flag_value(flag, args, user_config):
lc_flag = flag.lower()
flag_value = getattr(args, lc_flag, None)
if flag_value is None:
# Environment variables use pattern 'DBT_{flag name}'
env_flag = f"DBT_{flag}"
env_value = os.getenv(env_flag)
if env_value is not None:
Expand Down
33 changes: 28 additions & 5 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _build_build_subparser(subparsers, base_subparser):
sub.add_argument(
'-x',
'--fail-fast',
dest='sub_fail_fast',
action='store_true',
help='''
Stop execution upon a first failure.
Expand Down Expand Up @@ -488,6 +489,7 @@ def _build_run_subparser(subparsers, base_subparser):
run_sub.add_argument(
'-x',
'--fail-fast',
dest='sub_fail_fast',
action='store_true',
help='''
Stop execution upon a first failure.
Expand Down Expand Up @@ -706,6 +708,7 @@ def _build_test_subparser(subparsers, base_subparser):
sub.add_argument(
'-x',
'--fail-fast',
dest='sub_fail_fast',
action='store_true',
help='''
Stop execution upon a first test failure.
Expand Down Expand Up @@ -1038,6 +1041,16 @@ def parse_args(args, cls=DBTArgumentParser):
'''
)

p.add_argument(
'-x',
'--fail-fast',
dest='fail_fast',
action='store_true',
help='''
Stop execution upon a first failure.
'''
)

subs = p.add_subparsers(title="Available sub-commands")

base_subparser = _build_base_subparser()
Expand Down Expand Up @@ -1086,13 +1099,23 @@ def parse_args(args, cls=DBTArgumentParser):
parsed = p.parse_args(args)

# profiles_dir is set before subcommands and after, so normalize
sub_profiles_dir = getattr(parsed, 'sub_profiles_dir', None)
profiles_dir = sub_profiles_dir if sub_profiles_dir else parsed.profiles_dir
parsed.profiles_dir = os.path.abspath(profiles_dir)
if hasattr(parsed, 'sub_profiles_dir'):
if parsed.sub_profiles_dir is not None:
parsed.profiles_dir = parsed.sub_profiles_dir
parsed.profiles_dir = os.path.abspath(parsed.profiles_dir)
delattr(parsed, 'sub_profiles_dir')

# version_check is set before subcommands and after, so normalize
if getattr(parsed, 'sub_version_check', None) is False:
parsed.version_check = False
if hasattr(parsed, 'sub_version_check'):
if parsed.sub_version_check is not None:
parsed.version_check = False
delattr(parsed, 'sub_version_check')

# fail_fast is set before subcommands and after, so normalize
if hasattr(parsed, 'sub_fail_fast'):
if parsed.sub_fail_fast is not None:
parsed.fail_fast = True
delattr(parsed, 'sub_fail_fast')

if getattr(parsed, 'project_dir', None) is not None:
expanded_user = os.path.expanduser(parsed.project_dir)
Expand Down

0 comments on commit 2956b6a

Please sign in to comment.