From 22f917d89b33f93cea2fe799f2a1edbfc2aed9ba Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Mon, 9 Oct 2023 16:37:14 -0700 Subject: [PATCH] move_check --- core/dbt/cli/main.py | 15 ++++++++++++++- core/dbt/task/deps.py | 10 ---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index a015bc1a5cf..fa3f6663e93 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -473,7 +473,20 @@ def deps(ctx, **kwargs): There is a way to add new packages by providing an `--add-package` flag to deps command which will allow user to specify a package they want to add in the format of packagename@version. """ - task = DepsTask(ctx.obj["flags"], ctx.obj["project"]) + flags = ctx.obj["flags"] + if flags.ADD_PACKAGE: + if not flags.ADD_PACKAGE["version"] and flags.SOURCE != "local": + raise BadOptionUsage( + 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) return results, success diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py index 113c2f6672c..1433c9a48ca 100644 --- a/core/dbt/task/deps.py +++ b/core/dbt/task/deps.py @@ -151,11 +151,6 @@ def add(self): yaml.safe_dump({"packages": []}, package_yml) fire_event(Formatting("Created packages.yml")) - if not self.args.add_package["version"] and self.args.source != "local": - raise dbt.exceptions.DbtRuntimeError( - f"Version is required in --add-package when a package when source is {self.args.source}" - ) - new_package_entry = _create_packages_yml_entry( self.args.add_package["name"], self.args.add_package["version"], self.args.source ) @@ -213,11 +208,6 @@ def lock(self) -> None: def run(self) -> None: if self.args.add_package: self.add() - else: - if self.args.dry_run: - raise dbt.exceptions.DbtRuntimeError( - "Invalid flag `--dry-run` when not using `--add-package`." - ) # Check lock file exist and generated by the same pacakges.yml # or dependencies.yml.