From dc34e3b7dcd75d6bac02773efb955f27728205b8 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 23 Jan 2025 12:04:48 -0600 Subject: [PATCH 1/2] First pass of alphebetizing click option definitions --- core/dbt/cli/params.py | 362 ++++++++++++++++++++--------------------- 1 file changed, 181 insertions(+), 181 deletions(-) diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index 612728de222..49d814025a9 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -33,10 +33,10 @@ help="At start of run, populate relational cache only for schemas containing selected nodes, or for all schemas of interest.", ) -introspect = click.option( - "--introspect/--no-introspect", - envvar="DBT_INTROSPECT", - help="Whether to scaffold introspective queries as part of compilation", +clean_project_files_only = click.option( + "--clean-project-files-only / --no-clean-project-files-only", + envvar="DBT_CLEAN_PROJECT_FILES_ONLY", + help="If disabled, dbt clean will delete all paths specified in clean-paths, even if they're outside the dbt project.", default=True, ) @@ -69,6 +69,13 @@ help="Display debug logging during dbt execution. Useful for debugging and making bug reports.", ) +debug_connection = click.option( + "--connection", + envvar=None, + help="Test the connection to the target database independent of dependency checks.", + is_flag=True, +) + # flag was previously named DEFER_MODE defer = click.option( "--defer/--no-defer", @@ -76,6 +83,19 @@ help="If set, resolve unselected nodes by deferring to the manifest within the --state directory.", ) +defer_state = click.option( + "--defer-state", + envvar="DBT_DEFER_STATE", + help="Override the state directory for deferral only.", + type=click.Path( + dir_okay=True, + file_okay=False, + readable=True, + resolve_path=False, + path_type=Path, + ), +) + deprecated_defer = click.option( "--deprecated-defer", envvar="DBT_DEFER_TO_STATE", @@ -84,6 +104,44 @@ hidden=True, ) +deprecated_favor_state = click.option( + "--deprecated-favor-state", + envvar="DBT_FAVOR_STATE_MODE", + help="Internal flag for deprecating old env var.", +) + +# Renamed to --export-saved-queries +deprecated_include_saved_query = click.option( + "--include-saved-query/--no-include-saved-query", + envvar="DBT_INCLUDE_SAVED_QUERY", + help="Include saved queries in the list of resources to be selected for build command", + is_flag=True, + hidden=True, +) + +deprecated_print = click.option( + "--deprecated-print/--deprecated-no-print", + envvar="DBT_NO_PRINT", + help="Internal flag for deprecating old env var.", + default=True, + hidden=True, + callback=lambda ctx, param, value: not value, +) + +deprecated_state = click.option( + "--deprecated-state", + envvar="DBT_ARTIFACT_STATE_PATH", + help="Internal flag for deprecating old env var.", + hidden=True, + type=click.Path( + dir_okay=True, + file_okay=False, + readable=True, + resolve_path=True, + path_type=Path, + ), +) + empty = click.option( "--empty/--no-empty", envvar="DBT_EMPTY", @@ -91,6 +149,13 @@ is_flag=True, ) +empty_catalog = click.option( + "--empty-catalog", + help="If specified, generate empty catalog.json file during the `dbt docs generate` command.", + default=False, + is_flag=True, +) + event_time_end = click.option( "--event-time-end", envvar="DBT_EVENT_TIME_END", @@ -116,6 +181,33 @@ help="Specify the nodes to exclude.", ) +exclude_resource_type = click.option( + "--exclude-resource-types", + "--exclude-resource-type", + envvar="DBT_EXCLUDE_RESOURCE_TYPES", + help="Specify the types of resources that dbt will exclude", + type=ChoiceTuple( + [ + "metric", + "semantic_model", + "saved_query", + "source", + "analysis", + "model", + "test", + "unit_test", + "exposure", + "snapshot", + "seed", + "default", + ], + case_sensitive=False, + ), + cls=MultiOption, + multiple=True, + default=(), +) + export_saved_queries = click.option( "--export-saved-queries/--no-export-saved-queries", envvar="DBT_EXPORT_SAVED_QUERIES", @@ -137,12 +229,6 @@ help="If set, defer to the argument provided to the state flag for resolving unselected nodes, even if the node(s) exist as a database object in the current environment.", ) -deprecated_favor_state = click.option( - "--deprecated-favor-state", - envvar="DBT_FAVOR_STATE_MODE", - help="Internal flag for deprecating old env var.", -) - full_refresh = click.option( "--full-refresh", "-f", @@ -167,6 +253,26 @@ default="eager", ) +inline = click.option( + "--inline", + envvar=None, + help="Pass SQL inline to dbt compile and show", +) + +inline_direct = click.option( + "--inline-direct", + envvar=None, + help="Internal flag to pass SQL inline to dbt show. Do not load the entire project or apply templating.", + hidden=True, +) + +introspect = click.option( + "--introspect/--no-introspect", + envvar="DBT_INTROSPECT", + help="Whether to scaffold introspective queries as part of compilation", + default=True, +) + lock = click.option( "--lock", envvar=None, @@ -212,20 +318,6 @@ default="debug", ) -use_colors = click.option( - "--use-colors/--no-use-colors", - envvar="DBT_USE_COLORS", - help="Specify whether log output is colorized in the console and the log file. Use --use-colors-file/--no-use-colors-file to colorize the log file differently than the console.", - default=True, -) - -use_colors_file = click.option( - "--use-colors-file/--no-use-colors-file", - envvar="DBT_USE_COLORS_FILE", - help="Specify whether log file output is colorized by overriding the default value and the general --use-colors/--no-use-colors setting.", - default=True, -) - log_file_max_bytes = click.option( "--log-file-max-bytes", envvar="DBT_LOG_FILE_MAX_BYTES", @@ -258,22 +350,6 @@ default="selector", ) -show_output_format = click.option( - "--output", - envvar=None, - help="Output format for dbt compile and dbt show", - type=click.Choice(["json", "text"], case_sensitive=False), - default="text", -) - -show_limit = click.option( - "--limit", - envvar=None, - help="Limit the number of results returned by dbt show", - type=click.INT, - default=5, -) - output_keys = click.option( "--output-keys", envvar=None, @@ -303,6 +379,14 @@ default=True, ) +partial_parse_file_diff = click.option( + "--partial-parse-file-diff/--no-partial-parse-file-diff", + envvar="DBT_PARTIAL_PARSE_FILE_DIFF", + help="Internal flag for whether to compute a file diff during partial parsing.", + hidden=True, + default=True, +) + partial_parse_file_path = click.option( "--partial-parse-file-path", envvar="DBT_PARTIAL_PARSE_FILE_PATH", @@ -312,11 +396,10 @@ type=click.Path(exists=True, dir_okay=False, resolve_path=True), ) -partial_parse_file_diff = click.option( - "--partial-parse-file-diff/--no-partial-parse-file-diff", - envvar="DBT_PARTIAL_PARSE_FILE_DIFF", - help="Internal flag for whether to compute a file diff during partial parsing.", - hidden=True, +print = click.option( + "--print/--no-print", + envvar="DBT_PRINT", + help="Output all {{ print() }} macro calls.", default=True, ) @@ -335,22 +418,6 @@ type=click.INT, ) -print = click.option( - "--print/--no-print", - envvar="DBT_PRINT", - help="Output all {{ print() }} macro calls.", - default=True, -) - -deprecated_print = click.option( - "--deprecated-print/--deprecated-no-print", - envvar="DBT_NO_PRINT", - help="Internal flag for deprecating old env var.", - default=True, - hidden=True, - callback=lambda ctx, param, value: not value, -) - printer_width = click.option( "--printer-width", envvar="DBT_PRINTER_WIDTH", @@ -435,42 +502,6 @@ default=(), ) -exclude_resource_type = click.option( - "--exclude-resource-types", - "--exclude-resource-type", - envvar="DBT_EXCLUDE_RESOURCE_TYPES", - help="Specify the types of resources that dbt will exclude", - type=ChoiceTuple( - [ - "metric", - "semantic_model", - "saved_query", - "source", - "analysis", - "model", - "test", - "unit_test", - "exposure", - "snapshot", - "seed", - "default", - ], - case_sensitive=False, - ), - cls=MultiOption, - multiple=True, - default=(), -) - -# Renamed to --export-saved-queries -deprecated_include_saved_query = click.option( - "--include-saved-query/--no-include-saved-query", - envvar="DBT_INCLUDE_SAVED_QUERY", - help="Include saved queries in the list of resources to be selected for build command", - is_flag=True, - hidden=True, -) - model_decls = ("-m", "--models", "--model") select_decls = ("-s", "--select") select_attrs = { @@ -481,19 +512,6 @@ "type": tuple, } -inline = click.option( - "--inline", - envvar=None, - help="Pass SQL inline to dbt compile and show", -) - -inline_direct = click.option( - "--inline-direct", - envvar=None, - help="Internal flag to pass SQL inline to dbt show. Do not load the entire project or apply templating.", - hidden=True, -) - # `--select` and `--models` are analogous for most commands except `dbt list` for legacy reasons. # Most CLI arguments should use the combined `select` option that aliases `--models` to `--select`. # However, if you need to split out these separators (like `dbt ls`), use the `models` and `raw_select` options instead. @@ -515,13 +533,6 @@ default=True, ) -clean_project_files_only = click.option( - "--clean-project-files-only / --no-clean-project-files-only", - envvar="DBT_CLEAN_PROJECT_FILES_ONLY", - help="If disabled, dbt clean will delete all paths specified in clean-paths, even if they're outside the dbt project.", - default=True, -) - show = click.option( "--show", envvar=None, @@ -529,6 +540,29 @@ is_flag=True, ) +show_limit = click.option( + "--limit", + envvar=None, + help="Limit the number of results returned by dbt show", + type=click.INT, + default=5, +) + +show_output_format = click.option( + "--output", + envvar=None, + help="Output format for dbt compile and dbt show", + type=click.Choice(["json", "text"], case_sensitive=False), + default="text", +) + +show_resource_report = click.option( + "--show-resource-report/--no-show-resource-report", + default=False, + envvar="DBT_SHOW_RESOURCE_REPORT", + hidden=True, +) + # TODO: The env var is a correction! # The original env var was `DBT_TEST_SINGLE_THREADED`. # This broke the existing naming convention. @@ -550,13 +584,6 @@ is_flag=True, ) -empty_catalog = click.option( - "--empty-catalog", - help="If specified, generate empty catalog.json file during the `dbt docs generate` command.", - default=False, - is_flag=True, -) - source = click.option( "--source", envvar=None, @@ -565,13 +592,6 @@ default="hub", ) -static = click.option( - "--static", - help="Generate an additional static_index.html with manifest and catalog built-in.", - default=False, - is_flag=True, -) - state = click.option( "--state", envvar="DBT_STATE", @@ -585,31 +605,11 @@ ), ) -defer_state = click.option( - "--defer-state", - envvar="DBT_DEFER_STATE", - help="Override the state directory for deferral only.", - type=click.Path( - dir_okay=True, - file_okay=False, - readable=True, - resolve_path=False, - path_type=Path, - ), -) - -deprecated_state = click.option( - "--deprecated-state", - envvar="DBT_ARTIFACT_STATE_PATH", - help="Internal flag for deprecating old env var.", - hidden=True, - type=click.Path( - dir_okay=True, - file_okay=False, - readable=True, - resolve_path=True, - path_type=Path, - ), +static = click.option( + "--static", + help="Generate an additional static_index.html with manifest and catalog built-in.", + default=False, + is_flag=True, ) static_parser = click.option( @@ -640,6 +640,14 @@ type=click.Path(), ) +threads = click.option( + "--threads", + envvar=None, + help="Specify number of threads to use while executing models. Overrides settings in profiles.yml.", + default=None, + type=click.INT, +) + upgrade = click.option( "--upgrade", envvar=None, @@ -647,19 +655,18 @@ is_flag=True, ) -debug_connection = click.option( - "--connection", - envvar=None, - help="Test the connection to the target database independent of dependency checks.", - is_flag=True, +use_colors = click.option( + "--use-colors/--no-use-colors", + envvar="DBT_USE_COLORS", + help="Specify whether log output is colorized in the console and the log file. Use --use-colors-file/--no-use-colors-file to colorize the log file differently than the console.", + default=True, ) -threads = click.option( - "--threads", - envvar=None, - help="Specify number of threads to use while executing models. Overrides settings in profiles.yml.", - default=None, - type=click.INT, +use_colors_file = click.option( + "--use-colors-file/--no-use-colors-file", + envvar="DBT_USE_COLORS_FILE", + help="Specify whether log file output is colorized by overriding the default value and the general --use-colors/--no-use-colors setting.", + default=True, ) use_experimental_parser = click.option( @@ -668,6 +675,13 @@ help="Enable experimental parsing features.", ) +use_fast_test_edges = click.option( + "--use-fast-test-edges/--no-use-fast-test-edges", + envvar="DBT_USE_FAST_TEST_EDGES", + default=False, + hidden=True, +) + vars = click.option( "--vars", envvar=None, @@ -728,17 +742,3 @@ def _version_callback(ctx, _param, value): help="Whether or not to write the manifest.json and run_results.json files to the target directory", default=True, ) - -show_resource_report = click.option( - "--show-resource-report/--no-show-resource-report", - default=False, - envvar="DBT_SHOW_RESOURCE_REPORT", - hidden=True, -) - -use_fast_test_edges = click.option( - "--use-fast-test-edges/--no-use-fast-test-edges", - envvar="DBT_USE_FAST_TEST_EDGES", - default=False, - hidden=True, -) From b38d55afdb4781e4ab83d7fae573f67beb892489 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Thu, 23 Jan 2025 12:15:21 -0600 Subject: [PATCH 2/2] Second pass at organizing cli param click options --- core/dbt/cli/params.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index 49d814025a9..610f3073d96 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -7,6 +7,18 @@ from dbt.cli.resolvers import default_profiles_dir, default_project_dir from dbt.version import get_version_information +# --- shared option specs --- # +model_decls = ("-m", "--models", "--model") +select_decls = ("-s", "--select") +select_attrs = { + "envvar": None, + "help": "Specify the nodes to include.", + "cls": MultiOption, + "multiple": True, + "type": tuple, +} + +# --- The actual option definitions --- # add_package = click.option( "--add-package", help="Add a package to current package spec, specify it as package-name@version. Change the source with --source flag.", @@ -341,6 +353,8 @@ hidden=True, ) +models = click.option(*model_decls, **select_attrs) # type: ignore[arg-type] + # This less standard usage of --output where output_path below is more standard output = click.option( "--output", @@ -466,6 +480,8 @@ help="Suppress all non-error logging to stdout. Does not affect {{ print() }} macro calls.", ) +raw_select = click.option(*select_decls, **select_attrs) # type: ignore[arg-type] + record_timing_info = click.option( "--record-timing-info", "-r", @@ -502,22 +518,10 @@ default=(), ) -model_decls = ("-m", "--models", "--model") -select_decls = ("-s", "--select") -select_attrs = { - "envvar": None, - "help": "Specify the nodes to include.", - "cls": MultiOption, - "multiple": True, - "type": tuple, -} - # `--select` and `--models` are analogous for most commands except `dbt list` for legacy reasons. # Most CLI arguments should use the combined `select` option that aliases `--models` to `--select`. # However, if you need to split out these separators (like `dbt ls`), use the `models` and `raw_select` options instead. # See https://github.com/dbt-labs/dbt-core/pull/6774#issuecomment-1408476095 for more info. -models = click.option(*model_decls, **select_attrs) # type: ignore[arg-type] -raw_select = click.option(*select_decls, **select_attrs) # type: ignore[arg-type] select = click.option(*select_decls, *model_decls, **select_attrs) # type: ignore[arg-type] selector = click.option(