Skip to content

Commit 91255cd

Browse files
committed
Revert to old attribute names for multilineCommands and excludeFromHistory to prevent breaking change
Also: - Reverted multilineCommands and shortcuts to class variables to prevent other breaking changes
1 parent ab03d90 commit 91255cd

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

cmd2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,10 @@ class Cmd(cmd.Cmd):
793793
commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
794794
commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd ^ '*/')
795795
legalChars = u'!#$%.:?@_-' + pyparsing.alphanums + pyparsing.alphas8bit
796+
multilineCommands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
796797
prefixParser = pyparsing.Empty()
797798
redirector = '>' # for sending output to file
799+
shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
798800
terminators = [';'] # make sure your terminators are not in legalChars!
799801

800802
# Attributes which are NOT dynamically settable at runtime
@@ -870,12 +872,9 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
870872
# Call super class constructor. Need to do it in this way for Python 2 and 3 compatibility
871873
cmd.Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
872874

873-
self.multiline_commands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
874-
self.shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
875-
876875
# Commands to exclude from the help menu or history command
877876
self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load']
878-
self.exclude_from_history = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
877+
self.excludeFromHistory = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
879878

880879
self._finalize_app_parameters()
881880

@@ -884,7 +883,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
884883
self.pystate = {}
885884
self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) if fname.startswith('do_')]
886885
self.parser_manager = ParserManager(redirector=self.redirector, terminators=self.terminators,
887-
multilineCommands=self.multiline_commands,
886+
multilineCommands=self.multilineCommands,
888887
legalChars=self.legalChars, commentGrammars=self.commentGrammars,
889888
commentInProgress=self.commentInProgress,
890889
case_insensitive=self.case_insensitive,
@@ -1399,7 +1398,7 @@ def _func_named(self, arg):
13991398
result = target
14001399
else:
14011400
if self.abbrev: # accept shortened versions of commands
1402-
funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multiline_commands]
1401+
funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multilineCommands]
14031402
if len(funcs) == 1:
14041403
result = 'do_' + funcs[0]
14051404
return result
@@ -1418,7 +1417,7 @@ def onecmd(self, line):
14181417
return self.default(statement)
14191418

14201419
# Since we have a valid command store it in the history
1421-
if statement.parsed.command not in self.exclude_from_history:
1420+
if statement.parsed.command not in self.excludeFromHistory:
14221421
self.history.append(statement.parsed.raw)
14231422

14241423
try:

tests/test_parsing.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def hist():
2424
@pytest.fixture
2525
def parser():
2626
c = cmd2.Cmd()
27-
c.multiline_commands = ['multiline']
27+
c.multilineCommands = ['multiline']
2828
c.case_insensitive = True
29-
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multiline_commands,
29+
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
3030
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
3131
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
3232
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
@@ -37,9 +37,9 @@ def parser():
3737
@pytest.fixture
3838
def ci_pm():
3939
c = cmd2.Cmd()
40-
c.multiline_commands = ['multiline']
40+
c.multilineCommands = ['multiline']
4141
c.case_insensitive = True
42-
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multiline_commands,
42+
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
4343
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
4444
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
4545
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,
@@ -50,9 +50,9 @@ def ci_pm():
5050
@pytest.fixture
5151
def cs_pm():
5252
c = cmd2.Cmd()
53-
c.multiline_commands = ['multiline']
53+
c.multilineCommands = ['multiline']
5454
c.case_insensitive = False
55-
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multiline_commands,
55+
c.parser_manager = cmd2.ParserManager(redirector=c.redirector, terminators=c.terminators, multilineCommands=c.multilineCommands,
5656
legalChars=c.legalChars, commentGrammars=c.commentGrammars,
5757
commentInProgress=c.commentInProgress, case_insensitive=c.case_insensitive,
5858
blankLinesAllowed=c.blankLinesAllowed, prefixParser=c.prefixParser,

0 commit comments

Comments
 (0)