Skip to content

Commit e53143c

Browse files
jubiizJulien Audet
andauthored
Feat/50 catch unspecified args (#67)
Fix #50. Co-authored-by: Julien Audet <julien.audet@ubisoft.com>
1 parent 74c329b commit e53143c

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

src/chatdbg/__main__.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
import ipdb
2-
from chatdbg.chatdbg_pdb import ChatDBG
3-
from chatdbg.util.config import chatdbg_config
41
import sys
2+
from getopt import GetoptError
53

6-
_usage = """\
7-
usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ...
8-
9-
Debug the Python program given by pyfile.
10-
11-
Initial commands are read from .pdbrc files in your home directory
12-
and in the current directory, if they exist. Commands supplied with
13-
-c are executed after commands from .pdbrc files.
14-
15-
To let the script run until an exception occurs, use "-c continue".
16-
To let the script run up to a given line X in the debugged file, use
17-
"-c 'until X'"
18-
19-
Option -m is available only in Python 3.7 and later.
4+
import ipdb
205

21-
ChatDBG-specific options may appear anywhere before pyfile:
22-
"""
6+
from chatdbg.chatdbg_pdb import ChatDBG
7+
from chatdbg.util.config import chatdbg_config
8+
from chatdbg.util.help import print_help
239

2410

2511
def main() -> None:
@@ -28,13 +14,16 @@ def main() -> None:
2814
args = chatdbg_config.parse_user_flags(sys.argv[1:])
2915

3016
if "-h" in args or "--help" in args:
31-
print(_usage)
32-
print(chatdbg_config.user_flags_help())
33-
sys.exit()
17+
print_help()
3418

3519
sys.argv = [sys.argv[0]] + args
3620

37-
ipdb.__main__.main()
21+
try:
22+
ipdb.__main__.main()
23+
except GetoptError as e:
24+
print(f"Unrecognized option: {e.opt}\n")
25+
print_help()
26+
sys.exit(1)
3827

3928

4029
if __name__ == "__main__":

src/chatdbg/util/help.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
3+
from chatdbg.util.config import chatdbg_config
4+
5+
_usage = """\
6+
usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ...
7+
8+
Debug the Python program given by pyfile.
9+
10+
Initial commands are read from .pdbrc files in your home directory
11+
and in the current directory, if they exist. Commands supplied with
12+
-c are executed after commands from .pdbrc files.
13+
14+
To let the script run until an exception occurs, use "-c continue".
15+
To let the script run up to a given line X in the debugged file, use
16+
"-c 'until X'"
17+
18+
Option -m is available only in Python 3.7 and later.
19+
20+
ChatDBG-specific options may appear anywhere before pyfile:
21+
"""
22+
23+
24+
def print_help():
25+
print(_usage)
26+
print(chatdbg_config.user_flags_help())
27+
sys.exit()

0 commit comments

Comments
 (0)