55To use, simply import cmd2.Cmd instead of cmd.Cmd; use precisely as though you
66were using the standard library's cmd, while enjoying the extra features.
77
8- Searchable command history (commands: "history", "list", "run" )
8+ Searchable command history (commands: "history")
99Load commands from file, save to file, edit commands in file
1010Multi-line commands
11- Case-insensitive commands
1211Special-character shortcut commands (beyond cmd's "@" and "!")
1312Settable environment parameters
14- Optional _onchange_{paramname} called when environment parameter changes
15- Parsing commands with `optparse` options (flags)
13+ Parsing commands with `argparse` argument parsers (flags)
1614Redirection to file with >, >>; input from file with <
1715Easy transcript-based testing of applications (see examples/example.py)
1816Bash-style ``select`` available
@@ -991,7 +989,6 @@ class Cmd(cmd.Cmd):
991989 """
992990 # Attributes used to configure the ParserManager (all are not dynamically settable at runtime)
993991 blankLinesAllowed = False
994- case_insensitive = True # Commands recognized regardless of case
995992 commentGrammars = pyparsing .Or ([pyparsing .pythonStyleComment , pyparsing .cStyleComment ])
996993 commentInProgress = pyparsing .Literal ('/*' ) + pyparsing .SkipTo (pyparsing .stringEnd ^ '*/' )
997994 legalChars = u'!#$%.:?@_-' + pyparsing .alphanums + pyparsing .alphas8bit
@@ -1086,7 +1083,6 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
10861083 multilineCommands = self .multilineCommands ,
10871084 legalChars = self .legalChars , commentGrammars = self .commentGrammars ,
10881085 commentInProgress = self .commentInProgress ,
1089- case_insensitive = self .case_insensitive ,
10901086 blankLinesAllowed = self .blankLinesAllowed , prefixParser = self .prefixParser ,
10911087 preparse = self .preparse , postparse = self .postparse , shortcuts = self .shortcuts )
10921088 self ._transcript_files = transcript_files
@@ -1216,12 +1212,8 @@ def colorize(self, val, color):
12161212 # noinspection PyMethodOverriding
12171213 def completenames (self , text , line , begidx , endidx ):
12181214 """Override of cmd method which completes command names both for command completion and help."""
1219- command = text
1220- if self .case_insensitive :
1221- command = text .lower ()
1222-
12231215 # Call super class method. Need to do it this way for Python 2 and 3 compatibility
1224- cmd_completion = cmd .Cmd .completenames (self , command )
1216+ cmd_completion = cmd .Cmd .completenames (self , text )
12251217
12261218 # If we are completing the initial command name and get exactly 1 result and are at end of line, add a space
12271219 if begidx == 0 and len (cmd_completion ) == 1 and endidx == len (line ):
@@ -1954,15 +1946,14 @@ def cmdenvironment(self):
19541946 :return: str - summary report of read-only settings which the user cannot modify at runtime
19551947 """
19561948 read_only_settings = """
1957- Commands are case-sensitive: {}
19581949 Commands may be terminated with: {}
19591950 Arguments at invocation allowed: {}
19601951 Output redirection and pipes allowed: {}
19611952 Parsing of @options commands:
19621953 Shell lexer mode for command argument splitting: {}
19631954 Strip Quotes after splitting arguments: {}
19641955 Argument type: {}
1965- """ .format (not self . case_insensitive , str (self .terminators ), self .allow_cli_args , self .allow_redirection ,
1956+ """ .format (str (self .terminators ), self .allow_cli_args , self .allow_redirection ,
19661957 "POSIX" if POSIX_SHLEX else "non-POSIX" ,
19671958 "True" if STRIP_QUOTES_FOR_NON_POSIX and not POSIX_SHLEX else "False" ,
19681959 "List of argument strings" if USE_ARG_LIST else "string of space-separated arguments" )
@@ -2575,7 +2566,7 @@ class ParserManager:
25752566 Class which encapsulates all of the pyparsing parser functionality for cmd2 in a single location.
25762567 """
25772568 def __init__ (self , redirector , terminators , multilineCommands , legalChars , commentGrammars , commentInProgress ,
2578- case_insensitive , blankLinesAllowed , prefixParser , preparse , postparse , shortcuts ):
2569+ blankLinesAllowed , prefixParser , preparse , postparse , shortcuts ):
25792570 """Creates and uses parsers for user input according to app's parameters."""
25802571
25812572 self .commentGrammars = commentGrammars
@@ -2586,13 +2577,12 @@ def __init__(self, redirector, terminators, multilineCommands, legalChars, comme
25862577 self .main_parser = self ._build_main_parser (redirector = redirector , terminators = terminators ,
25872578 multilineCommands = multilineCommands , legalChars = legalChars ,
25882579 commentInProgress = commentInProgress ,
2589- case_insensitive = case_insensitive ,
25902580 blankLinesAllowed = blankLinesAllowed , prefixParser = prefixParser )
25912581 self .input_source_parser = self ._build_input_source_parser (legalChars = legalChars ,
25922582 commentInProgress = commentInProgress )
25932583
2594- def _build_main_parser (self , redirector , terminators , multilineCommands , legalChars ,
2595- commentInProgress , case_insensitive , blankLinesAllowed , prefixParser ):
2584+ def _build_main_parser (self , redirector , terminators , multilineCommands , legalChars , commentInProgress ,
2585+ blankLinesAllowed , prefixParser ):
25962586 """Builds a PyParsing parser for interpreting user commands."""
25972587
25982588 # Build several parsing components that are eventually compiled into overall parser
@@ -2604,7 +2594,7 @@ def _build_main_parser(self, redirector, terminators, multilineCommands, legalCh
26042594 [(hasattr (t , 'parseString' ) and t ) or pyparsing .Literal (t ) for t in terminators ])('terminator' )
26052595 string_end = pyparsing .stringEnd ^ '\n EOF'
26062596 multilineCommand = pyparsing .Or (
2607- [pyparsing .Keyword (c , caseless = case_insensitive ) for c in multilineCommands ])('multilineCommand' )
2597+ [pyparsing .Keyword (c , caseless = False ) for c in multilineCommands ])('multilineCommand' )
26082598 oneline_command = (~ multilineCommand + pyparsing .Word (legalChars ))('command' )
26092599 pipe = pyparsing .Keyword ('|' , identChars = '|' )
26102600 do_not_parse = self .commentGrammars | commentInProgress | pyparsing .quotedString
@@ -2614,12 +2604,9 @@ def _build_main_parser(self, redirector, terminators, multilineCommands, legalCh
26142604 pyparsing .Optional (output_destination_parser +
26152605 pyparsing .SkipTo (string_end ,
26162606 ignore = do_not_parse ).setParseAction (lambda x : x [0 ].strip ())('outputTo' ))
2617- if case_insensitive :
2618- multilineCommand .setParseAction (lambda x : x [0 ].lower ())
2619- oneline_command .setParseAction (lambda x : x [0 ].lower ())
2620- else :
2621- multilineCommand .setParseAction (lambda x : x [0 ])
2622- oneline_command .setParseAction (lambda x : x [0 ])
2607+
2608+ multilineCommand .setParseAction (lambda x : x [0 ])
2609+ oneline_command .setParseAction (lambda x : x [0 ])
26232610
26242611 if blankLinesAllowed :
26252612 blankLineTerminationParser = pyparsing .NoMatch
@@ -2687,7 +2674,7 @@ def parsed(self, raw):
26872674 s = self .input_source_parser .transformString (s .lstrip ())
26882675 s = self .commentGrammars .transformString (s )
26892676 for (shortcut , expansion ) in self .shortcuts :
2690- if s .lower (). startswith (shortcut ):
2677+ if s .startswith (shortcut ):
26912678 s = s .replace (shortcut , expansion + ' ' , 1 )
26922679 break
26932680 try :
0 commit comments