Skip to content

Commit

Permalink
make deploy command behave correctly if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Oct 9, 2024
1 parent 5231edf commit 1d4c52b
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions dlt/cli/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
COMMAND_DEPLOY_REPO_LOCATION,
SecretFormats,
)

deploy_command_available = True
except ModuleNotFoundError:
pass
deploy_command_available = False


@plugins.hookspec()
Expand Down Expand Up @@ -304,6 +306,14 @@ def configure_parser(self, parser: argparse.ArgumentParser) -> None:
deploy_comm = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter, add_help=False
)

deploy_cmd.add_argument(
"pipeline_script_path", metavar="pipeline-script-path", help="Path to a pipeline script"
)

if not deploy_command_available:
return

deploy_comm.add_argument(
"--location",
default=COMMAND_DEPLOY_REPO_LOCATION,
Expand All @@ -314,9 +324,6 @@ def configure_parser(self, parser: argparse.ArgumentParser) -> None:
help="Advanced. Uses specific branch of the deploy repository to fetch the template.",
)

deploy_cmd.add_argument(
"pipeline_script_path", metavar="pipeline-script-path", help="Path to a pipeline script"
)
deploy_sub_parsers = deploy_cmd.add_subparsers(dest="deployment_method")

# deploy github actions
Expand Down Expand Up @@ -362,20 +369,8 @@ def configure_parser(self, parser: argparse.ArgumentParser) -> None:
)

def execute(self, args: argparse.Namespace) -> int:
try:
deploy_args = vars(args)
if deploy_args.get("deployment_method") is None:
self.parser.print_help()
return -1
else:
return deploy_command_wrapper(
pipeline_script_path=deploy_args.pop("pipeline_script_path"),
deployment_method=deploy_args.pop("deployment_method"),
repo_location=deploy_args.pop("location"),
branch=deploy_args.pop("branch"),
**deploy_args,
)
except (NameError, KeyError):
# exit if deploy command is not available
if not deploy_command_available:
fmt.warning(
"Please install additional command line dependencies to use deploy command:"
)
Expand All @@ -386,6 +381,19 @@ def execute(self, args: argparse.Namespace) -> int:
)
return -1

deploy_args = vars(args)
if deploy_args.get("deployment_method") is None:
self.parser.print_help()
return -1
else:
return deploy_command_wrapper(
pipeline_script_path=deploy_args.pop("pipeline_script_path"),
deployment_method=deploy_args.pop("deployment_method"),
repo_location=deploy_args.pop("location"),
branch=deploy_args.pop("branch"),
**deploy_args,
)


#
# Register all commands
Expand Down

0 comments on commit 1d4c52b

Please sign in to comment.