| 19 | def cli(pyfile): |
| 20 | @pyfile |
| 21 | def cli_parser(): |
| 22 | import os |
| 23 | import pickle |
| 24 | import sys |
| 25 | from debugpy.server import cli |
| 26 | |
| 27 | try: |
| 28 | cli.parse_args() |
| 29 | except Exception as exc: |
| 30 | os.write(1, pickle.dumps(exc)) |
| 31 | sys.exit(1) |
| 32 | |
| 33 | # Check that sys.argv has the correct type after parsing - there should be no bytes. |
| 34 | assert all(isinstance(s, str) for s in sys.argv) |
| 35 | |
| 36 | # We only care about options that correspond to public switches. |
| 37 | options = { |
| 38 | name: getattr(cli.options, name) |
| 39 | for name in [ |
| 40 | "address", |
| 41 | "config", |
| 42 | "log_to", |
| 43 | "log_to_stderr", |
| 44 | "mode", |
| 45 | "target", |
| 46 | "target_kind", |
| 47 | "wait_for_client", |
| 48 | "parent_session_pid", |
| 49 | ] |
| 50 | } |
| 51 | |
| 52 | # Serialize the command line args and the options to stdout |
| 53 | serialized_data = pickle.dumps([sys.argv[1:], options]) |
| 54 | os.write(1, serialized_data) |
| 55 | # Ensure all data is written before process exits |
| 56 | sys.stdout.flush() |
| 57 | |
| 58 | def parse(args): |
| 59 | log.debug("Parsing argv: {0!r}", args) |