Skip to content

Commit f594dc2

Browse files
committed
Fixed a couple case sensitivity bugs and added an example
Bugs fixed: - Case-sensitive parsing was completely broken, this has been fixed - <Ctrl>+D to quit wasn't working when case-sensitive parsing was enabled, this is fixed Added a "case_sensitive.py" example in the examples directory for quickly testing case-sensitive command parsing behavior.
1 parent f517ff8 commit f594dc2

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

cmd2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,13 @@ def pseudo_raw_input(self, prompt):
891891
try:
892892
line = sm.input(safe_prompt)
893893
except EOFError:
894-
line = 'EOF'
894+
line = 'eof'
895895
else:
896896
self.stdout.write(safe_prompt)
897897
self.stdout.flush()
898898
line = self.stdin.readline()
899899
if not len(line):
900-
line = 'EOF'
900+
line = 'eof'
901901
else:
902902
line = line.rstrip('\r\n')
903903

@@ -1846,6 +1846,10 @@ def _build_main_parser(self, redirector, terminators, multilineCommands, legalCh
18461846
if case_insensitive:
18471847
multilineCommand.setParseAction(lambda x: x[0].lower())
18481848
oneline_command.setParseAction(lambda x: x[0].lower())
1849+
else:
1850+
multilineCommand.setParseAction(lambda x: x[0])
1851+
oneline_command.setParseAction(lambda x: x[0])
1852+
18491853
if blankLinesAllowed:
18501854
blankLineTerminationParser = pyparsing.NoMatch
18511855
else:

examples/case_sensitive.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
"""A sample application demonstrating when commands are set to be case sensitive.
4+
5+
By default cmd2 parses commands in a case-insensitive manner. But this behavior can be changed.
6+
"""
7+
8+
import cmd2
9+
10+
11+
class CaseSensitiveApp(cmd2.Cmd):
12+
""" Example cmd2 application where commands are case-sensitive."""
13+
14+
def __init__(self):
15+
# Set this before calling the super class __init__()
16+
self.case_insensitive = False
17+
18+
cmd2.Cmd.__init__(self)
19+
20+
self.debug = True
21+
22+
23+
if __name__ == '__main__':
24+
app = CaseSensitiveApp()
25+
app.cmdloop()

0 commit comments

Comments
 (0)