Skip to content

Commit b513c16

Browse files
authored
Merge pull request #103 from python-cmd2/multiline_abbreviations
Multiline abbreviations
2 parents 8297145 + a57c664 commit b513c16

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ News
2323
* Added CmdResult namedtumple for returning and storing results
2424
* Added local file system path completion for ``edit``, ``load``, ``save``, and ``shell`` commands
2525
* Add shell command completion for ``shell`` command or ``!`` shortcut
26+
* Abbreviated multiline commands are no longer allowed (they never worked correctly anyways)
2627

2728
0.7.0
2829
-----

cmd2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ class Cmd(cmd.Cmd):
600600
excludeFromHistory = '''run r list l history hi ed edit li eof'''.split()
601601
# make sure your terminators are not in legalChars!
602602
legalChars = u'!#$%.:?@_-' + pyparsing.alphanums + pyparsing.alphas8bit
603-
multilineCommands = []
603+
multilineCommands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
604604
noSpecialParse = 'set ed edit exit'.split()
605605
prefixParser = pyparsing.Empty()
606606
redirector = '>' # for sending output to file
@@ -1089,7 +1089,7 @@ def func_named(self, arg):
10891089
result = target
10901090
else:
10911091
if self.abbrev: # accept shortened versions of commands
1092-
funcs = [fname for fname in self.keywords if fname.startswith(arg)]
1092+
funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multilineCommands]
10931093
if len(funcs) == 1:
10941094
result = 'do_' + funcs[0]
10951095
return result

docs/freefeatures.rst

+5
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ no other commands defined beginning with *divid*,
243243

244244
This behavior can be turned off with ``app.abbrev`` (see :ref:`parameters`)
245245

246+
.. warning::
247+
248+
Due to the way the parsing logic works for multiline commands, abbreviations
249+
will not be accepted for multiline commands.
250+
246251
Misc. pre-defined commands
247252
==========================
248253

tests/test_parsing.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Unit/functional testing for helper functions/classes in the cmd2.py module.
44
5-
These are primarily tests related to parsing. Moreover, they are mostly a port of the old doctest tests which were
5+
These are primarily tests related to parsing. Moreover, they are mostly a port of the old doctest tests which were
66
problematic because they worked properly for some versions of pyparsing but not for others.
77
88
Copyright 2017 Todd Leonhardt <[email protected]>
@@ -247,6 +247,12 @@ def test_parse_multiline_ignores_terminators_in_comments(parser):
247247
assert results.terminator[0] == '\n'
248248
assert results.terminator[1] == '\n'
249249

250+
def test_parse_abbreviated_multiline_not_allowed(parser):
251+
line = 'multilin command\n'
252+
results = parser.parseString(line)
253+
assert results.command == 'multilin'
254+
assert results.multilineCommand == ''
255+
250256
# Unicode support is only present in cmd2 for Python 3
251257
@pytest.mark.skipif(sys.version_info < (3,0), reason="cmd2 unicode support requires python3")
252258
def test_parse_command_with_unicode_args(parser):

0 commit comments

Comments
 (0)