We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Changes in CLI arguments between versions
## Environment data

- PTVSD version: 4.1.3
- Using VS Code or Visual Studio: N/A

## Actual behavior

* CLI args for starting apps for remote debugging has changed 
* Now the arg requires `--server-host`, this wasn't the case in the past.
* This is a breaking change.

## Expected  behavior

* We need to revert if possible as existing users will not be able to use PTSVD for remote debugging scenarios.

Reported here https://github.com/Microsoft/vscode-python/issues/2833#issuecomment-428422616


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ptvsd/__main__.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License. See LICENSE in the project root
3 # for license information.
4 
5 import argparse
6 import os.path
7 import sys
8 
9 from ptvsd._attach import attach_main
10 from ptvsd._local import debug_main, run_main
11 from ptvsd.socket import Address
12 from ptvsd.version import __version__, __author__  # noqa
13 
14 
15 ##################################
16 # the script
17 
18 """
19 For the PyDevd CLI handling see:
20 
21   https://github.com/fabioz/PyDev.Debugger/blob/master/_pydevd_bundle/pydevd_command_line_handling.py
22   https://github.com/fabioz/PyDev.Debugger/blob/master/pydevd.py#L1450  (main func)
23 """  # noqa
24 
25 PYDEVD_OPTS = {
26     '--file',
27     '--client',
28     #'--port',
29     '--vm_type',
30 }
31 
32 PYDEVD_FLAGS = {
33     '--DEBUG',
34     '--DEBUG_RECORD_SOCKET_READS',
35     '--cmd-line',
36     '--module',
37     '--multiproc',
38     '--multiprocess',
39     '--print-in-debugger-startup',
40     '--save-signatures',
41     '--save-threading',
42     '--save-asyncio',
43     '--server',
44     '--qt-support=auto',
45 }
46 
47 USAGE = """
48   {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]
49   {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]
50   {0} [-h] [-V] --host HOST --port PORT --pid PROCESS_ID
51 """  # noqa
52 
53 
54 def parse_args(argv=None):
55     """Return the parsed args to use in main()."""
56     if argv is None:
57         argv = sys.argv
58         prog = argv[0]
59         if prog == __file__:
60             prog = '{} -m ptvsd'.format(os.path.basename(sys.executable))
61     else:
62         prog = argv[0]
63     argv = argv[1:]
64 
65     supported, pydevd, script = _group_args(argv)
66     args = _parse_args(prog, supported)
67     # '--' is used in _run_args to extract pydevd specific args
68     extra = pydevd + ['--']
69     if script:
70         extra += script
71     return args, extra
72 
73 
74 def _group_args(argv):
75     supported = []
76     pydevd = []
77     script = []
78 
79     try:
80         pos = argv.index('--')
81     except ValueError:
82         script = []
83     else:
84         script = argv[pos + 1:]
85         argv = argv[:pos]
86 
87     for arg in argv:
88         if arg == '-h' or arg == '--help':
89             return argv, [], script
90 
91     gottarget = False
92     skip = 0
93     for i in range(len(argv)):
94         if skip:
95             skip -= 1
96             continue
97 
98         arg = argv[i]
99         try:
100             nextarg = argv[i + 1]
101         except IndexError:
102             nextarg = None
103 
104         # TODO: Deprecate the PyDevd arg support.
105         # PyDevd support
106         if gottarget:
107             script = argv[i:] + script
108             break
109         if arg == '--client':
110             arg = '--host'
111         elif arg == '--file':
112             if nextarg is None:  # The filename is missing...
113                 pydevd.append(arg)
114                 continue  # This will get handled later.
115             if nextarg.endswith(':') and '--module' in pydevd:
116                 pydevd.remove('--module')
117                 arg = '-m'
118                 argv[i + 1] = nextarg = nextarg[:-1]
119             else:
120                 arg = nextarg
121                 skip += 1
122 
123         if arg in PYDEVD_OPTS:
124             pydevd.append(arg)
125             if nextarg is not None:
126                 pydevd.append(nextarg)
127             skip += 1
128         elif arg in PYDEVD_FLAGS:
129             pydevd.append(arg)
130         elif arg == '--nodebug':
131             supported.append(arg)
132 
133         # ptvsd support
134         elif arg in ('--host', '--server-host', '--port', '--pid', '-m'):
135             if arg == '-m' or arg == '--pid':
136                 gottarget = True
137             supported.append(arg)
138             if nextarg is not None:
139                 supported.append(nextarg)
140             skip += 1
141         elif arg in ('--single-session', '--wait'):
142             supported.append(arg)
143         elif not arg.startswith('-'):
144             supported.append(arg)
145             gottarget = True
146 
147         # unsupported arg
148         else:
149             supported.append(arg)
150             break
151 
152     return supported, pydevd, script
153 
154 
155 def _parse_args(prog, argv):
156     parser = argparse.ArgumentParser(
157         prog=prog,
158         usage=USAGE.format(prog),
159     )
160 
161     parser.add_argument('--nodebug', action='store_true')
162 
163     host = parser.add_mutually_exclusive_group()
164     host.add_argument('--host')
165     host.add_argument('--server-host')
166     parser.add_argument('--port', type=int, required=True)
167 
168     target = parser.add_mutually_exclusive_group(required=True)
169     target.add_argument('-m', dest='module')
170     target.add_argument('--pid', type=int)
171     target.add_argument('filename', nargs='?')
172 
173     parser.add_argument('--single-session', action='store_true')
174     parser.add_argument('--wait', action='store_true')
175 
176     parser.add_argument('-V', '--version', action='version')
177     parser.version = __version__
178 
179     args = parser.parse_args(argv)
180     ns = vars(args)
181 
182     serverhost = ns.pop('server_host', None)
183     clienthost = ns.pop('host', None)
184     if serverhost:
185         args.address = Address.as_server(serverhost, ns.pop('port'))
186     elif not clienthost:
187         if args.nodebug:
188             args.address = Address.as_client(clienthost, ns.pop('port'))
189         else:
190             args.address = Address.as_server(clienthost, ns.pop('port'))
191     else:
192         args.address = Address.as_client(clienthost, ns.pop('port'))
193 
194     pid = ns.pop('pid')
195     module = ns.pop('module')
196     filename = ns.pop('filename')
197     if pid is not None:
198         args.name = pid
199         args.kind = 'pid'
200     elif module is not None:
201         args.name = module
202         args.kind = 'module'
203     else:
204         args.name = filename
205         args.kind = 'script'
206 
207     return args
208 
209 
210 def handle_args(addr, name, kind, extra=(), nodebug=False, **kwargs):
211     if kind == 'pid':
212         attach_main(addr, name, *extra, **kwargs)
213     elif nodebug:
214         run_main(addr, name, kind, *extra, **kwargs)
215     else:
216         debug_main(addr, name, kind, *extra, **kwargs)
217 
218 
219 def main(argv=None):
220     args, extra = parse_args(argv)
221     handle_args(args.address, args.name, args.kind, extra,
222                 nodebug=args.nodebug, singlesession=args.single_session,
223                 wait=args.wait)
224 
225 
226 if __name__ == '__main__':
227     main()
228
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ptvsd/__main__.py b/ptvsd/__main__.py
--- a/ptvsd/__main__.py
+++ b/ptvsd/__main__.py
@@ -24,8 +24,6 @@
 
 PYDEVD_OPTS = {
     '--file',
-    '--client',
-    #'--port',
     '--vm_type',
 }
 
@@ -45,8 +43,8 @@
 }
 
 USAGE = """
-  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]
-  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]
+  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT -m MODULE [arg ...]
+  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT FILENAME [arg ...]
   {0} [-h] [-V] --host HOST --port PORT --pid PROCESS_ID
 """  # noqa
 
@@ -106,9 +104,7 @@
         if gottarget:
             script = argv[i:] + script
             break
-        if arg == '--client':
-            arg = '--host'
-        elif arg == '--file':
+        if arg == '--file':
             if nextarg is None:  # The filename is missing...
                 pydevd.append(arg)
                 continue  # This will get handled later.
@@ -131,14 +127,14 @@
             supported.append(arg)
 
         # ptvsd support
-        elif arg in ('--host', '--server-host', '--port', '--pid', '-m'):
+        elif arg in ('--host', '--port', '--pid', '-m'):
             if arg == '-m' or arg == '--pid':
                 gottarget = True
             supported.append(arg)
             if nextarg is not None:
                 supported.append(nextarg)
             skip += 1
-        elif arg in ('--single-session', '--wait'):
+        elif arg in ('--single-session', '--wait', '--client'):
             supported.append(arg)
         elif not arg.startswith('-'):
             supported.append(arg)
@@ -159,10 +155,9 @@
     )
 
     parser.add_argument('--nodebug', action='store_true')
+    parser.add_argument('--client', action='store_true')
 
-    host = parser.add_mutually_exclusive_group()
-    host.add_argument('--host')
-    host.add_argument('--server-host')
+    parser.add_argument('--host')
     parser.add_argument('--port', type=int, required=True)
 
     target = parser.add_mutually_exclusive_group(required=True)
@@ -179,17 +174,10 @@
     args = parser.parse_args(argv)
     ns = vars(args)
 
-    serverhost = ns.pop('server_host', None)
-    clienthost = ns.pop('host', None)
-    if serverhost:
-        args.address = Address.as_server(serverhost, ns.pop('port'))
-    elif not clienthost:
-        if args.nodebug:
-            args.address = Address.as_client(clienthost, ns.pop('port'))
-        else:
-            args.address = Address.as_server(clienthost, ns.pop('port'))
-    else:
-        args.address = Address.as_client(clienthost, ns.pop('port'))
+    host = ns.pop('host', None)
+    port = ns.pop('port')
+    client = ns.pop('client')
+    args.address = (Address.as_client if client else Address.as_server)(host, port) # noqa
 
     pid = ns.pop('pid')
     module = ns.pop('module')

{"golden_diff": "diff --git a/ptvsd/__main__.py b/ptvsd/__main__.py\n--- a/ptvsd/__main__.py\n+++ b/ptvsd/__main__.py\n@@ -24,8 +24,6 @@\n \n PYDEVD_OPTS = {\n     '--file',\n-    '--client',\n-    #'--port',\n     '--vm_type',\n }\n \n@@ -45,8 +43,8 @@\n }\n \n USAGE = \"\"\"\n-  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]\n-  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]\n+  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT -m MODULE [arg ...]\n+  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT FILENAME [arg ...]\n   {0} [-h] [-V] --host HOST --port PORT --pid PROCESS_ID\n \"\"\"  # noqa\n \n@@ -106,9 +104,7 @@\n         if gottarget:\n             script = argv[i:] + script\n             break\n-        if arg == '--client':\n-            arg = '--host'\n-        elif arg == '--file':\n+        if arg == '--file':\n             if nextarg is None:  # The filename is missing...\n                 pydevd.append(arg)\n                 continue  # This will get handled later.\n@@ -131,14 +127,14 @@\n             supported.append(arg)\n \n         # ptvsd support\n-        elif arg in ('--host', '--server-host', '--port', '--pid', '-m'):\n+        elif arg in ('--host', '--port', '--pid', '-m'):\n             if arg == '-m' or arg == '--pid':\n                 gottarget = True\n             supported.append(arg)\n             if nextarg is not None:\n                 supported.append(nextarg)\n             skip += 1\n-        elif arg in ('--single-session', '--wait'):\n+        elif arg in ('--single-session', '--wait', '--client'):\n             supported.append(arg)\n         elif not arg.startswith('-'):\n             supported.append(arg)\n@@ -159,10 +155,9 @@\n     )\n \n     parser.add_argument('--nodebug', action='store_true')\n+    parser.add_argument('--client', action='store_true')\n \n-    host = parser.add_mutually_exclusive_group()\n-    host.add_argument('--host')\n-    host.add_argument('--server-host')\n+    parser.add_argument('--host')\n     parser.add_argument('--port', type=int, required=True)\n \n     target = parser.add_mutually_exclusive_group(required=True)\n@@ -179,17 +174,10 @@\n     args = parser.parse_args(argv)\n     ns = vars(args)\n \n-    serverhost = ns.pop('server_host', None)\n-    clienthost = ns.pop('host', None)\n-    if serverhost:\n-        args.address = Address.as_server(serverhost, ns.pop('port'))\n-    elif not clienthost:\n-        if args.nodebug:\n-            args.address = Address.as_client(clienthost, ns.pop('port'))\n-        else:\n-            args.address = Address.as_server(clienthost, ns.pop('port'))\n-    else:\n-        args.address = Address.as_client(clienthost, ns.pop('port'))\n+    host = ns.pop('host', None)\n+    port = ns.pop('port')\n+    client = ns.pop('client')\n+    args.address = (Address.as_client if client else Address.as_server)(host, port) # noqa\n \n     pid = ns.pop('pid')\n     module = ns.pop('module')\n", "issue": "Changes in CLI arguments between versions\n## Environment data\r\n\r\n- PTVSD version: 4.1.3\r\n- Using VS Code or Visual Studio: N/A\r\n\r\n## Actual behavior\r\n\r\n* CLI args for starting apps for remote debugging has changed \r\n* Now the arg requires `--server-host`, this wasn't the case in the past.\r\n* This is a breaking change.\r\n\r\n## Expected  behavior\r\n\r\n* We need to revert if possible as existing users will not be able to use PTSVD for remote debugging scenarios.\r\n\r\nReported here https://github.com/Microsoft/vscode-python/issues/2833#issuecomment-428422616\r\n\n", "before_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See LICENSE in the project root\n# for license information.\n\nimport argparse\nimport os.path\nimport sys\n\nfrom ptvsd._attach import attach_main\nfrom ptvsd._local import debug_main, run_main\nfrom ptvsd.socket import Address\nfrom ptvsd.version import __version__, __author__  # noqa\n\n\n##################################\n# the script\n\n\"\"\"\nFor the PyDevd CLI handling see:\n\n  https://github.com/fabioz/PyDev.Debugger/blob/master/_pydevd_bundle/pydevd_command_line_handling.py\n  https://github.com/fabioz/PyDev.Debugger/blob/master/pydevd.py#L1450  (main func)\n\"\"\"  # noqa\n\nPYDEVD_OPTS = {\n    '--file',\n    '--client',\n    #'--port',\n    '--vm_type',\n}\n\nPYDEVD_FLAGS = {\n    '--DEBUG',\n    '--DEBUG_RECORD_SOCKET_READS',\n    '--cmd-line',\n    '--module',\n    '--multiproc',\n    '--multiprocess',\n    '--print-in-debugger-startup',\n    '--save-signatures',\n    '--save-threading',\n    '--save-asyncio',\n    '--server',\n    '--qt-support=auto',\n}\n\nUSAGE = \"\"\"\n  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]\n  {0} [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]\n  {0} [-h] [-V] --host HOST --port PORT --pid PROCESS_ID\n\"\"\"  # noqa\n\n\ndef parse_args(argv=None):\n    \"\"\"Return the parsed args to use in main().\"\"\"\n    if argv is None:\n        argv = sys.argv\n        prog = argv[0]\n        if prog == __file__:\n            prog = '{} -m ptvsd'.format(os.path.basename(sys.executable))\n    else:\n        prog = argv[0]\n    argv = argv[1:]\n\n    supported, pydevd, script = _group_args(argv)\n    args = _parse_args(prog, supported)\n    # '--' is used in _run_args to extract pydevd specific args\n    extra = pydevd + ['--']\n    if script:\n        extra += script\n    return args, extra\n\n\ndef _group_args(argv):\n    supported = []\n    pydevd = []\n    script = []\n\n    try:\n        pos = argv.index('--')\n    except ValueError:\n        script = []\n    else:\n        script = argv[pos + 1:]\n        argv = argv[:pos]\n\n    for arg in argv:\n        if arg == '-h' or arg == '--help':\n            return argv, [], script\n\n    gottarget = False\n    skip = 0\n    for i in range(len(argv)):\n        if skip:\n            skip -= 1\n            continue\n\n        arg = argv[i]\n        try:\n            nextarg = argv[i + 1]\n        except IndexError:\n            nextarg = None\n\n        # TODO: Deprecate the PyDevd arg support.\n        # PyDevd support\n        if gottarget:\n            script = argv[i:] + script\n            break\n        if arg == '--client':\n            arg = '--host'\n        elif arg == '--file':\n            if nextarg is None:  # The filename is missing...\n                pydevd.append(arg)\n                continue  # This will get handled later.\n            if nextarg.endswith(':') and '--module' in pydevd:\n                pydevd.remove('--module')\n                arg = '-m'\n                argv[i + 1] = nextarg = nextarg[:-1]\n            else:\n                arg = nextarg\n                skip += 1\n\n        if arg in PYDEVD_OPTS:\n            pydevd.append(arg)\n            if nextarg is not None:\n                pydevd.append(nextarg)\n            skip += 1\n        elif arg in PYDEVD_FLAGS:\n            pydevd.append(arg)\n        elif arg == '--nodebug':\n            supported.append(arg)\n\n        # ptvsd support\n        elif arg in ('--host', '--server-host', '--port', '--pid', '-m'):\n            if arg == '-m' or arg == '--pid':\n                gottarget = True\n            supported.append(arg)\n            if nextarg is not None:\n                supported.append(nextarg)\n            skip += 1\n        elif arg in ('--single-session', '--wait'):\n            supported.append(arg)\n        elif not arg.startswith('-'):\n            supported.append(arg)\n            gottarget = True\n\n        # unsupported arg\n        else:\n            supported.append(arg)\n            break\n\n    return supported, pydevd, script\n\n\ndef _parse_args(prog, argv):\n    parser = argparse.ArgumentParser(\n        prog=prog,\n        usage=USAGE.format(prog),\n    )\n\n    parser.add_argument('--nodebug', action='store_true')\n\n    host = parser.add_mutually_exclusive_group()\n    host.add_argument('--host')\n    host.add_argument('--server-host')\n    parser.add_argument('--port', type=int, required=True)\n\n    target = parser.add_mutually_exclusive_group(required=True)\n    target.add_argument('-m', dest='module')\n    target.add_argument('--pid', type=int)\n    target.add_argument('filename', nargs='?')\n\n    parser.add_argument('--single-session', action='store_true')\n    parser.add_argument('--wait', action='store_true')\n\n    parser.add_argument('-V', '--version', action='version')\n    parser.version = __version__\n\n    args = parser.parse_args(argv)\n    ns = vars(args)\n\n    serverhost = ns.pop('server_host', None)\n    clienthost = ns.pop('host', None)\n    if serverhost:\n        args.address = Address.as_server(serverhost, ns.pop('port'))\n    elif not clienthost:\n        if args.nodebug:\n            args.address = Address.as_client(clienthost, ns.pop('port'))\n        else:\n            args.address = Address.as_server(clienthost, ns.pop('port'))\n    else:\n        args.address = Address.as_client(clienthost, ns.pop('port'))\n\n    pid = ns.pop('pid')\n    module = ns.pop('module')\n    filename = ns.pop('filename')\n    if pid is not None:\n        args.name = pid\n        args.kind = 'pid'\n    elif module is not None:\n        args.name = module\n        args.kind = 'module'\n    else:\n        args.name = filename\n        args.kind = 'script'\n\n    return args\n\n\ndef handle_args(addr, name, kind, extra=(), nodebug=False, **kwargs):\n    if kind == 'pid':\n        attach_main(addr, name, *extra, **kwargs)\n    elif nodebug:\n        run_main(addr, name, kind, *extra, **kwargs)\n    else:\n        debug_main(addr, name, kind, *extra, **kwargs)\n\n\ndef main(argv=None):\n    args, extra = parse_args(argv)\n    handle_args(args.address, args.name, args.kind, extra,\n                nodebug=args.nodebug, singlesession=args.single_session,\n                wait=args.wait)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "ptvsd/__main__.py"}], "after_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See LICENSE in the project root\n# for license information.\n\nimport argparse\nimport os.path\nimport sys\n\nfrom ptvsd._attach import attach_main\nfrom ptvsd._local import debug_main, run_main\nfrom ptvsd.socket import Address\nfrom ptvsd.version import __version__, __author__  # noqa\n\n\n##################################\n# the script\n\n\"\"\"\nFor the PyDevd CLI handling see:\n\n  https://github.com/fabioz/PyDev.Debugger/blob/master/_pydevd_bundle/pydevd_command_line_handling.py\n  https://github.com/fabioz/PyDev.Debugger/blob/master/pydevd.py#L1450  (main func)\n\"\"\"  # noqa\n\nPYDEVD_OPTS = {\n    '--file',\n    '--vm_type',\n}\n\nPYDEVD_FLAGS = {\n    '--DEBUG',\n    '--DEBUG_RECORD_SOCKET_READS',\n    '--cmd-line',\n    '--module',\n    '--multiproc',\n    '--multiprocess',\n    '--print-in-debugger-startup',\n    '--save-signatures',\n    '--save-threading',\n    '--save-asyncio',\n    '--server',\n    '--qt-support=auto',\n}\n\nUSAGE = \"\"\"\n  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT -m MODULE [arg ...]\n  {0} [-h] [-V] [--nodebug] [--client] [--host HOST] --port PORT FILENAME [arg ...]\n  {0} [-h] [-V] --host HOST --port PORT --pid PROCESS_ID\n\"\"\"  # noqa\n\n\ndef parse_args(argv=None):\n    \"\"\"Return the parsed args to use in main().\"\"\"\n    if argv is None:\n        argv = sys.argv\n        prog = argv[0]\n        if prog == __file__:\n            prog = '{} -m ptvsd'.format(os.path.basename(sys.executable))\n    else:\n        prog = argv[0]\n    argv = argv[1:]\n\n    supported, pydevd, script = _group_args(argv)\n    args = _parse_args(prog, supported)\n    # '--' is used in _run_args to extract pydevd specific args\n    extra = pydevd + ['--']\n    if script:\n        extra += script\n    return args, extra\n\n\ndef _group_args(argv):\n    supported = []\n    pydevd = []\n    script = []\n\n    try:\n        pos = argv.index('--')\n    except ValueError:\n        script = []\n    else:\n        script = argv[pos + 1:]\n        argv = argv[:pos]\n\n    for arg in argv:\n        if arg == '-h' or arg == '--help':\n            return argv, [], script\n\n    gottarget = False\n    skip = 0\n    for i in range(len(argv)):\n        if skip:\n            skip -= 1\n            continue\n\n        arg = argv[i]\n        try:\n            nextarg = argv[i + 1]\n        except IndexError:\n            nextarg = None\n\n        # TODO: Deprecate the PyDevd arg support.\n        # PyDevd support\n        if gottarget:\n            script = argv[i:] + script\n            break\n        if arg == '--file':\n            if nextarg is None:  # The filename is missing...\n                pydevd.append(arg)\n                continue  # This will get handled later.\n            if nextarg.endswith(':') and '--module' in pydevd:\n                pydevd.remove('--module')\n                arg = '-m'\n                argv[i + 1] = nextarg = nextarg[:-1]\n            else:\n                arg = nextarg\n                skip += 1\n\n        if arg in PYDEVD_OPTS:\n            pydevd.append(arg)\n            if nextarg is not None:\n                pydevd.append(nextarg)\n            skip += 1\n        elif arg in PYDEVD_FLAGS:\n            pydevd.append(arg)\n        elif arg == '--nodebug':\n            supported.append(arg)\n\n        # ptvsd support\n        elif arg in ('--host', '--port', '--pid', '-m'):\n            if arg == '-m' or arg == '--pid':\n                gottarget = True\n            supported.append(arg)\n            if nextarg is not None:\n                supported.append(nextarg)\n            skip += 1\n        elif arg in ('--single-session', '--wait', '--client'):\n            supported.append(arg)\n        elif not arg.startswith('-'):\n            supported.append(arg)\n            gottarget = True\n\n        # unsupported arg\n        else:\n            supported.append(arg)\n            break\n\n    return supported, pydevd, script\n\n\ndef _parse_args(prog, argv):\n    parser = argparse.ArgumentParser(\n        prog=prog,\n        usage=USAGE.format(prog),\n    )\n\n    parser.add_argument('--nodebug', action='store_true')\n    parser.add_argument('--client', action='store_true')\n\n    parser.add_argument('--host')\n    parser.add_argument('--port', type=int, required=True)\n\n    target = parser.add_mutually_exclusive_group(required=True)\n    target.add_argument('-m', dest='module')\n    target.add_argument('--pid', type=int)\n    target.add_argument('filename', nargs='?')\n\n    parser.add_argument('--single-session', action='store_true')\n    parser.add_argument('--wait', action='store_true')\n\n    parser.add_argument('-V', '--version', action='version')\n    parser.version = __version__\n\n    args = parser.parse_args(argv)\n    ns = vars(args)\n\n    host = ns.pop('host', None)\n    port = ns.pop('port')\n    client = ns.pop('client')\n    args.address = (Address.as_client if client else Address.as_server)(host, port) # noqa\n\n    pid = ns.pop('pid')\n    module = ns.pop('module')\n    filename = ns.pop('filename')\n    if pid is not None:\n        args.name = pid\n        args.kind = 'pid'\n    elif module is not None:\n        args.name = module\n        args.kind = 'module'\n    else:\n        args.name = filename\n        args.kind = 'script'\n\n    return args\n\n\ndef handle_args(addr, name, kind, extra=(), nodebug=False, **kwargs):\n    if kind == 'pid':\n        attach_main(addr, name, *extra, **kwargs)\n    elif nodebug:\n        run_main(addr, name, kind, *extra, **kwargs)\n    else:\n        debug_main(addr, name, kind, *extra, **kwargs)\n\n\ndef main(argv=None):\n    args, extra = parse_args(argv)\n    handle_args(args.address, args.name, args.kind, extra,\n                nodebug=args.nodebug, singlesession=args.single_session,\n                wait=args.wait)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "ptvsd/__main__.py"}]}