diff --git a/ardy/core/cmd/main.py b/ardy/core/cmd/main.py index 7194a70..18856ad 100644 --- a/ardy/core/cmd/main.py +++ b/ardy/core/cmd/main.py @@ -19,6 +19,7 @@ class Command(object): def __init__(self, *args, **kwargs): arguments = kwargs.get("arguments", False) + self.exit_at_finish = kwargs.get("exit_at_finish", True) if not arguments: arguments = sys.argv[1:] @@ -106,11 +107,13 @@ def parse_commandline(self): def exit_with_error(self, msg=""): self.print_error(msg) - sys.exit(2) + if self.exit_at_finish: + sys.exit(2) def exit_ok(self, msg=""): self.print_ok(msg) - sys.exit(0) + if self.exit_at_finish: + sys.exit(0) @staticmethod def print_ok(msg=""): diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 2c830dc..138f823 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -39,7 +39,7 @@ def test_base(self): test_folder = "myexamplelambdaproject_test" try: arguments = ["-p", test_folder, "-f", "config.json"] - Command(arguments=arguments) + Command(arguments=arguments, exit_at_finish=False) self.fail("notexist folder not exists") except ArdyNoDirError: pass @@ -48,7 +48,7 @@ def test_base(self): try: arguments = ["-p", test_folder, "-f", "config.json"] - Command(arguments=arguments) + Command(arguments=arguments, exit_at_finish=False) self.fail("config.json not exist in myexamplelambdaproject") except ArdyNoFileError: pass @@ -57,15 +57,15 @@ def test_base(self): if sys.version_info <= (3, 0): with self.assertRaises(SystemExit): - Command(arguments=self.base_arguments) + Command(arguments=self.base_arguments, exit_at_finish=False) else: - command = Command(arguments=self.base_arguments) + command = Command(arguments=self.base_arguments, exit_at_finish=False) self.assert_base_conf(command) def test_deploy_error(self): lambda_functions_to_deploy = ["lambda1", "lambda2"] with self.assertRaises(SystemExit): - Command(arguments=self.base_arguments + ["deploy", ] + lambda_functions_to_deploy) + Command(arguments=self.base_arguments + ["deploy", ] + lambda_functions_to_deploy, exit_at_finish=False) self.fail("Environment is needed is it's defined in config.json") @patch.object(Deploy, "run") @@ -73,7 +73,7 @@ def test_deploy(self, deploy_run_mock): lambda_functions_to_deploy = ["lambda1", "lambda2"] for environment in self.deploy_environments: arguments = self.base_arguments + ["deploy", ] + lambda_functions_to_deploy + [environment, ] - deploy = Command(arguments=arguments) + deploy = Command(arguments=arguments, exit_at_finish=False) self.assertEqual(deploy.args.lambdafunctions, lambda_functions_to_deploy) self.assertEqual(deploy.args.environment, environment) @@ -83,7 +83,7 @@ def test_deploy(self, deploy_run_mock): @patch.object(Build, "run") def test_build(self, build_run_mock): arguments = self.base_arguments + ["build", ] - build = Command(arguments=arguments) + build = Command(arguments=arguments, exit_at_finish=False) self.assertEqual(build_run_mock.call_count, 1) self.assert_base_conf(build)