@@ -1460,34 +1460,14 @@ def fix_x11_paste(root):
1460
1460
root .bind_class (cls , '<<Paste>>' ))
1461
1461
1462
1462
1463
- usage_msg = """\
1464
-
1465
- USAGE: idle [-deins] [-t title] [file]*
1466
- idle [-dns] [-t title] (-c cmd | -r file) [arg]*
1467
- idle [-dns] [-t title] - [arg]*
1468
-
1469
- -h print this help message and exit
1470
- -n run IDLE without a subprocess (DEPRECATED,
1471
- see Help/IDLE Help for details)
1472
-
1473
- The following options will override the IDLE 'settings' configuration:
1474
-
1475
- -e open an edit window
1476
- -i open a shell window
1477
-
1478
- The following options imply -i and will open a shell:
1479
-
1480
- -c cmd run the command in a shell, or
1481
- -r file run script from file
1482
-
1483
- -d enable the debugger
1484
- -s run $IDLESTARTUP or $PYTHONSTARTUP before anything else
1485
- -t title set title of shell window
1463
+ usage = """%(prog)s -h
1464
+ %(prog)s [-deins] [-t title] [file ...]
1465
+ %(prog)s [-dns] [-t title] (-c cmd | -r file) [arg ...]
1466
+ %(prog)s [-dns] [-t title] - [arg ...]"""
1486
1467
1468
+ epilog = """\
1487
1469
A default edit window will be bypassed when -c, -r, or - are used.
1488
1470
1489
- [arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].
1490
-
1491
1471
Examples:
1492
1472
1493
1473
idle
@@ -1511,30 +1491,45 @@ def fix_x11_paste(root):
1511
1491
1512
1492
echo "import sys; print(sys.argv)" | idle - "foobar"
1513
1493
Open a shell window, run the script piped in, passing '' in sys.argv[0]
1514
- and "foobar" in sys.argv[1].
1515
- """
1494
+ and "foobar" in sys.argv[1]."""
1516
1495
1517
1496
def main ():
1518
- import getopt
1497
+ from argparse import ArgumentParser , RawTextHelpFormatter
1519
1498
from platform import system
1520
1499
from idlelib import testing # bool value
1521
1500
from idlelib import macosx
1522
1501
1523
1502
global flist , root , use_subprocess
1524
1503
1525
1504
capture_warnings (True )
1526
- use_subprocess = True
1527
- enable_shell = False
1528
- enable_edit = False
1529
- debug = False
1530
- cmd = None
1531
- script = None
1532
- startup = False
1533
- try :
1534
- opts , args = getopt .getopt (sys .argv [1 :], "c:deihnr:st:" )
1535
- except getopt .error as msg :
1536
- print ("Error: %s\n %s" % (msg , usage_msg ), file = sys .stderr )
1537
- sys .exit (2 )
1505
+ parser = ArgumentParser (description = 'Python’s Integrated Development and '
1506
+ 'Learning Environment' , usage = usage , epilog = epilog ,
1507
+ formatter_class = RawTextHelpFormatter )
1508
+ parser .add_argument ('-n' , action = 'store_true' , help = 'run IDLE without a '
1509
+ 'subprocess (DEPRECATED, see Help/IDLE Help for '
1510
+ 'details)' )
1511
+ parser .add_argument ('file' , nargs = '*' , help = 'file path to open' )
1512
+ parser .add_argument ('arg' , nargs = '*' , help = 'parameter passed to the '
1513
+ 'command (-c), script (-r), or REPL (-) in '
1514
+ 'sys.argv[1:]' )
1515
+ settings = parser .add_argument_group (description = "the following options "
1516
+ "have priority over the IDLE "
1517
+ "'settings' configuration:" )
1518
+ settings .add_argument ('-e' , '--edit' , action = 'store_true' , help = 'open an edit window' )
1519
+ settings .add_argument ('-i' , '--interactive' , action = 'store_true' , help = 'open a shell window' )
1520
+ shell = parser .add_argument_group (description = 'the following options '
1521
+ 'imply -i:' )
1522
+ run = parser .add_mutually_exclusive_group ()
1523
+ run .add_argument ('-c' , '--command' , metavar = 'cmd' ,
1524
+ help = 'run the command in a shell, or' )
1525
+ run .add_argument ('-r' , '--run' , metavar = 'file' , help = 'run script from file' )
1526
+ shell .add_argument ('-d' , '--debug' , action = 'store_true' , help = 'enable the debugger' )
1527
+ shell .add_argument ('-s' , action = 'store_true' , help = 'run $IDLESTARTUP or '
1528
+ '$PYTHONSTARTUP before anything else' )
1529
+ shell .add_argument ('-t' , '--title' , metavar = 'title' , help = 'set title of shell window' )
1530
+
1531
+ arguments = parser .parse_args ()
1532
+
1538
1533
for o , a in opts :
1539
1534
if o == '-c' :
1540
1535
cmd = a
0 commit comments