|
15 | 15 | def main(): |
16 | 16 | result = 0 |
17 | 17 | command = None |
| 18 | + |
18 | 19 | printer = Printer() |
19 | 20 | console = Console(printer=printer) |
20 | 21 | logger = Log(printer=printer) |
21 | | - try: |
22 | | - Command, extra_cmdline = parse_cmdline(sys.argv[1:], console=console) |
23 | | - command = Command(logger=logger, console=console) |
24 | | - options, overrides = command.parse_options(extra=extra_cmdline) |
25 | | - command.parse_config( |
26 | | - Path.cwd() / "pyproject.toml", |
27 | | - overrides=overrides, |
28 | | - ) |
29 | | - command(**options) |
30 | | - except HelpText as e: |
31 | | - logger.info() |
32 | | - logger.info(str(e)) |
33 | | - result = e.error_code |
34 | | - except BriefcaseWarning as w: |
35 | | - # The case of something that hasn't gone right, but in an |
36 | | - # acceptable way. |
37 | | - logger.warning(str(w)) |
38 | | - result = w.error_code |
39 | | - except BriefcaseTestSuiteFailure as e: |
40 | | - # Test suite status is logged when the test is executed. |
41 | | - # Set the return code, but don't log anything else. |
42 | | - result = e.error_code |
43 | | - except BriefcaseError as e: |
44 | | - logger.error() |
45 | | - logger.error(str(e)) |
46 | | - result = e.error_code |
47 | | - logger.capture_stacktrace() |
48 | | - except Exception: |
49 | | - logger.capture_stacktrace() |
50 | | - raise |
51 | | - except KeyboardInterrupt: |
52 | | - logger.warning() |
53 | | - logger.warning("Aborted by user.") |
54 | | - logger.warning() |
55 | | - result = -42 |
56 | | - if logger.save_log: |
| 22 | + |
| 23 | + with suppress(KeyboardInterrupt): |
| 24 | + try: |
| 25 | + Command, extra_cmdline = parse_cmdline(sys.argv[1:], console=console) |
| 26 | + command = Command(logger=logger, console=console) |
| 27 | + options, overrides = command.parse_options(extra=extra_cmdline) |
| 28 | + command.parse_config(Path.cwd() / "pyproject.toml", overrides=overrides) |
| 29 | + command(**options) |
| 30 | + except HelpText as e: |
| 31 | + logger.info() |
| 32 | + logger.info(str(e)) |
| 33 | + result = e.error_code |
| 34 | + except BriefcaseWarning as w: |
| 35 | + # The case of something that hasn't gone right, but in an |
| 36 | + # acceptable way. |
| 37 | + logger.warning(str(w)) |
| 38 | + result = w.error_code |
| 39 | + except BriefcaseTestSuiteFailure as e: |
| 40 | + # Test suite status is logged when the test is executed. |
| 41 | + # Set the return code, but don't log anything else. |
| 42 | + result = e.error_code |
| 43 | + except BriefcaseError as e: |
| 44 | + logger.error() |
| 45 | + logger.error(str(e)) |
| 46 | + result = e.error_code |
| 47 | + logger.capture_stacktrace() |
| 48 | + except Exception: |
57 | 49 | logger.capture_stacktrace() |
58 | | - finally: |
59 | | - with suppress(KeyboardInterrupt): |
| 50 | + raise |
| 51 | + except KeyboardInterrupt: |
| 52 | + logger.warning() |
| 53 | + logger.warning("Aborted by user.") |
| 54 | + logger.warning() |
| 55 | + result = -42 |
| 56 | + if logger.save_log: |
| 57 | + logger.capture_stacktrace() |
| 58 | + finally: |
| 59 | + if command is not None: |
| 60 | + command.tracking_save() |
60 | 61 | logger.save_log_to_file(command) |
61 | 62 |
|
62 | 63 | return result |
|
0 commit comments