summaryrefslogtreecommitdiff
path: root/doxygen/man/man3/cmd2_Cmd.3
blob: cd5c11dcc2a65aee1edad7688e61d004558b91d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
.TH "cmd2::Cmd" 3 "Fri Sep 9 2011" "Cmd2" \" -*- nroff -*-
.ad l
.nh
.SH NAME
cmd2::Cmd \- 
.SH SYNOPSIS
.br
.PP
.PP
Inherited by \fBexample::CmdLineApp\fP, \fBpirate6::Pirate\fP, \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "def \fB__init__\fP"
.br
.ti -1c
.RI "def \fBcmdloop\fP"
.br
.ti -1c
.RI "def \fBcolorize\fP"
.br
.ti -1c
.RI "def \fBcomplete_statement\fP"
.br
.ti -1c
.RI "def \fBdo__relative_load\fP"
.br
.ti -1c
.RI "def \fBdo_cmdenvironment\fP"
.br
.ti -1c
.RI "def \fBdo_ed\fP"
.br
.ti -1c
.RI "def \fBdo_EOF\fP"
.br
.ti -1c
.RI "def \fBdo_help\fP"
.br
.ti -1c
.RI "def \fBdo_history\fP"
.br
.ti -1c
.RI "def \fBdo_list\fP"
.br
.ti -1c
.RI "def \fBdo_load\fP"
.br
.ti -1c
.RI "def \fBdo_pause\fP"
.br
.ti -1c
.RI "def \fBdo_py\fP"
.br
.ti -1c
.RI "def \fBdo_quit\fP"
.br
.ti -1c
.RI "def \fBdo_run\fP"
.br
.ti -1c
.RI "def \fBdo_save\fP"
.br
.ti -1c
.RI "def \fBdo_set\fP"
.br
.ti -1c
.RI "def \fBdo_shell\fP"
.br
.ti -1c
.RI "def \fBdo_shortcuts\fP"
.br
.ti -1c
.RI "def \fBdo_show\fP"
.br
.ti -1c
.RI "def \fBfileimport\fP"
.br
.ti -1c
.RI "def \fBfunc_named\fP"
.br
.ti -1c
.RI "def \fBlast_matching\fP"
.br
.ti -1c
.RI "def \fBonecmd\fP"
.br
.ti -1c
.RI "def \fBonecmd_plus_hooks\fP"
.br
.ti -1c
.RI "def \fBparsed\fP"
.br
.ti -1c
.RI "def \fBperror\fP"
.br
.ti -1c
.RI "def \fBpfeedback\fP"
.br
.ti -1c
.RI "def \fBpostparse\fP"
.br
.ti -1c
.RI "def \fBpostparsing_postcmd\fP"
.br
.ti -1c
.RI "def \fBpostparsing_precmd\fP"
.br
.ti -1c
.RI "def \fBpoutput\fP"
.br
.ti -1c
.RI "def \fBpreparse\fP"
.br
.ti -1c
.RI "def \fBpseudo_raw_input\fP"
.br
.ti -1c
.RI "def \fBread_file_or_url\fP"
.br
.ti -1c
.RI "def \fBredirect_output\fP"
.br
.ti -1c
.RI "def \fBrestore_output\fP"
.br
.ti -1c
.RI "def \fBrun_commands_at_invocation\fP"
.br
.ti -1c
.RI "def \fBrunTranscriptTests\fP"
.br
.ti -1c
.RI "def \fBselect\fP"
.br
.in -1c
.SS "Public Attributes"

.in +1c
.ti -1c
.RI "\fBblankLineTerminationParser\fP"
.br
.ti -1c
.RI "\fBblankLineTerminator\fP"
.br
.ti -1c
.RI "\fBcontinuation_prompt\fP"
.br
.ti -1c
.RI "\fBhistory\fP"
.br
.ti -1c
.RI "\fBinitial_stdout\fP"
.br
.ti -1c
.RI "\fBinputParser\fP"
.br
.ti -1c
.RI "\fBintro\fP"
.br
.ti -1c
.RI "\fBkept_sys\fP"
.br
.ti -1c
.RI "\fBkeywords\fP"
.br
.ti -1c
.RI "\fBlastcmd\fP"
.br
.ti -1c
.RI "\fBmultilineCommand\fP"
.br
.ti -1c
.RI "\fBmultilineParser\fP"
.br
.ti -1c
.RI "\fBold_completer\fP"
.br
.ti -1c
.RI "\fBparser\fP"
.br
.ti -1c
.RI "\fBprompt\fP"
.br
.ti -1c
.RI "\fBpystate\fP"
.br
.ti -1c
.RI "\fBredirect\fP"
.br
.ti -1c
.RI "\fBshortcuts\fP"
.br
.ti -1c
.RI "\fBsingleLineParser\fP"
.br
.ti -1c
.RI "\fBstdin\fP"
.br
.ti -1c
.RI "\fBstdout\fP"
.br
.ti -1c
.RI "\fBuse_rawinput\fP"
.br
.in -1c
.SS "Static Public Attributes"

.in +1c
.ti -1c
.RI "\fBabbrev\fP = True"
.br
.ti -1c
.RI "\fBblankLinesAllowed\fP = False"
.br
.ti -1c
.RI "\fBcase_insensitive\fP = True"
.br
.ti -1c
.RI "dictionary \fBcolorcodes\fP"
.br
.ti -1c
.RI "tuple \fBcolors\fP = (platform\&.system() != 'Windows')"
.br
.ti -1c
.RI "tuple \fBcommentGrammars\fP = pyparsing\&.Or([pyparsing\&.pythonStyleComment, pyparsing\&.cStyleComment])"
.br
.ti -1c
.RI "tuple \fBcommentInProgress\fP = pyparsing\&.Literal('/*')"
.br
.ti -1c
.RI "string \fBcontinuation_prompt\fP = '> '"
.br
.ti -1c
.RI "\fBcurrent_script_dir\fP = None"
.br
.ti -1c
.RI "\fBdebug\fP = False"
.br
.ti -1c
.RI "string \fBdefault_file_name\fP = 'command\&.txt'"
.br
.ti -1c
.RI "\fBdefault_to_shell\fP = False"
.br
.ti -1c
.RI "string \fBdefaultExtension\fP = 'txt'"
.br
.ti -1c
.RI "\fBdo__load\fP = do_load"
.br
.ti -1c
.RI "\fBdo_edit\fP = do_ed"
.br
.ti -1c
.RI "\fBdo_eof\fP = do_EOF"
.br
.ti -1c
.RI "\fBdo_exit\fP = do_quit"
.br
.ti -1c
.RI "\fBdo_hi\fP = do_history"
.br
.ti -1c
.RI "\fBdo_l\fP = do_list"
.br
.ti -1c
.RI "\fBdo_li\fP = do_list"
.br
.ti -1c
.RI "\fBdo_q\fP = do_quit"
.br
.ti -1c
.RI "\fBdo_r\fP = do_run"
.br
.ti -1c
.RI "\fBecho\fP = False"
.br
.ti -1c
.RI "tuple \fBeditor\fP = os\&.environ\&.get('EDITOR')"
.br
.ti -1c
.RI "string \fBeditor\fP = 'notepad'"
.br
.ti -1c
.RI "string \fBexcludeFromHistory\fP = '''run r list l \fBhistory\fP hi ed edit li eof'''"
.br
.ti -1c
.RI "\fBfeedback_to_output\fP = False"
.br
.ti -1c
.RI "string \fBhelp\fP = 'describe function of parameter'"
.br
.ti -1c
.RI "\fBkept_state\fP = None"
.br
.ti -1c
.RI "string \fBlegalChars\fP = u'!#$%\&.:?@_'"
.br
.ti -1c
.RI "\fBlocals_in_py\fP = True"
.br
.ti -1c
.RI "list \fBmultilineCommands\fP = []"
.br
.ti -1c
.RI "string \fBnoSpecialParse\fP = 'set ed edit exit'"
.br
.ti -1c
.RI "tuple \fBprefixParser\fP = pyparsing\&.Empty()"
.br
.ti -1c
.RI "\fBquiet\fP = False"
.br
.ti -1c
.RI "string \fBredirector\fP = '>'"
.br
.ti -1c
.RI "list \fBreserved_words\fP = []"
.br
.ti -1c
.RI "tuple \fBsaveparser\fP"
.br
.ti -1c
.RI "tuple \fBsettable\fP"
.br
.ti -1c
.RI "dictionary \fBshortcuts\fP = {'?': '\fBhelp\fP', '!': 'shell', '@': 'load', '@@': '_relative_load'}"
.br
.ti -1c
.RI "list \fBterminators\fP = [';']"
.br
.ti -1c
.RI "\fBtiming\fP = False"
.br
.ti -1c
.RI "tuple \fBurlre\fP = re\&.compile('(https?://[-\\\\w\\\\\&./]+)')"
.br
.in -1c
.SS "Private Member Functions"

.in +1c
.ti -1c
.RI "def \fB_cmdloop\fP"
.br
.ti -1c
.RI "def \fB_default\fP"
.br
.ti -1c
.RI "def \fB_init_parser\fP"
.br
.in -1c
.SS "Static Private Attributes"

.in +1c
.ti -1c
.RI "\fB_STOP_AND_EXIT\fP = True"
.br
.ti -1c
.RI "int \fB_STOP_SCRIPT_NO_EXIT\fP = 999"
.br
.in -1c
.SH "Detailed Description"
.PP 
Definition at line 361 of file cmd2\&.py'\&.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "def cmd2::Cmd::__init__ (self, args, kwargs)"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.PP
.nf
469 
470     def __init__(self, *args, **kwargs):        
471         cmd\&.Cmd\&.__init__(self, *args, **kwargs)
472         self\&.initial_stdout = sys\&.stdout
473         self\&.history = History()
474         self\&.pystate = {}
475         self\&.shortcuts = sorted(self\&.shortcuts\&.items(), reverse=True)
476         self\&.keywords = self\&.reserved_words + [fname[3:] for fname in dir(self) 
477                                                if fname\&.startswith('do_')]            
478         self\&._init_parser()
            
.fi
.SH "Member Function Documentation"
.PP 
.SS "def cmd2::Cmd::_cmdloop (self, intro = \fCNone\fP)\fC [private]\fP".PP
.nf
Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
.fi
.PP
 
.PP
Definition at line 895 of file cmd2\&.py'\&.
.PP
Referenced by cmdloop()\&.
.PP
.nf
895 
896     def _cmdloop(self, intro=None):
897         '''Repeatedly issue a prompt, accept input, parse an initial prefix
898         off the received input, and dispatch to action methods, passing them
899         the remainder of the line as argument\&.
900         '''
901 
902         # An almost perfect copy from Cmd; however, the pseudo_raw_input portion
903         # has been split out so that it can be called separately
904         
905         self\&.preloop()
906         if self\&.use_rawinput and self\&.completekey:
907             try:
908                 import readline
909                 self\&.old_completer = readline\&.get_completer()
910                 readline\&.set_completer(self\&.complete)
911                 readline\&.parse_and_bind(self\&.completekey+': complete')
912             except ImportError:
913                 pass
914         try:
915             if intro is not None:
916                 self\&.intro = intro
917             if self\&.intro:
918                 self\&.stdout\&.write(str(self\&.intro)+'\n')
919             stop = None
920             while not stop:
921                 if self\&.cmdqueue:
922                     line = self\&.cmdqueue\&.pop(0)
923                 else:
924                     line = self\&.pseudo_raw_input(self\&.prompt)
925                 if (self\&.echo) and (isinstance(self\&.stdin, file)):
926                     self\&.stdout\&.write(line + '\n')
927                 stop = self\&.onecmd_plus_hooks(line)
928             self\&.postloop()
929         finally:
930             if self\&.use_rawinput and self\&.completekey:
931                 try:
932                     import readline
933                     readline\&.set_completer(self\&.old_completer)
934                 except ImportError:
935                     pass    
936             return stop

.fi
.SS "def cmd2::Cmd::_default (self, statement)\fC [private]\fP"
.PP
Definition at line 868 of file cmd2\&.py'\&.
.PP
References pirate6::Pirate::default(), pirate8::Pirate::default(), pirate7::Pirate::default(), default_to_shell, and postparsing_postcmd()\&.
.PP
.nf
868 
869     def _default(self, statement):
870         arg = statement\&.full_parsed_statement()
871         if self\&.default_to_shell:
872             result = os\&.system(arg)
873             if not result:
874                 return self\&.postparsing_postcmd(None)
875         return self\&.postparsing_postcmd(self\&.default(arg))

.fi
.SS "def cmd2::Cmd::_init_parser (self)\fC [private]\fP"
.PP
Definition at line 493 of file cmd2\&.py'\&.
.PP
.nf
493 
494     def _init_parser(self):
495         r'''
496         >>> c = Cmd()
497         >>> c\&.multilineCommands = ['multiline']
498         >>> c\&.case_insensitive = True
499         >>> c\&._init_parser()
500         >>> print (c\&.parser\&.parseString('')\&.dump())
501         []
502         >>> print (c\&.parser\&.parseString('')\&.dump())
503         []        
504         >>> print (c\&.parser\&.parseString('/* empty command */')\&.dump())
505         []        
506         >>> print (c\&.parser\&.parseString('plainword')\&.dump())
507         ['plainword', '']
508         - command: plainword
509         - statement: ['plainword', '']
510           - command: plainword        
511         >>> print (c\&.parser\&.parseString('termbare;')\&.dump())
512         ['termbare', '', ';', '']
513         - command: termbare
514         - statement: ['termbare', '', ';']
515           - command: termbare
516           - terminator: ;
517         - terminator: ;        
518         >>> print (c\&.parser\&.parseString('termbare; suffx')\&.dump())
519         ['termbare', '', ';', 'suffx']
520         - command: termbare
521         - statement: ['termbare', '', ';']
522           - command: termbare
523           - terminator: ;
524         - suffix: suffx
525         - terminator: ;        
526         >>> print (c\&.parser\&.parseString('barecommand')\&.dump())
527         ['barecommand', '']
528         - command: barecommand
529         - statement: ['barecommand', '']
530           - command: barecommand
531         >>> print (c\&.parser\&.parseString('COMmand with args')\&.dump())
532         ['command', 'with args']
533         - args: with args
534         - command: command
535         - statement: ['command', 'with args']
536           - args: with args
537           - command: command
538         >>> print (c\&.parser\&.parseString('command with args and terminator; and suffix')\&.dump())
539         ['command', 'with args and terminator', ';', 'and suffix']
540         - args: with args and terminator
541         - command: command
542         - statement: ['command', 'with args and terminator', ';']
543           - args: with args and terminator
544           - command: command
545           - terminator: ;
546         - suffix: and suffix
547         - terminator: ;
548         >>> print (c\&.parser\&.parseString('simple | piped')\&.dump())
549         ['simple', '', '|', ' piped']
550         - command: simple
551         - pipeTo:  piped
552         - statement: ['simple', '']
553           - command: simple
554         >>> print (c\&.parser\&.parseString('double-pipe || is not a pipe')\&.dump())
555         ['double', '-pipe || is not a pipe']
556         - args: -pipe || is not a pipe
557         - command: double
558         - statement: ['double', '-pipe || is not a pipe']
559           - args: -pipe || is not a pipe
560           - command: double
561         >>> print (c\&.parser\&.parseString('command with args, terminator;sufx | piped')\&.dump())
562         ['command', 'with args, terminator', ';', 'sufx', '|', ' piped']
563         - args: with args, terminator
564         - command: command
565         - pipeTo:  piped
566         - statement: ['command', 'with args, terminator', ';']
567           - args: with args, terminator
568           - command: command
569           - terminator: ;
570         - suffix: sufx
571         - terminator: ;
572         >>> print (c\&.parser\&.parseString('output into > afile\&.txt')\&.dump())
573         ['output', 'into', '>', 'afile\&.txt']
574         - args: into
575         - command: output
576         - output: >
577         - outputTo: afile\&.txt
578         - statement: ['output', 'into']
579           - args: into
580           - command: output   
581         >>> print (c\&.parser\&.parseString('output into;sufx | pipethrume plz > afile\&.txt')\&.dump())
582         ['output', 'into', ';', 'sufx', '|', ' pipethrume plz', '>', 'afile\&.txt']
583         - args: into
584         - command: output
585         - output: >
586         - outputTo: afile\&.txt
587         - pipeTo:  pipethrume plz
588         - statement: ['output', 'into', ';']
589           - args: into
590           - command: output
591           - terminator: ;
592         - suffix: sufx
593         - terminator: ;
594         >>> print (c\&.parser\&.parseString('output to paste buffer >> ')\&.dump())
595         ['output', 'to paste buffer', '>>', '']
596         - args: to paste buffer
597         - command: output
598         - output: >>
599         - statement: ['output', 'to paste buffer']
600           - args: to paste buffer
601           - command: output
602         >>> print (c\&.parser\&.parseString('ignore the /* commented | > */ stuff;')\&.dump())
603         ['ignore', 'the /* commented | > */ stuff', ';', '']
604         - args: the /* commented | > */ stuff
605         - command: ignore
606         - statement: ['ignore', 'the /* commented | > */ stuff', ';']
607           - args: the /* commented | > */ stuff
608           - command: ignore
609           - terminator: ;
610         - terminator: ;
611         >>> print (c\&.parser\&.parseString('has > inside;')\&.dump())
612         ['has', '> inside', ';', '']
613         - args: > inside
614         - command: has
615         - statement: ['has', '> inside', ';']
616           - args: > inside
617           - command: has
618           - terminator: ;
619         - terminator: ;        
620         >>> print (c\&.parser\&.parseString('multiline has > inside an unfinished command')\&.dump())
621         ['multiline', ' has > inside an unfinished command']
622         - multilineCommand: multiline        
623         >>> print (c\&.parser\&.parseString('multiline has > inside;')\&.dump())
624         ['multiline', 'has > inside', ';', '']
625         - args: has > inside
626         - multilineCommand: multiline
627         - statement: ['multiline', 'has > inside', ';']
628           - args: has > inside
629           - multilineCommand: multiline
630           - terminator: ;
631         - terminator: ;        
632         >>> print (c\&.parser\&.parseString('multiline command /* with comment in progress;')\&.dump())
633         ['multiline', ' command /* with comment in progress;']
634         - multilineCommand: multiline
635         >>> print (c\&.parser\&.parseString('multiline command /* with comment complete */ is done;')\&.dump())
636         ['multiline', 'command /* with comment complete */ is done', ';', '']
637         - args: command /* with comment complete */ is done
638         - multilineCommand: multiline
639         - statement: ['multiline', 'command /* with comment complete */ is done', ';']
640           - args: command /* with comment complete */ is done
641           - multilineCommand: multiline
642           - terminator: ;
643         - terminator: ;
644         >>> print (c\&.parser\&.parseString('multiline command ends\n\n')\&.dump())
645         ['multiline', 'command ends', '\n', '\n']
646         - args: command ends
647         - multilineCommand: multiline
648         - statement: ['multiline', 'command ends', '\n', '\n']
649           - args: command ends
650           - multilineCommand: multiline
651           - terminator: ['\n', '\n']
652         - terminator: ['\n', '\n']
653         >>> print (c\&.parser\&.parseString('multiline command 'with term; ends' now\n\n')\&.dump())
654         ['multiline', 'command 'with term; ends' now', '\n', '\n']
655         - args: command 'with term; ends' now
656         - multilineCommand: multiline
657         - statement: ['multiline', 'command 'with term; ends' now', '\n', '\n']
658           - args: command 'with term; ends' now
659           - multilineCommand: multiline
660           - terminator: ['\n', '\n']
661         - terminator: ['\n', '\n']
662         >>> print (c\&.parser\&.parseString('what if 'quoted strings /* seem to ' start comments?')\&.dump())
663         ['what', 'if 'quoted strings /* seem to ' start comments?']
664         - args: if 'quoted strings /* seem to ' start comments?
665         - command: what
666         - statement: ['what', 'if 'quoted strings /* seem to ' start comments?']
667           - args: if 'quoted strings /* seem to ' start comments?
668           - command: what
669         '''
670         #outputParser = (pyparsing\&.Literal('>>') | (pyparsing\&.WordStart() + '>') | pyparsing\&.Regex('[^=]>'))('output')
671         outputParser = (pyparsing\&.Literal(self\&.redirector *2) | \
672                        (pyparsing\&.WordStart() + self\&.redirector) | \
673                         pyparsing\&.Regex('[^=]' + self\&.redirector))('output')
674         
675         terminatorParser = pyparsing\&.Or([(hasattr(t, 'parseString') and t) or pyparsing\&.Literal(t) for t in self\&.terminators])('terminator')
676         stringEnd = pyparsing\&.stringEnd ^ '\nEOF'
677         self\&.multilineCommand = pyparsing\&.Or([pyparsing\&.Keyword(c, caseless=self\&.case_insensitive) for c in self\&.multilineCommands])('multilineCommand')
678         oneLineCommand = (~self\&.multilineCommand + pyparsing\&.Word(self\&.legalChars))('command')
679         pipe = pyparsing\&.Keyword('|', identChars='|')
680         self\&.commentGrammars\&.ignore(pyparsing\&.quotedString)\&.setParseAction(lambda x: '')
681         doNotParse = self\&.commentGrammars | self\&.commentInProgress | pyparsing\&.quotedString
682         afterElements = \
683             pyparsing\&.Optional(pipe + pyparsing\&.SkipTo(outputParser ^ stringEnd, ignore=doNotParse)('pipeTo')) + \
684             pyparsing\&.Optional(outputParser + pyparsing\&.SkipTo(stringEnd, ignore=doNotParse)\&.setParseAction(lambda x: x[0]\&.strip())('outputTo'))
685         if self\&.case_insensitive:
686             self\&.multilineCommand\&.setParseAction(lambda x: x[0]\&.lower())
687             oneLineCommand\&.setParseAction(lambda x: x[0]\&.lower())
688         if self\&.blankLinesAllowed:
689             self\&.blankLineTerminationParser = pyparsing\&.NoMatch
690         else:
691             self\&.blankLineTerminator = (pyparsing\&.lineEnd + pyparsing\&.lineEnd)('terminator')
692             self\&.blankLineTerminator\&.setResultsName('terminator')
693             self\&.blankLineTerminationParser = ((self\&.multilineCommand ^ oneLineCommand) + pyparsing\&.SkipTo(self\&.blankLineTerminator, ignore=doNotParse)\&.setParseAction(lambda x: x[0]\&.strip())('args') + self\&.blankLineTerminator)('statement')
694         self\&.multilineParser = (((self\&.multilineCommand ^ oneLineCommand) + pyparsing\&.SkipTo(terminatorParser, ignore=doNotParse)\&.setParseAction(lambda x: x[0]\&.strip())('args') + terminatorParser)('statement') +
695                                 pyparsing\&.SkipTo(outputParser ^ pipe ^ stringEnd, ignore=doNotParse)\&.setParseAction(lambda x: x[0]\&.strip())('suffix') + afterElements)
696         self\&.multilineParser\&.ignore(self\&.commentInProgress)
697         self\&.singleLineParser = ((oneLineCommand + pyparsing\&.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser, ignore=doNotParse)\&.setParseAction(lambda x:x[0]\&.strip())('args'))('statement') +
698                                  pyparsing\&.Optional(terminatorParser) + afterElements)
699         #self\&.multilineParser = self\&.multilineParser\&.setResultsName('multilineParser')
700         #self\&.singleLineParser = self\&.singleLineParser\&.setResultsName('singleLineParser')
701         self\&.blankLineTerminationParser = self\&.blankLineTerminationParser\&.setResultsName('statement')
702         self\&.parser = self\&.prefixParser + (
703             stringEnd |
704             self\&.multilineParser |
705             self\&.singleLineParser |
706             self\&.blankLineTerminationParser | 
707             self\&.multilineCommand + pyparsing\&.SkipTo(stringEnd, ignore=doNotParse)
708             )
709         self\&.parser\&.ignore(self\&.commentGrammars)
710         
711         inputMark = pyparsing\&.Literal('<')
712         inputMark\&.setParseAction(lambda x: '')
713         fileName = pyparsing\&.Word(self\&.legalChars + '/\\')
714         inputFrom = fileName('inputFrom')
715         inputFrom\&.setParseAction(replace_with_file_contents)
716         # a not-entirely-satisfactory way of distinguishing < as in 'import from' from <
717         # as in 'lesser than'
718         self\&.inputParser = inputMark + pyparsing\&.Optional(inputFrom) + pyparsing\&.Optional('>') + \
719                            pyparsing\&.Optional(fileName) + (pyparsing\&.stringEnd | '|')
720         self\&.inputParser\&.ignore(self\&.commentInProgress)               
    
.fi
.SS "def cmd2::Cmd::cmdloop (self)"
.PP
Definition at line 1283 of file cmd2\&.py'\&.
.PP
References _cmdloop(), run_commands_at_invocation(), and runTranscriptTests()\&.
.PP
.nf
1283 
1284     def cmdloop(self):
1285         parser = optparse\&.OptionParser()
1286         parser\&.add_option('-t', '--test', dest='test',
1287                action='store_true', 
1288                help='Test against transcript(s) in FILE (wildcards OK)')
1289         (callopts, callargs) = parser\&.parse_args()
1290         if callopts\&.test:
1291             self\&.runTranscriptTests(callargs)
1292         else:
1293             if not self\&.run_commands_at_invocation(callargs):
1294                 self\&._cmdloop()   
            
.fi
.SS "def cmd2::Cmd::colorize (self, val, color)".PP
.nf
Given a string (``val``), returns that string wrapped in UNIX-style 
   special characters that turn on (and then off) text color and style.
   If the ``colors`` environment paramter is ``False``, or the application
   is running on Windows, will return ``val`` unchanged.
   ``color`` should be one of the supported strings (or styles):
   red/blue/green/cyan/magenta, bold, underline.fi
.PP
 
.PP
Definition at line 435 of file cmd2\&.py'\&.
.PP
Referenced by pirate7::Pirate::do_sing(), and pirate8::Pirate::do_sing()\&.
.PP
.nf
435 
436     def colorize(self, val, color):
437         '''Given a string (``val``), returns that string wrapped in UNIX-style 
438            special characters that turn on (and then off) text color and style\&.
439            If the ``colors`` environment paramter is ``False``, or the application
440            is running on Windows, will return ``val`` unchanged\&.
441            ``color`` should be one of the supported strings (or styles):
442            red/blue/green/cyan/magenta, bold, underline'''
443         if self\&.colors and (self\&.stdout == self\&.initial_stdout):
444             return self\&.colorcodes[color][True] + val + self\&.colorcodes[color][False]
445         return val

.fi
.SS "def cmd2::Cmd::complete_statement (self, line)".PP
.nf
Keep accepting lines of input until the command is complete..fi
.PP
 
.PP
Definition at line 794 of file cmd2\&.py'\&.
.PP
References commentGrammars, continuation_prompt, parsed(), and pseudo_raw_input()\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.PP
.nf
794 
795     def complete_statement(self, line):
796         '''Keep accepting lines of input until the command is complete\&.'''
797         if (not line) or (
798             not pyparsing\&.Or(self\&.commentGrammars)\&.
799                 setParseAction(lambda x: '')\&.transformString(line)):
800             raise EmptyStatement
801         statement = self\&.parsed(line)
802         while statement\&.parsed\&.multilineCommand and (statement\&.parsed\&.terminator == ''):
803             statement = '%s\n%s' % (statement\&.parsed\&.raw, 
804                                     self\&.pseudo_raw_input(self\&.continuation_prompt))                
805             statement = self\&.parsed(statement)
806         if not statement\&.parsed\&.command:
807             raise EmptyStatement
808         return statement
    
.fi
.SS "def cmd2::Cmd::do__relative_load (self, arg = \fCNone\fP)".PP
.nf

Runs commands in script at file or URL; if this is called from within an
already-running script, the filename will be interpreted relative to the 
already-running script's directory..fi
.PP
 
.PP
Definition at line 1206 of file cmd2\&.py'\&.
.PP
References current_script_dir, and do__load\&.
.PP
.nf
1206 
1207     def do__relative_load(self, arg=None):
1208         '''
1209         Runs commands in script at file or URL; if this is called from within an
1210         already-running script, the filename will be interpreted relative to the 
1211         already-running script's directory\&.'''
1212         if arg:
1213             arg = arg\&.split(None, 1)
1214             targetname, args = arg[0], (arg[1:] or [''])[0]
1215             targetname = os\&.path\&.join(self\&.current_script_dir or '', targetname)
1216             self\&.do__load('%s %s' % (targetname, args))
    
.fi
.SS "def cmd2::Cmd::do_cmdenvironment (self, args)".PP
.nf
Summary report of interactive parameters..fi
.PP
 
.PP
Definition at line 446 of file cmd2\&.py'\&.
.PP
References case_insensitive, settable, and terminators\&.
.PP
.nf
446 
447     def do_cmdenvironment(self, args):
448         '''Summary report of interactive parameters\&.'''
449         self\&.stdout\&.write('''
450         Commands are %(casesensitive)scase-sensitive\&.
451         Commands may be terminated with: %(terminators)s
452         Settable parameters: %(settable)s\n''' % \
453         { 'casesensitive': (self\&.case_insensitive and 'not ') or '',
454           'terminators': str(self\&.terminators),
455           'settable': ' '\&.join(self\&.settable)
456         })
        
.fi
.SS "def cmd2::Cmd::do_ed (self, arg)".PP
.nf
ed: edit most recent command in text editor
ed [N]: edit numbered command from history
ed [filename]: edit specified file name

commands are run after editor is closed.
"set edit (program-name)" or set  EDITOR environment variable
to control which editing program is used..fi
.PP
 
.PP
Definition at line 1128 of file cmd2\&.py'\&.
.PP
References default_file_name, do__load, editor, history, and last_matching()\&.
.PP
.nf
1128 
1129     def do_ed(self, arg):
1130         '''ed: edit most recent command in text editor
1131         ed [N]: edit numbered command from history
1132         ed [filename]: edit specified file name
1133         
1134         commands are run after editor is closed\&.
1135         'set edit (program-name)' or set  EDITOR environment variable
1136         to control which editing program is used\&.'''
1137         if not self\&.editor:
1138             raise EnvironmentError('Please use 'set editor' to specify your text editing program of choice\&.')
1139         filename = self\&.default_file_name
1140         if arg:
1141             try:
1142                 buffer = self\&.last_matching(int(arg))
1143             except ValueError:
1144                 filename = arg
1145                 buffer = ''
1146         else:
1147             buffer = self\&.history[-1]
1148 
1149         if buffer:
1150             f = open(os\&.path\&.expanduser(filename), 'w')
1151             f\&.write(buffer or '')
1152             f\&.close()        
1153                 
1154         os\&.system('%s %s' % (self\&.editor, filename))
        self\&.do__load(filename)
.fi
.SS "def cmd2::Cmd::do_EOF (self, arg)"
.PP
Definition at line 937 of file cmd2\&.py'\&.
.PP
References _STOP_SCRIPT_NO_EXIT\&.
.PP
.nf
937 
938     def do_EOF(self, arg):
        return self\&._STOP_SCRIPT_NO_EXIT # End of script; should not exit app
.fi
.SS "def cmd2::Cmd::do_help (self, arg)"
.PP
Definition at line 457 of file cmd2\&.py'\&.
.PP
References func_named(), and stdout\&.
.PP
.nf
457 
458     def do_help(self, arg):
459         if arg:
460             funcname = self\&.func_named(arg)
461             if funcname:
462                 fn = getattr(self, funcname)
463                 try:
464                     fn\&.optionParser\&.print_help(file=self\&.stdout)
465                 except AttributeError:
466                     cmd\&.Cmd\&.do_help(self, funcname[3:])
467         else:
468             cmd\&.Cmd\&.do_help(self, arg)
        
.fi
.SS "def cmd2::Cmd::do_history (self, arg, opts)".PP
.nf
history [arg]: lists past commands issued

| no arg:         list all
| arg is integer: list one history item, by index
| arg is string:  string search
| arg is /enclosed in forward-slashes/: regular expression search
.fi
.PP
 
.PP
Definition at line 1083 of file cmd2\&.py'\&.
.PP
References history, and poutput()\&.
.PP
.nf
1083 
1084     def do_history(self, arg, opts):
1085         '''history [arg]: lists past commands issued
1086         
1087         | no arg:         list all
1088         | arg is integer: list one history item, by index
1089         | arg is string:  string search
1090         | arg is /enclosed in forward-slashes/: regular expression search
1091         '''
1092         if arg:
1093             history = self\&.history\&.get(arg)
1094         else:
1095             history = self\&.history
1096         for hi in history:
1097             if opts\&.script:
1098                 self\&.poutput(hi)
1099             else:
                self\&.stdout\&.write(hi\&.pr())
.fi
.SS "def cmd2::Cmd::do_list (self, arg)".PP
.nf
list [arg]: lists last command issued

no arg -> list most recent command
arg is integer -> list one history item, by index
a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end)
arg is string -> list all commands matching string search
arg is /enclosed in forward-slashes/ -> regular expression search
.fi
.PP
 
.PP
Definition at line 1108 of file cmd2\&.py'\&.
.PP
References poutput()\&.
.PP
.nf
1108 
1109     def do_list(self, arg):
1110         '''list [arg]: lists last command issued
1111         
1112         no arg -> list most recent command
1113         arg is integer -> list one history item, by index
1114         a\&.\&.b, a:b, a:, \&.\&.b -> list spans from a (or start) to b (or end)
1115         arg is string -> list all commands matching string search
1116         arg is /enclosed in forward-slashes/ -> regular expression search
1117         '''
1118         try:
1119             history = self\&.history\&.span(arg or '-1')
1120         except IndexError:
1121             history = self\&.history\&.search(arg)
1122         for hi in history:
1123             self\&.poutput(hi\&.pr())

.fi
.SS "def cmd2::Cmd::do_load (self, arg = \fCNone\fP)".PP
.nf
Runs script of command(s) from a file or URL..fi
.PP
 
.PP
Definition at line 1218 of file cmd2\&.py'\&.
.PP
.nf
1218 
1219     def do_load(self, arg=None):           
1220         '''Runs script of command(s) from a file or URL\&.'''
1221         if arg is None:
1222             targetname = self\&.default_file_name
1223         else:
1224             arg = arg\&.split(None, 1)
1225             targetname, args = arg[0], (arg[1:] or [''])[0]\&.strip()
1226         try:
1227             target = self\&.read_file_or_url(targetname)
1228         except IOError, e:
1229             self\&.perror('Problem accessing script from %s: \n%s' % (targetname, e))
1230             return
1231         keepstate = Statekeeper(self, ('stdin','use_rawinput','prompt',
1232                                        'continuation_prompt','current_script_dir'))
1233         self\&.stdin = target    
1234         self\&.use_rawinput = False
1235         self\&.prompt = self\&.continuation_prompt = ''
1236         self\&.current_script_dir = os\&.path\&.split(targetname)[0]
1237         stop = self\&._cmdloop()
1238         self\&.stdin\&.close()
1239         keepstate\&.restore()
1240         self\&.lastcmd = ''
        return stop and (stop != self\&._STOP_SCRIPT_NO_EXIT)    
.fi
.SS "def cmd2::Cmd::do_pause (self, arg)"
.PP
Definition at line 1031 of file cmd2\&.py'\&.
.PP
.nf
1031 
1032     def do_pause(self, arg):
1033         'Displays the specified text then waits for the user to press RETURN\&.'
1034         raw_input(arg + '\n')
        
.fi
.SS "def cmd2::Cmd::do_py (self, arg)".PP
.nf

py <command>: Executes a Python command.
py: Enters interactive Python mode.
End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``.
Non-python commands can be issued with ``cmd("your command")``.
Run python code from external files with ``run("filename.py")``
.fi
.PP
 
.PP
Definition at line 1039 of file cmd2\&.py'\&.
.PP
References do_py(), locals_in_py, onecmd_plus_hooks(), cmd2::options(), perror(), pystate, stdin, and stdout\&.
.PP
Referenced by do_py()\&.
.PP
.nf
1039 
1040     def do_py(self, arg):  
1041         '''
1042         py <command>: Executes a Python command\&.
1043         py: Enters interactive Python mode\&.
1044         End with ``Ctrl-D`` (Unix) / ``Ctrl-Z`` (Windows), ``quit()``, '`exit()``\&.
1045         Non-python commands can be issued with ``cmd('your command')``\&.
1046         Run python code from external files with ``run('filename\&.py')``
1047         '''
1048         self\&.pystate['self'] = self
1049         arg = arg\&.parsed\&.raw[2:]\&.strip()
1050         localvars = (self\&.locals_in_py and self\&.pystate) or {}
1051         interp = InteractiveConsole(locals=localvars)
1052         interp\&.runcode('import sys, os;sys\&.path\&.insert(0, os\&.getcwd())')
1053         if arg\&.strip():
1054             interp\&.runcode(arg)
1055         else:
1056             def quit():
1057                 raise EmbeddedConsoleExit
1058             def onecmd_plus_hooks(arg):
1059                 return self\&.onecmd_plus_hooks(arg + '\n')
1060             def run(arg):
1061                 try:
1062                     file = open(arg)
1063                     interp\&.runcode(file\&.read())
1064                     file\&.close()
1065                 except IOError, e:
1066                     self\&.perror(e)
1067             self\&.pystate['quit'] = quit
1068             self\&.pystate['exit'] = quit
1069             self\&.pystate['cmd'] = onecmd_plus_hooks
1070             self\&.pystate['run'] = run
1071             try:
1072                 cprt = 'Type 'help', 'copyright', 'credits' or 'license' for more information\&.'        
1073                 keepstate = Statekeeper(sys, ('stdin','stdout'))
1074                 sys\&.stdout = self\&.stdout
1075                 sys\&.stdin = self\&.stdin
1076                 interp\&.interact(banner= 'Python %s on %s\n%s\n(%s)\n%s' %
1077                        (sys\&.version, sys\&.platform, cprt, self\&.__class__\&.__name__, self\&.do_py\&.__doc__))
1078             except EmbeddedConsoleExit:
1079                 pass
1080             keepstate\&.restore()
            
.fi
.SS "def cmd2::Cmd::do_quit (self, arg)"
.PP
Reimplemented in \fBpirate6::Pirate\fP, \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 941 of file cmd2\&.py'\&.
.PP
References _STOP_AND_EXIT\&.
.PP
.nf
941 
942     def do_quit(self, arg):
        return self\&._STOP_AND_EXIT
.fi
.SS "def cmd2::Cmd::do_run (self, arg)".PP
.nf
run [arg]: re-runs an earlier command

no arg -> run most recent command
arg is integer -> run one history item, by index
arg is string -> run most recent command by string search
arg is /enclosed in forward-slashes/ -> run most recent by regex
.fi
.PP
 
.PP
Definition at line 1243 of file cmd2\&.py'\&.
.PP
References last_matching(), onecmd_plus_hooks(), and pfeedback()\&.
.PP
.nf
1243 
1244     def do_run(self, arg):
1245         '''run [arg]: re-runs an earlier command
1246         
1247         no arg -> run most recent command
1248         arg is integer -> run one history item, by index
1249         arg is string -> run most recent command by string search
1250         arg is /enclosed in forward-slashes/ -> run most recent by regex
1251         '''        
1252         'run [N]: runs the SQL that was run N commands ago'
1253         runme = self\&.last_matching(arg)
1254         self\&.pfeedback(runme)
1255         if runme:
            stop = self\&.onecmd_plus_hooks(runme)
.fi
.SS "def cmd2::Cmd::do_save (self, arg)".PP
.nf
`save [N] [filename.ext]`

Saves command from history to file.

| N => Number of command (from history), or `*`; 
|      most recent command if omitted.fi
.PP
 
.PP
Definition at line 1160 of file cmd2\&.py'\&.
.PP
References default_file_name, do_save(), history, perror(), and pfeedback()\&.
.PP
Referenced by do_save()\&.
.PP
.nf
1160 
1161     def do_save(self, arg):
1162         '''`save [N] [filename\&.ext]`
1163 
1164         Saves command from history to file\&.
1165 
1166         | N => Number of command (from history), or `*`; 
1167         |      most recent command if omitted'''
1168 
1169         try:
1170             args = self\&.saveparser\&.parseString(arg)
1171         except pyparsing\&.ParseException:
1172             self\&.perror('Could not understand save target %s' % arg)
1173             raise SyntaxError(self\&.do_save\&.__doc__)
1174         fname = args\&.fname or self\&.default_file_name
1175         if args\&.idx == '*':
1176             saveme = '\n\n'\&.join(self\&.history[:])
1177         elif args\&.idx:
1178             saveme = self\&.history[int(args\&.idx)-1]
1179         else:
1180             saveme = self\&.history[-1]
1181         try:
1182             f = open(os\&.path\&.expanduser(fname), 'w')
1183             f\&.write(saveme)
1184             f\&.close()
1185             self\&.pfeedback('Saved to %s' % (fname))
1186         except Exception, e:
1187             self\&.perror('Error saving %s' % (fname))
1188             raise
            
.fi
.SS "def cmd2::Cmd::do_set (self, arg)".PP
.nf

Sets a cmd2 parameter.  Accepts abbreviated parameter names so long
as there is no ambiguity.  Call without arguments for a list of 
settable parameters with their values..fi
.PP
 
.PP
Definition at line 1000 of file cmd2\&.py'\&.
.PP
References cmd2::cast(), do_show(), and settable\&.
.PP
.nf
1000 
1001     def do_set(self, arg):
1002         '''
1003         Sets a cmd2 parameter\&.  Accepts abbreviated parameter names so long
1004         as there is no ambiguity\&.  Call without arguments for a list of 
1005         settable parameters with their values\&.'''
1006         try:
1007             statement, paramName, val = arg\&.parsed\&.raw\&.split(None, 2)
1008             val = val\&.strip()
1009             paramName = paramName\&.strip()\&.lower()
1010             if paramName not in self\&.settable:
1011                 hits = [p for p in self\&.settable if p\&.startswith(paramName)]
1012                 if len(hits) == 1:
1013                     paramName = hits[0]
1014                 else:
1015                     return self\&.do_show(paramName)
1016             currentVal = getattr(self, paramName)
1017             if (val[0] == val[-1]) and val[0] in (''', '''):
1018                 val = val[1:-1]
1019             else:                
1020                 val = cast(currentVal, val)
1021             setattr(self, paramName, val)
1022             self\&.stdout\&.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val))
1023             if currentVal != val:
1024                 try:
1025                     onchange_hook = getattr(self, '_onchange_%s' % paramName)
1026                     onchange_hook(old=currentVal, new=val)
1027                 except AttributeError:
1028                     pass
1029         except (ValueError, AttributeError, NotSettableError), e:
1030             self\&.do_show(arg)
                
.fi
.SS "def cmd2::Cmd::do_shell (self, arg)"
.PP
Definition at line 1035 of file cmd2\&.py'\&.
.PP
.nf
1035 
1036     def do_shell(self, arg):
1037         'execute a command as if at the OS prompt\&.'
1038         os\&.system(arg)
                
.fi
.SS "def cmd2::Cmd::do_shortcuts (self, args)".PP
.nf
Lists single-key shortcuts available..fi
.PP
 
.PP
Definition at line 479 of file cmd2\&.py'\&.
.PP
References shortcuts\&.
.PP
.nf
479 
480     def do_shortcuts(self, args):
481         '''Lists single-key shortcuts available\&.'''
482         result = '\n'\&.join('%s: %s' % (sc[0], sc[1]) for sc in sorted(self\&.shortcuts))
483         self\&.stdout\&.write('Single-key shortcuts for other commands:\n%s\n' % (result))

.fi
.SS "def cmd2::Cmd::do_show (self, arg, opts)".PP
.nf
Shows value of a parameter..fi
.PP
 
.PP
Definition at line 982 of file cmd2\&.py'\&.
.PP
References cmd2::ljust(), poutput(), and settable\&.
.PP
Referenced by do_set()\&.
.PP
.nf
982 
983     def do_show(self, arg, opts):
984         '''Shows value of a parameter\&.'''
985         param = arg\&.strip()\&.lower()
986         result = {}
987         maxlen = 0
988         for p in self\&.settable:
989             if (not param) or p\&.startswith(param):
990                 result[p] = '%s: %s' % (p, str(getattr(self, p)))
991                 maxlen = max(maxlen, len(result[p]))
992         if result:
993             for p in sorted(result):
994                 if opts\&.long:
995                     self\&.poutput('%s # %s' % (result[p]\&.ljust(maxlen), self\&.settable[p]))
996                 else:
997                     self\&.poutput(result[p])
998         else:
999             raise NotImplementedError('Parameter '%s' not supported (type 'show' for list of parameters)\&.' % param)
    
.fi
.SS "def cmd2::Cmd::fileimport (self, statement, source)"
.PP
Definition at line 1258 of file cmd2\&.py'\&.
.PP
.nf
1258 
1259     def fileimport(self, statement, source):
1260         try:
1261             f = open(os\&.path\&.expanduser(source))
1262         except IOError:
1263             self\&.stdout\&.write('Couldn't read from file %s\n' % source)
1264             return ''
1265         data = f\&.read()
1266         f\&.close()
1267         return data

.fi
.SS "def cmd2::Cmd::func_named (self, arg)"
.PP
Definition at line 755 of file cmd2\&.py'\&.
.PP
References abbrev, and keywords\&.
.PP
Referenced by do_help()\&.
.PP
.nf
755 
756     def func_named(self, arg):
757         result = None
758         target = 'do_' + arg
759         if target in dir(self):
760             result = target
761         else:
762             if self\&.abbrev:   # accept shortened versions of commands
763                 funcs = [fname for fname in self\&.keywords if fname\&.startswith(arg)]
764                 if len(funcs) == 1:
765                     result = 'do_' + funcs[0]
        return result
.fi
.SS "def cmd2::Cmd::last_matching (self, arg)"
.PP
Definition at line 1100 of file cmd2\&.py'\&.
.PP
References history\&.
.PP
Referenced by do_ed(), and do_run()\&.
.PP
.nf
1100 
1101     def last_matching(self, arg):
1102         try:
1103             if arg:
1104                 return self\&.history\&.get(arg)[-1]
1105             else:
1106                 return self\&.history[-1]
1107         except IndexError:
            return None        
.fi
.SS "def cmd2::Cmd::onecmd (self, line)".PP
.nf
Interpret the argument as though it had been typed in response
to the prompt.

This may be overridden, but should not normally need to be;
see the precmd() and postcmd() methods for useful execution hooks.
The return value is a flag indicating whether interpretation of
commands by the interpreter should stop.

This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`.

.fi
.PP
 
.PP
Definition at line 844 of file cmd2\&.py'\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.PP
.nf
844 
845     def onecmd(self, line):
846         '''Interpret the argument as though it had been typed in response
847         to the prompt\&.
848 
849         This may be overridden, but should not normally need to be;
850         see the precmd() and postcmd() methods for useful execution hooks\&.
851         The return value is a flag indicating whether interpretation of
852         commands by the interpreter should stop\&.
853         
854         This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`\&.
855 
856         '''
857         statement = self\&.parsed(line)
858         self\&.lastcmd = statement\&.parsed\&.raw   
859         funcname = self\&.func_named(statement\&.parsed\&.command)
860         if not funcname:
861             return self\&._default(statement)
862         try:
863             func = getattr(self, funcname)
864         except AttributeError:
865             return self\&._default(statement)
866         stop = func(statement) 
867         return stop                
        
.fi
.SS "def cmd2::Cmd::onecmd_plus_hooks (self, line)"
.PP
Definition at line 766 of file cmd2\&.py'\&.
.PP
References complete_statement(), excludeFromHistory, onecmd(), perror(), pfeedback(), pirate3::Pirate::postcmd(), pirate4::Pirate::postcmd(), pirate5::Pirate::postcmd(), pirate7::Pirate::postcmd(), pirate8::Pirate::postcmd(), pirate6::Pirate::postcmd(), postparsing_postcmd(), postparsing_precmd(), pirate3::Pirate::precmd(), pirate4::Pirate::precmd(), pirate5::Pirate::precmd(), pirate7::Pirate::precmd(), pirate8::Pirate::precmd(), pirate6::Pirate::precmd(), redirect_output(), restore_output(), and timing\&.
.PP
Referenced by do_py(), do_run(), and run_commands_at_invocation()\&.
.PP
.nf
766 
767     def onecmd_plus_hooks(self, line):
768         # The outermost level of try/finally nesting can be condensed once
769         # Python 2\&.4 support can be dropped\&.
770         stop = 0
771         try:
772             try:
773                 statement = self\&.complete_statement(line)
774                 (stop, statement) = self\&.postparsing_precmd(statement)
775                 if stop:
776                     return self\&.postparsing_postcmd(stop)
777                 if statement\&.parsed\&.command not in self\&.excludeFromHistory:
778                     self\&.history\&.append(statement\&.parsed\&.raw)      
779                 try:
780                     self\&.redirect_output(statement)
781                     timestart = datetime\&.datetime\&.now()
782                     statement = self\&.precmd(statement)
783                     stop = self\&.onecmd(statement)
784                     stop = self\&.postcmd(stop, statement)
785                     if self\&.timing:
786                         self\&.pfeedback('Elapsed: %s' % str(datetime\&.datetime\&.now() - timestart))
787                 finally:
788                     self\&.restore_output(statement)
789             except EmptyStatement:
790                 return 0
791             except Exception, e:
792                 self\&.perror(str(e), statement)            
793         finally:
            return self\&.postparsing_postcmd(stop)        
.fi
.SS "def cmd2::Cmd::parsed (self, raw, kwargs)"
.PP
Definition at line 726 of file cmd2\&.py'\&.
.PP
References parsed(), postparse(), preparse(), and shortcuts\&.
.PP
Referenced by complete_statement(), cmd2::ParsedString::full_parsed_statement(), parsed(), and cmd2::ParsedString::with_args_replaced()\&.
.PP
.nf
726 
727     def parsed(self, raw, **kwargs):
728         if isinstance(raw, ParsedString):
729             p = raw
730         else:
731             # preparse is an overridable hook; default makes no changes
732             s = self\&.preparse(raw, **kwargs)
733             s = self\&.inputParser\&.transformString(s\&.lstrip())
734             s = self\&.commentGrammars\&.transformString(s)
735             for (shortcut, expansion) in self\&.shortcuts:
736                 if s\&.lower()\&.startswith(shortcut):
737                     s = s\&.replace(shortcut, expansion + ' ', 1)
738                     break
739             result = self\&.parser\&.parseString(s)
740             result['raw'] = raw            
741             result['command'] = result\&.multilineCommand or result\&.command        
742             result = self\&.postparse(result)
743             p = ParsedString(result\&.args)
744             p\&.parsed = result
745             p\&.parser = self\&.parsed
746         for (key, val) in kwargs\&.items():
747             p\&.parsed[key] = val
748         return p
              
.fi
.SS "def cmd2::Cmd::perror (self, errmsg, statement = \fCNone\fP)"
.PP
Definition at line 404 of file cmd2\&.py'\&.
.PP
References debug\&.
.PP
Referenced by do_py(), do_save(), and onecmd_plus_hooks()\&.
.PP
.nf
404 
405     def perror(self, errmsg, statement=None):
406         if self\&.debug:
407             traceback\&.print_exc()
        print (str(errmsg))
.fi
.SS "def cmd2::Cmd::pfeedback (self, msg)".PP
.nf
For printing nonessential feedback.  Can be silenced with `quiet`.
   Inclusion in redirected output is controlled by `feedback_to_output`..fi
.PP
 
.PP
Definition at line 408 of file cmd2\&.py'\&.
.PP
References feedback_to_output, poutput(), and quiet\&.
.PP
Referenced by do_run(), do_save(), and onecmd_plus_hooks()\&.
.PP
.nf
408 
409     def pfeedback(self, msg):
410         '''For printing nonessential feedback\&.  Can be silenced with `quiet`\&.
411            Inclusion in redirected output is controlled by `feedback_to_output`\&.'''
412         if not self\&.quiet:
413             if self\&.feedback_to_output:
414                 self\&.poutput(msg)
415             else:
                print (msg)
.fi
.SS "def cmd2::Cmd::postparse (self, parseResult)"
.PP
Definition at line 723 of file cmd2\&.py'\&.
.PP
Referenced by parsed()\&.
.PP
.nf
723 
724     def postparse(self, parseResult):
725         return parseResult
   
.fi
.SS "def cmd2::Cmd::postparsing_postcmd (self, stop)"
.PP
Definition at line 752 of file cmd2\&.py'\&.
.PP
Referenced by _default(), and onecmd_plus_hooks()\&.
.PP
.nf
752 
753     def postparsing_postcmd(self, stop):
754         return stop
    
.fi
.SS "def cmd2::Cmd::postparsing_precmd (self, statement)"
.PP
Definition at line 749 of file cmd2\&.py'\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.PP
.nf
749 
750     def postparsing_precmd(self, statement):
751         stop = 0
        return stop, statement
.fi
.SS "def cmd2::Cmd::poutput (self, msg)".PP
.nf
Convenient shortcut for self.stdout.write(); adds newline if necessary..fi
.PP
 
.PP
Definition at line 398 of file cmd2\&.py'\&.
.PP
Referenced by do_history(), do_list(), do_show(), pfeedback(), and select()\&.
.PP
.nf
398 
399     def poutput(self, msg):
400         '''Convenient shortcut for self\&.stdout\&.write(); adds newline if necessary\&.'''
401         if msg:
402             self\&.stdout\&.write(msg)
403             if msg[-1] != '\n':
                self\&.stdout\&.write('\n')
.fi
.SS "def cmd2::Cmd::preparse (self, raw, kwargs)"
.PP
Definition at line 721 of file cmd2\&.py'\&.
.PP
Referenced by parsed()\&.
.PP
.nf
721 
722     def preparse(self, raw, **kwargs):
        return raw
.fi
.SS "def cmd2::Cmd::pseudo_raw_input (self, prompt)".PP
.nf
copied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdout.fi
.PP
 
.PP
Definition at line 876 of file cmd2\&.py'\&.
.PP
References use_rawinput\&.
.PP
Referenced by complete_statement()\&.
.PP
.nf
876 
877     def pseudo_raw_input(self, prompt):
878         '''copied from cmd's cmdloop; like raw_input, but accounts for changed stdin, stdout'''
879         
880         if self\&.use_rawinput:
881             try:
882                 line = raw_input(prompt)
883             except EOFError:
884                 line = 'EOF'
885         else:
886             self\&.stdout\&.write(prompt)
887             self\&.stdout\&.flush()
888             line = self\&.stdin\&.readline()
889             if not len(line):
890                 line = 'EOF'
891             else:
892                 if line[-1] == '\n': # this was always true in Cmd
893                     line = line[:-1] 
894         return line
    
.fi
.SS "def cmd2::Cmd::read_file_or_url (self, fname)"
.PP
Definition at line 1189 of file cmd2\&.py'\&.
.PP
References defaultExtension\&.
.PP
.nf
1189 
1190     def read_file_or_url(self, fname):
1191         # TODO: not working on localhost
1192         if isinstance(fname, file):
1193             result = open(fname, 'r')
1194         else:
1195             match = self\&.urlre\&.match(fname)
1196             if match:
1197                 result = urllib\&.urlopen(match\&.group(1))
1198             else:
1199                 fname = os\&.path\&.expanduser(fname)
1200                 try:
1201                     result = open(os\&.path\&.expanduser(fname), 'r')
1202                 except IOError:                    
1203                     result = open('%s\&.%s' % (os\&.path\&.expanduser(fname), 
1204                                              self\&.defaultExtension), 'r')
1205         return result
        
.fi
.SS "def cmd2::Cmd::redirect_output (self, statement)"
.PP
Definition at line 809 of file cmd2\&.py'\&.
.PP
References cmd2::get_paste_buffer(), kept_state, kept_sys, redirect, redirector, and stdout\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.PP
.nf
809 
810     def redirect_output(self, statement):
811         if statement\&.parsed\&.pipeTo:
812             self\&.kept_state = Statekeeper(self, ('stdout',))
813             self\&.kept_sys = Statekeeper(sys, ('stdout',))
814             self\&.redirect = subprocess\&.Popen(statement\&.parsed\&.pipeTo, shell=True, stdout=subprocess\&.PIPE, stdin=subprocess\&.PIPE)
815             sys\&.stdout = self\&.stdout = self\&.redirect\&.stdin
816         elif statement\&.parsed\&.output:
817             if (not statement\&.parsed\&.outputTo) and (not can_clip):
818                 raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable')
819             self\&.kept_state = Statekeeper(self, ('stdout',))            
820             self\&.kept_sys = Statekeeper(sys, ('stdout',))
821             if statement\&.parsed\&.outputTo:
822                 mode = 'w'
823                 if statement\&.parsed\&.output == 2 * self\&.redirector:
824                     mode = 'a'
825                 sys\&.stdout = self\&.stdout = open(os\&.path\&.expanduser(statement\&.parsed\&.outputTo), mode)                            
826             else:
827                 sys\&.stdout = self\&.stdout = tempfile\&.TemporaryFile(mode='w+')
828                 if statement\&.parsed\&.output == '>>':
829                     self\&.stdout\&.write(get_paste_buffer())
                    
.fi
.SS "def cmd2::Cmd::restore_output (self, statement)"
.PP
Definition at line 830 of file cmd2\&.py'\&.
.PP
References kept_state, and cmd2::write_to_paste_buffer\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.PP
.nf
830 
831     def restore_output(self, statement):
832         if self\&.kept_state:
833             if statement\&.parsed\&.output:
834                 if not statement\&.parsed\&.outputTo:
835                     self\&.stdout\&.seek(0)
836                     write_to_paste_buffer(self\&.stdout\&.read())
837             elif statement\&.parsed\&.pipeTo:
838                 for result in self\&.redirect\&.communicate():              
839                     self\&.kept_state\&.stdout\&.write(result or '')                        
840             self\&.stdout\&.close()
841             self\&.kept_state\&.restore()  
842             self\&.kept_sys\&.restore()
843             self\&.kept_state = None                        
                        
.fi
.SS "def cmd2::Cmd::run_commands_at_invocation (self, callargs)"
.PP
Definition at line 1278 of file cmd2\&.py'\&.
.PP
References _STOP_AND_EXIT, and onecmd_plus_hooks()\&.
.PP
Referenced by cmdloop()\&.
.PP
.nf
1278 
1279     def run_commands_at_invocation(self, callargs):
1280         for initial_command in callargs:
1281             if self\&.onecmd_plus_hooks(initial_command + '\n'):
1282                 return self\&._STOP_AND_EXIT

.fi
.SS "def cmd2::Cmd::runTranscriptTests (self, callargs)"
.PP
Definition at line 1268 of file cmd2\&.py'\&.
.PP
Referenced by cmdloop()\&.
.PP
.nf
1268 
1269     def runTranscriptTests(self, callargs):
1270         class TestMyAppCase(Cmd2TestCase):
1271             CmdApp = self\&.__class__        
1272         self\&.__class__\&.testfiles = callargs
1273         sys\&.argv = [sys\&.argv[0]] # the --test argument upsets unittest\&.main()
1274         testcase = TestMyAppCase()
1275         runner = unittest\&.TextTestRunner()
1276         result = runner\&.run(testcase)
1277         result\&.printErrors()

.fi
.SS "def cmd2::Cmd::select (self, options, prompt = \fC'Your choice? '\fP)".PP
.nf
Presents a numbered menu to the user.  Modelled after
   the bash shell's SELECT.  Returns the item chosen.
   
   Argument ``options`` can be:

     | a single string -> will be split into one-word options
     | a list of strings -> will be offered as options
     | a list of tuples -> interpreted as (value, text), so 
                   that the return value can differ from
                   the text advertised to the user .fi
.PP
 
.PP
Definition at line 946 of file cmd2\&.py'\&.
.PP
References cmd2::options(), and poutput()\&.
.PP
.nf
946 
947     def select(self, options, prompt='Your choice? '):
948         '''Presents a numbered menu to the user\&.  Modelled after
949            the bash shell's SELECT\&.  Returns the item chosen\&.
950            
951            Argument ``options`` can be:
952 
953              | a single string -> will be split into one-word options
954              | a list of strings -> will be offered as options
955              | a list of tuples -> interpreted as (value, text), so 
956                                    that the return value can differ from
957                                    the text advertised to the user '''
958         if isinstance(options, basestring):
959             options = zip(options\&.split(), options\&.split())
960         fulloptions = []
961         for opt in options:
962             if isinstance(opt, basestring):
963                 fulloptions\&.append((opt, opt))
964             else:
965                 try:
966                     fulloptions\&.append((opt[0], opt[1]))
967                 except IndexError:
968                     fulloptions\&.append((opt[0], opt[0]))
969         for (idx, (value, text)) in enumerate(fulloptions):
970             self\&.poutput('  %2d\&. %s\n' % (idx+1, text))
971         while True:
972             response = raw_input(prompt)
973             try:
974                 response = int(response)
975                 result = fulloptions[response - 1][0]
976                 break
977             except ValueError:
978                 pass # loop and ask again
979         return result
    
.fi
.SH "Member Data Documentation"
.PP 
.SS "\fBcmd2::Cmd::_STOP_AND_EXIT\fP = True\fC [static, private]\fP"
.PP
Definition at line 416 of file cmd2\&.py'\&.
.PP
Referenced by do_quit(), and run_commands_at_invocation()\&.
.SS "int \fBcmd2::Cmd::_STOP_SCRIPT_NO_EXIT\fP = 999\fC [static, private]\fP"
.PP
Definition at line 417 of file cmd2\&.py'\&.
.PP
Referenced by do_EOF()\&.
.SS "\fBcmd2::Cmd::abbrev\fP = True\fC [static]\fP"
.PP
Definition at line 374 of file cmd2\&.py'\&.
.PP
Referenced by func_named()\&.
.SS "\fBcmd2::Cmd::blankLinesAllowed\fP = False\fC [static]\fP"
.PP
Definition at line 490 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::blankLineTerminationParser\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::blankLineTerminator\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::case_insensitive\fP = True\fC [static]\fP"
.PP
Definition at line 363 of file cmd2\&.py'\&.
.PP
Referenced by do_cmdenvironment()\&.
.SS "dictionary \fBcmd2::Cmd::colorcodes\fP\fC [static]\fP"\fBInitial value:\fP
.PP
.nf
{'bold':{True:'\x1b[1m',False:'\x1b[22m'},
                  'cyan':{True:'\x1b[36m',False:'\x1b[39m'},
                  'blue':{True:'\x1b[34m',False:'\x1b[39m'},
                  'red':{True:'\x1b[31m',False:'\x1b[39m'},
                  'magenta':{True:'\x1b[35m',False:'\x1b[39m'},
                  'green':{True:'\x1b[32m',False:'\x1b[39m'},
                  'underline':{True:'\x1b[4m',False:'\x1b[24m'}}
.fi
.PP
Definition at line 427 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::Cmd::colors\fP = (platform\&.system() != 'Windows')\fC [static]\fP"
.PP
Definition at line 434 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::Cmd::commentGrammars\fP = pyparsing\&.Or([pyparsing\&.pythonStyleComment, pyparsing\&.cStyleComment])\fC [static]\fP"
.PP
Definition at line 485 of file cmd2\&.py'\&.
.PP
Referenced by complete_statement()\&.
.SS "tuple \fBcmd2::Cmd::commentInProgress\fP = pyparsing\&.Literal('/*')\fC [static]\fP"
.PP
Definition at line 487 of file cmd2\&.py'\&.
.SS "string \fBcmd2::Cmd::continuation_prompt\fP = '> '\fC [static]\fP"
.PP
Definition at line 364 of file cmd2\&.py'\&.
.PP
Referenced by complete_statement()\&.
.SS "\fBcmd2::Cmd::continuation_prompt\fP"
.PP
Definition at line 1218 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::current_script_dir\fP = None\fC [static]\fP"
.PP
Definition at line 375 of file cmd2\&.py'\&.
.PP
Referenced by do__relative_load()\&.
.SS "\fBcmd2::Cmd::debug\fP = False\fC [static]\fP"
.PP
Definition at line 379 of file cmd2\&.py'\&.
.PP
Referenced by perror()\&.
.SS "string \fBcmd2::Cmd::default_file_name\fP = 'command\&.txt'\fC [static]\fP"
.PP
Definition at line 373 of file cmd2\&.py'\&.
.PP
Referenced by do_ed(), and do_save()\&.
.SS "\fBcmd2::Cmd::default_to_shell\fP = False\fC [static]\fP"
.PP
Reimplemented in \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 370 of file cmd2\&.py'\&.
.PP
Referenced by _default()\&.
.SS "string \fBcmd2::Cmd::defaultExtension\fP = 'txt'\fC [static]\fP"
.PP
Definition at line 372 of file cmd2\&.py'\&.
.PP
Referenced by read_file_or_url()\&.
.SS "\fBcmd2::Cmd::do__load\fP = do_load\fC [static]\fP"
.PP
Definition at line 1241 of file cmd2\&.py'\&.
.PP
Referenced by do__relative_load(), and do_ed()\&.
.SS "\fBcmd2::Cmd::do_edit\fP = do_ed\fC [static]\fP"
.PP
Definition at line 1155 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_eof\fP = do_EOF\fC [static]\fP"
.PP
Definition at line 939 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_exit\fP = do_quit\fC [static]\fP"
.PP
Definition at line 943 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_hi\fP = do_history\fC [static]\fP"
.PP
Definition at line 1124 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_l\fP = do_list\fC [static]\fP"
.PP
Definition at line 1125 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_li\fP = do_list\fC [static]\fP"
.PP
Definition at line 1126 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_q\fP = do_quit\fC [static]\fP"
.PP
Definition at line 944 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::do_r\fP = do_run\fC [static]\fP"
.PP
Definition at line 1256 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::echo\fP = False\fC [static]\fP"
.PP
Definition at line 362 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::Cmd::editor\fP = os\&.environ\&.get('EDITOR')\fC [static]\fP"
.PP
Definition at line 418 of file cmd2\&.py'\&.
.PP
Referenced by do_ed()\&.
.SS "string \fBcmd2::Cmd::editor\fP = 'notepad'\fC [static]\fP"
.PP
Definition at line 421 of file cmd2\&.py'\&.
.SS "string \fBcmd2::Cmd::excludeFromHistory\fP = '''run r list l \fBhistory\fP hi ed edit li eof'''\fC [static]\fP"
.PP
Definition at line 369 of file cmd2\&.py'\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.SS "\fBcmd2::Cmd::feedback_to_output\fP = False\fC [static]\fP"
.PP
Definition at line 377 of file cmd2\&.py'\&.
.PP
Referenced by pfeedback()\&.
.SS "string \fBcmd2::Cmd::help\fP = 'describe function of parameter'\fC [static]\fP"
.PP
Reimplemented in \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 981 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::history\fP"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.PP
Referenced by do_ed(), do_history(), do_save(), and last_matching()\&.
.SS "\fBcmd2::Cmd::initial_stdout\fP"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::inputParser\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::intro\fP"
.PP
Definition at line 898 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::kept_state\fP = None\fC [static]\fP"
.PP
Definition at line 381 of file cmd2\&.py'\&.
.PP
Referenced by redirect_output(), and restore_output()\&.
.SS "\fBcmd2::Cmd::kept_sys\fP"
.PP
Definition at line 809 of file cmd2\&.py'\&.
.PP
Referenced by redirect_output()\&.
.SS "\fBcmd2::Cmd::keywords\fP"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.PP
Referenced by func_named()\&.
.SS "\fBcmd2::Cmd::lastcmd\fP"
.PP
Definition at line 854 of file cmd2\&.py'\&.
.SS "string \fBcmd2::Cmd::legalChars\fP = u'!#$%\&.:?@_'\fC [static]\fP"
.PP
Definition at line 367 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::locals_in_py\fP = True\fC [static]\fP"
.PP
Definition at line 380 of file cmd2\&.py'\&.
.PP
Referenced by do_py()\&.
.SS "\fBcmd2::Cmd::multilineCommand\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "list \fBcmd2::Cmd::multilineCommands\fP = []\fC [static]\fP"
.PP
Reimplemented in \fBpirate7::Pirate\fP, \fBpirate8::Pirate\fP, and \fBexample::CmdLineApp\fP'\&.
.PP
Definition at line 491 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::multilineParser\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "string \fBcmd2::Cmd::noSpecialParse\fP = 'set ed edit exit'\fC [static]\fP"
.PP
Definition at line 371 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::old_completer\fP"
.PP
Definition at line 898 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::parser\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.PP
Referenced by cmd2::ParsedString::full_parsed_statement(), and cmd2::ParsedString::with_args_replaced()\&.
.SS "tuple \fBcmd2::Cmd::prefixParser\fP = pyparsing\&.Empty()\fC [static]\fP"
.PP
Definition at line 484 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::prompt\fP"
.PP
Reimplemented in \fBpirate6::Pirate\fP, \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 1218 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::pystate\fP"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.PP
Referenced by do_py()\&.
.SS "\fBcmd2::Cmd::quiet\fP = False\fC [static]\fP"
.PP
Definition at line 378 of file cmd2\&.py'\&.
.PP
Referenced by pfeedback()\&.
.SS "\fBcmd2::Cmd::redirect\fP"
.PP
Definition at line 809 of file cmd2\&.py'\&.
.PP
Referenced by redirect_output()\&.
.SS "string \fBcmd2::Cmd::redirector\fP = '>'\fC [static]\fP"
.PP
Reimplemented in \fBexample::CmdLineApp\fP'\&.
.PP
Definition at line 382 of file cmd2\&.py'\&.
.PP
Referenced by redirect_output()\&.
.SS "list \fBcmd2::Cmd::reserved_words\fP = []\fC [static]\fP"
.PP
Definition at line 376 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::Cmd::saveparser\fP\fC [static]\fP"\fBInitial value:\fP
.PP
.nf
(pyparsing\&.Optional(pyparsing\&.Word(pyparsing\&.nums)^'*')('idx') + 
                  pyparsing\&.Optional(pyparsing\&.Word(legalChars + '/\\'))('fname') +
                  pyparsing\&.stringEnd)
.fi
.PP
Definition at line 1157 of file cmd2\&.py'\&.
.SS "tuple \fBcmd2::Cmd::settable\fP\fC [static]\fP"\fBInitial value:\fP
.PP
.nf
stubbornDict('''
    prompt
    colors                Colorized output (*nix only)
    continuation_prompt   On 2nd+ line of input
    debug                 Show full error stack on error
    default_file_name     for ``save``, ``load``, etc\&.
    editor                Program used by ``edit``      
    case_insensitive      upper- and lower-case both OK
    feedback_to_output    include nonessentials in `|`, `>` results 
    quiet                 Don't print nonessential feedback
    echo                  Echo command issued into output
    timing                Report execution times
    abbrev                Accept abbreviated commands
    ''')
.fi
.PP
Reimplemented in \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 383 of file cmd2\&.py'\&.
.PP
Referenced by do_cmdenvironment(), do_set(), and do_show()\&.
.SS "dictionary \fBcmd2::Cmd::shortcuts\fP = {'?': '\fBhelp\fP', '!': 'shell', '@': 'load', '@@': '_relative_load'}\fC [static]\fP"
.PP
Definition at line 368 of file cmd2\&.py'\&.
.PP
Referenced by do_shortcuts(), and parsed()\&.
.SS "\fBcmd2::Cmd::shortcuts\fP"
.PP
Definition at line 469 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::singleLineParser\fP"
.PP
Definition at line 667 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::stdin\fP"
.PP
Definition at line 1218 of file cmd2\&.py'\&.
.PP
Referenced by do_py()\&.
.SS "\fBcmd2::Cmd::stdout\fP"
.PP
Definition at line 440 of file cmd2\&.py'\&.
.PP
Referenced by do_help(), do_py(), and redirect_output()\&.
.SS "list \fBcmd2::Cmd::terminators\fP = [';']\fC [static]\fP"
.PP
Reimplemented in \fBpirate7::Pirate\fP, and \fBpirate8::Pirate\fP'\&.
.PP
Definition at line 489 of file cmd2\&.py'\&.
.PP
Referenced by do_cmdenvironment()\&.
.SS "\fBcmd2::Cmd::timing\fP = False\fC [static]\fP"
.PP
Definition at line 365 of file cmd2\&.py'\&.
.PP
Referenced by onecmd_plus_hooks()\&.
.SS "tuple \fBcmd2::Cmd::urlre\fP = re\&.compile('(https?://[-\\\\w\\\\\&./]+)')\fC [static]\fP"
.PP
Definition at line 1217 of file cmd2\&.py'\&.
.SS "\fBcmd2::Cmd::use_rawinput\fP"
.PP
Definition at line 1218 of file cmd2\&.py'\&.
.PP
Referenced by pseudo_raw_input()\&.

.SH "Author"
.PP 
Generated automatically by Doxygen for Cmd2 from the source code'\&.