Repository: dbt-labs/dbt-core

Issue:
[CT-3395] [Feature] Merge `--dry-run` and `--lock` into the same flag for dbt deps
### Is this your first time submitting a feature request?

- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

> I don't see the need for both the flags `--dry-run` and `--lock`, they could be merged into a same flag as far as I can tell.

_Originally posted by @seub in https://github.com/dbt-labs/docs.getdbt.com/issues/4470#issuecomment-1811769591_
            

### Describe alternatives you've considered

See https://github.com/dbt-labs/docs.getdbt.com/issues/4470#issuecomment-1811769591_ for context

### Who will this benefit?

See https://github.com/dbt-labs/docs.getdbt.com/issues/4470#issuecomment-1811769591_ for context

### Are you interested in contributing this feature?

_No response_

### Anything else?

_No response_


Discussion:

Resolving patch:
diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py
--- a/core/dbt/cli/main.py
+++ b/core/dbt/cli/main.py
@@ -457,7 +457,6 @@ def debug(ctx, **kwargs):
 @p.target
 @p.vars
 @p.source
-@p.dry_run
 @p.lock
 @p.upgrade
 @p.add_package
@@ -483,12 +482,6 @@ def deps(ctx, **kwargs):
                 message=f"Version is required in --add-package when a package when source is {flags.SOURCE}",
                 option_name="--add-package",
             )
-    else:
-        if flags.DRY_RUN:
-            raise BadOptionUsage(
-                message="Invalid flag `--dry-run` when not using `--add-package`.",
-                option_name="--dry-run",
-            )
     task = DepsTask(flags, ctx.obj["project"])
     results = task.run()
     success = task.interpret_results(results)
diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py
--- a/core/dbt/cli/params.py
+++ b/core/dbt/cli/params.py
@@ -83,13 +83,6 @@
     hidden=True,
 )
 
-dry_run = click.option(
-    "--dry-run",
-    envvar=None,
-    help="Option to run `dbt deps --add-package` without updating package-lock.yml file.",
-    is_flag=True,
-)
-
 empty = click.option(
     "--empty/--no-empty",
     envvar="DBT_EMPTY",
diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py
--- a/core/dbt/task/deps.py
+++ b/core/dbt/task/deps.py
@@ -220,8 +220,9 @@ def run(self) -> None:
             if previous_hash != current_hash:
                 self.lock()
 
-        # Early return when dry run or lock only.
-        if self.args.dry_run or self.args.lock:
+        # Early return when 'dbt deps --lock'
+        # Just resolve packages and write lock file, don't actually install packages
+        if self.args.lock:
             return
 
         if system.path_exists(self.project.packages_install_path):


Test patch:
diff --git a/tests/functional/dependencies/test_dependency_options.py b/tests/functional/dependencies/test_dependency_options.py
--- a/tests/functional/dependencies/test_dependency_options.py
+++ b/tests/functional/dependencies/test_dependency_options.py
@@ -75,14 +75,14 @@ def test_deps_add(self, clean_start):
         )
         assert len(os.listdir("dbt_packages")) == 3
 
-    def test_deps_add_dry_run(self, clean_start):
+    def test_deps_add_without_install(self, clean_start):
         os.rename("packages.yml", "dependencies.yml")
         run_dbt(
             [
                 "deps",
                 "--add-package",
                 "dbt-labs/audit_helper@0.9.0",
-                "--dry-run",
+                "--lock",
             ]
         )
         assert not os.path.exists("dbt_packages")