Skip to content

Commit 9529eb4

Browse files
committed
Update cli.py
1 parent dce7bc3 commit 9529eb4

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

codeflash/cli_cmds/cli.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions
99
from codeflash.cli_cmds.console import logger
1010
from codeflash.code_utils import env_utils
11+
from codeflash.code_utils.code_utils import exit_with_message
1112
from codeflash.code_utils.config_parser import parse_config_file
1213
from codeflash.version import __version__ as version
1314

@@ -83,25 +84,21 @@ def process_and_validate_cmd_args(args: Namespace) -> Namespace:
8384
sys.exit()
8485
if not check_running_in_git_repo(module_root=args.module_root):
8586
if not confirm_proceeding_with_no_git_repo():
86-
logger.critical("No git repository detected and user aborted run. Exiting...")
87-
sys.exit(1)
87+
exit_with_message("No git repository detected and user aborted run. Exiting...", error_on_exit=True)
8888
args.no_pr = True
8989
if args.function and not args.file:
90-
logger.error("If you specify a --function, you must specify the --file it is in")
91-
sys.exit(1)
90+
exit_with_message("If you specify a --function, you must specify the --file it is in", error_on_exit=True)
9291
if args.file:
9392
if not Path(args.file).exists():
94-
logger.error(f"File {args.file} does not exist")
95-
sys.exit(1)
93+
exit_with_message(f"File {args.file} does not exist", error_on_exit=True)
9694
args.file = Path(args.file).resolve()
9795
if not args.no_pr:
9896
owner, repo = get_repo_owner_and_name()
9997
require_github_app_or_exit(owner, repo)
10098
if args.replay_test:
10199
for test_path in args.replay_test:
102100
if not Path(test_path).is_file():
103-
logger.error(f"Replay test file {test_path} does not exist")
104-
sys.exit(1)
101+
exit_with_message(f"Replay test file {test_path} does not exist", error_on_exit=True)
105102
args.replay_test = [Path(replay_test).resolve() for replay_test in args.replay_test]
106103

107104
return args
@@ -111,8 +108,7 @@ def process_pyproject_config(args: Namespace) -> Namespace:
111108
try:
112109
pyproject_config, pyproject_file_path = parse_config_file(args.config_file)
113110
except ValueError as e:
114-
logger.error(e)
115-
sys.exit(1)
111+
exit_with_message(f"Error parsing config file: {e}", error_on_exit=True)
116112
supported_keys = [
117113
"module_root",
118114
"tests_root",
@@ -207,8 +203,7 @@ def handle_optimize_all_arg_parsing(args: Namespace) -> Namespace:
207203
)
208204
apologize_and_exit()
209205
if not args.no_pr and not check_and_push_branch(git_repo):
210-
logger.critical("❌ Branch is not pushed. Exiting...")
211-
sys.exit(1)
206+
exit_with_message("Branch is not pushed...", error_on_exit=True)
212207
owner, repo = get_repo_owner_and_name(git_repo)
213208
if not args.no_pr:
214209
require_github_app_or_exit(owner, repo)

0 commit comments

Comments
 (0)