Given a command to execute and stage, execute that command.
(self, command, stage)
| 578 | sys.exit(e.exit_code) |
| 579 | |
| 580 | def dispatch_command(self, command, stage): |
| 581 | """ |
| 582 | Given a command to execute and stage, |
| 583 | execute that command. |
| 584 | """ |
| 585 | self.check_stage_name(stage) |
| 586 | self.api_stage = stage |
| 587 | |
| 588 | if command not in ["status", "manage"]: |
| 589 | if not self.vargs.get("json", None): |
| 590 | click.echo( |
| 591 | "Calling " |
| 592 | + click.style(command, fg="green", bold=True) |
| 593 | + " for stage " |
| 594 | + click.style(self.api_stage, bold=True) |
| 595 | + ".." |
| 596 | ) |
| 597 | |
| 598 | # Explicitly define the app function. |
| 599 | # Related: https://github.com/Miserlou/Zappa/issues/832 |
| 600 | if self.vargs.get("app_function", None): |
| 601 | self.app_function = self.vargs["app_function"] |
| 602 | |
| 603 | # Check if we should create settings for manage command |
| 604 | if command == "manage" and self.vargs.get("create_settings"): |
| 605 | # Generate settings using environment variables and defaults |
| 606 | settings = self._generate_settings_dict(stage=self.api_stage) |
| 607 | |
| 608 | # Write settings to zappa_settings.json |
| 609 | import json |
| 610 | |
| 611 | settings_file_path = Path("zappa_settings.json") |
| 612 | |
| 613 | with settings_file_path.open("w", encoding="utf8") as zappa_settings_file: |
| 614 | json_output = json.dumps(settings, sort_keys=True, indent=4) |
| 615 | zappa_settings_file.write(json_output) |
| 616 | |
| 617 | click.echo( |
| 618 | click.style("Created ", fg="green", bold=True) |
| 619 | + click.style("zappa_settings.json", bold=True) |
| 620 | + " with environment variables and defaults." |
| 621 | ) |
| 622 | |
| 623 | # Load our settings, based on api_stage. |
| 624 | try: |
| 625 | self.load_settings(self.vargs.get("settings_file")) |
| 626 | except ValueError as e: |
| 627 | if hasattr(e, "message"): |
| 628 | print("Error: {}".format(e.message)) |
| 629 | else: |
| 630 | print(str(e)) |
| 631 | sys.exit(-1) |
| 632 | self.callback("settings") |
| 633 | |
| 634 | # Hand it off |
| 635 | if command == "deploy": # pragma: no cover |
| 636 | self.deploy(self.vargs["zip"], self.vargs["docker_image_uri"]) |
| 637 | if command == "package": # pragma: no cover |
no test coverage detected