@@ -2250,15 +2250,19 @@ def main():
2250
2250
import argparse
2251
2251
2252
2252
parser = argparse .ArgumentParser (prog = "pdb" ,
2253
+ usage = "%(prog)s [-h] [-c command] (-m module | pyfile) [args ...]" ,
2253
2254
description = _usage ,
2254
2255
formatter_class = argparse .RawDescriptionHelpFormatter ,
2255
2256
allow_abbrev = False )
2256
2257
2257
- parser .add_argument ('-c' , '--command' , action = 'append' , default = [], metavar = 'command' )
2258
- group = parser .add_mutually_exclusive_group (required = True )
2259
- group .add_argument ('-m' , metavar = 'module' )
2260
- group .add_argument ('pyfile' , nargs = '?' )
2261
- parser .add_argument ('args' , nargs = "*" )
2258
+ # We need to maunally get the script from args, because the first positional
2259
+ # arguments could be either the script we need to debug, or the argument
2260
+ # to the -m module
2261
+ parser .add_argument ('-c' , '--command' , action = 'append' , default = [], metavar = 'command' , dest = 'commands' ,
2262
+ help = 'pdb commands to execute as if given in a .pdbrc file' )
2263
+ parser .add_argument ('-m' , metavar = 'module' , dest = 'module' )
2264
+ parser .add_argument ('args' , nargs = '*' ,
2265
+ help = "when -m is not specified, the first arg is the script to debug" )
2262
2266
2263
2267
if len (sys .argv ) == 1 :
2264
2268
# If no arguments were given (python -m pdb), print the whole help message.
@@ -2268,11 +2272,13 @@ def main():
2268
2272
2269
2273
opts = parse
10000
r .parse_args ()
2270
2274
2271
- if opts .m :
2272
- file = opts .m
2275
+ if opts .module :
2276
+ file = opts .module
2273
2277
target = _ModuleTarget (file )
2274
2278
else :
2275
- file = opts .pyfile
2279
+ if not opts .args :
2280
+ parser .error ("no module or script to run" )
2281
+ file = opts .args .pop (0 )
2276
2282
target = _ScriptTarget (file )
2277
2283
2278
2284
target .check ()
@@ -2284,7 +2290,7 @@ def main():
2284
2290
# changed by the user from the command line. There is a "restart" command
2285
2291
# which allows explicit specification of command line arguments.
2286
2292
pdb = Pdb ()
2287
- pdb .rcLines .extend (opts .command )
2293
+ pdb .rcLines .extend (opts .commands )
2288
2294
while True :
2289
2295
try :
2290
2296
pdb ._run (target )
0 commit comments