Skip to content

Commit 388d486

Browse files
authored
Merge pull request #292 from python-cmd2/abbrev
Removed abbrev attribute
2 parents 17781f2 + fa9479c commit 388d486

File tree

16 files changed

+44
-108
lines changed

16 files changed

+44
-108
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
* Fixed outdated help text for the **edit** command
77
* Fixed outdated [remove_unused.py](https://github.com/python-cmd2/cmd2/blob/master/examples/remove_unused.py)
88
* Enhancements
9-
* Added support for sub-menus.
9+
* Added support for sub-menus.
1010
* See [submenus.py](https://github.com/python-cmd2/cmd2/blob/master/examples/submenus.py) for an example of how to use it
1111
* Added option for persistent readline history
1212
* See [persistent_history.py](https://github.com/python-cmd2/cmd2/blob/master/examples/persistent_history.py) for an example
1313
* See the [Searchable command history](http://cmd2.readthedocs.io/en/latest/freefeatures.html#searchable-command-history) section of the documentation for more info
1414
* Improved PyPI packaging by including unit tests, examples, and docs in the tarball
1515
* Improved documentation to make it more obvious that **poutput()** should be used instead of **print()**
1616
* ``exclude_from_help`` and ``excludeFromHistory`` are now instance instead of class attributes
17-
17+
* Added flag and index based tab completion helper functions
18+
* See [tab_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_completion.py)
19+
* Attributes Removed
20+
* ``abbrev`` - Removed support for abbreviated commands
21+
* Good tab completion makes this unnecessary
22+
1823
## 0.8.0 (February 1, 2018)
1924
* Bug Fixes
2025
* Fixed unit tests on Python 3.7 due to changes in how re.escape() behaves in Python 3.7
@@ -28,7 +33,7 @@
2833
* **with_argparser_and_unknown_args** decorator for argparse-based argument parsing, but allows unknown args
2934
* **do_*** commands get two arguments, the output of argparse.parse_known_args()
3035
* See the [Argument Processing](http://cmd2.readthedocs.io/en/latest/argument_processing.html) section of the documentation for more information on these decorators
31-
* Alternatively, see the [argparse_example.py](https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_example.py)
36+
* Alternatively, see the [argparse_example.py](https://github.com/python-cmd2/cmd2/blob/master/examples/argparse_example.py)
3237
and [arg_print.py](https://github.com/python-cmd2/cmd2/blob/master/examples/arg_print.py) examples
3338
* Added support for Argpasre sub-commands when using the **with_argument_parser** or **with_argparser_and_unknown_args** decorators
3439
* See [subcommands.py](https://github.com/python-cmd2/cmd2/blob/master/examples/subcommands.py) for an example of how to use subcommands

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Main Features
2626
- Redirect command output to file with `>`, `>>`; input from file with `<`
2727
- Bare `>`, `>>` with no filename send output to paste buffer (clipboard)
2828
- `py` enters interactive Python console (opt-in `ipy` for IPython console)
29-
- Multi-line, case-insensitive, and abbreviated commands
29+
- Multi-line and case-insensitive commands
3030
- Special-character command shortcuts (beyond cmd's `@` and `!`)
3131
- Settable environment parameters
3232
- Parsing commands with arguments using `argparse`, including support for sub-commands
@@ -171,7 +171,6 @@ class CmdLineApp(Cmd):
171171
MUMBLE_LAST = ['right?']
172172

173173
def __init__(self):
174-
self.abbrev = True
175174
self.multilineCommands = ['orate']
176175
self.maxrepeats = 3
177176

@@ -248,7 +247,6 @@ example/transcript_regex.txt:
248247
# The regex for editor will match whatever program you use.
249248
# regexes on prompts just make the trailing space obvious
250249
(Cmd) set
251-
abbrev: True
252250
colors: /(True|False)/
253251
continuation_prompt: >/ /
254252
debug: False

cmd2.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ class Cmd(cmd.Cmd):
995995
commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
996996
commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd ^ '*/')
997997
legalChars = u'!#$%.:?@_-' + pyparsing.alphanums + pyparsing.alphas8bit
998-
multilineCommands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
998+
multilineCommands = []
999999
prefixParser = pyparsing.Empty()
10001000
redirector = '>' # for sending output to file
10011001
shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
@@ -1008,7 +1008,6 @@ class Cmd(cmd.Cmd):
10081008
reserved_words = []
10091009

10101010
# Attributes which ARE dynamically settable at runtime
1011-
abbrev = False # Abbreviated commands recognized
10121011
colors = (platform.system() != 'Windows')
10131012
continuation_prompt = '> '
10141013
debug = False
@@ -1029,8 +1028,7 @@ class Cmd(cmd.Cmd):
10291028

10301029
# To make an attribute settable with the "do_set" command, add it to this ...
10311030
# This starts out as a dictionary but gets converted to an OrderedDict sorted alphabetically by key
1032-
settable = {'abbrev': 'Accept abbreviated commands',
1033-
'colors': 'Colorized output (*nix only)',
1031+
settable = {'colors': 'Colorized output (*nix only)',
10341032
'continuation_prompt': 'On 2nd+ line of input',
10351033
'debug': 'Show full error stack on error',
10361034
'echo': 'Echo command issued into output',
@@ -1076,7 +1074,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
10761074

10771075
# Commands to exclude from the help menu or history command
10781076
self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load']
1079-
self.excludeFromHistory = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
1077+
self.excludeFromHistory = '''history edit eof eos'''.split()
10801078

10811079
self._finalize_app_parameters()
10821080

@@ -1664,21 +1662,13 @@ def _restore_output(self, statement):
16641662
def _func_named(self, arg):
16651663
"""Gets the method name associated with a given command.
16661664
1667-
If self.abbrev is False, it is always just looks for do_arg. However, if self.abbrev is True,
1668-
it allows abbreviated command names and looks for any commands which start with do_arg.
1669-
16701665
:param arg: str - command to look up method name which implements it
16711666
:return: str - method name which implements the given command
16721667
"""
16731668
result = None
16741669
target = 'do_' + arg
16751670
if target in dir(self):
16761671
result = target
1677-
else:
1678-
if self.abbrev: # accept shortened versions of commands
1679-
funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multilineCommands]
1680-
if len(funcs) == 1:
1681-
result = 'do_' + funcs[0]
16821672
return result
16831673

16841674
def onecmd(self, line):

docs/freefeatures.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,6 @@ Quitting the application
271271
It's trivial, but it's one less thing for you to remember.
272272

273273

274-
Abbreviated commands
275-
====================
276-
277-
``cmd2`` apps will accept shortened command names
278-
so long as there is no ambiguity if the ``abbrev`` settable parameter is set to ``True``.
279-
Thus, if ``do_divide`` is defined, then ``divid``, ``div``,
280-
or even ``d`` will suffice, so long as there are
281-
no other commands defined beginning with *divid*,
282-
*div*, or *d*.
283-
284-
This behavior is disabled by default, but can be turned on with ``app.abbrev`` (see :ref:`parameters`)
285-
286-
.. warning::
287-
288-
Due to the way the parsing logic works for multiline commands, abbreviations
289-
will not be accepted for multiline commands.
290-
291274
Misc. pre-defined commands
292275
==========================
293276

docs/settingchanges.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ comments, is viewable from within a running application
116116
with::
117117

118118
(Cmd) set --long
119-
abbrev: False # Accept abbreviated commands
120119
colors: True # Colorized output (*nix only)
121120
continuation_prompt: > # On 2nd+ line of input
122121
debug: False # Show full error stack on error
@@ -130,5 +129,5 @@ with::
130129

131130
Any of these user-settable parameters can be set while running your app with the ``set`` command like so::
132131

133-
set abbrev True
132+
set colors False
134133

examples/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class CmdLineApp(Cmd):
2727
MUMBLE_LAST = ['right?']
2828

2929
def __init__(self):
30-
self.abbrev = True
3130
self.multilineCommands = ['orate']
3231
self.maxrepeats = 3
3332

examples/transcripts/exampleSession.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# The regex for editor will match whatever program you use.
44
# regexes on prompts just make the trailing space obvious
55
(Cmd) set
6-
abbrev: False
76
colors: /(True|False)/
87
continuation_prompt: >/ /
98
debug: False

examples/transcripts/transcript_regex.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# The regex for editor will match whatever program you use.
44
# regexes on prompts just make the trailing space obvious
55
(Cmd) set
6-
abbrev: True
76
colors: /(True|False)/
87
continuation_prompt: >/ /
98
debug: False

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- Redirect command output to file with `>`, `>>`; input from file with `<`
2727
- Bare `>`, `>>` with no filename send output to paste buffer (clipboard)
2828
- `py` enters interactive Python console (opt-in `ipy` for IPython console)
29-
- Multi-line, case-insensitive, and abbreviated commands
29+
- Multi-line and case-insensitive commands
3030
- Special-character command shortcuts (beyond cmd's `@` and `!`)
3131
- Settable environment parameters
3232
- Parsing commands with arguments using `argparse`, including support for sub-commands

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
if sys.platform.startswith('win'):
5454
expect_colors = False
5555
# Output from the show command with default settings
56-
SHOW_TXT = """abbrev: False
57-
colors: {}
56+
SHOW_TXT = """colors: {}
5857
continuation_prompt: >
5958
debug: False
6059
echo: False
@@ -71,7 +70,6 @@
7170
else:
7271
color_str = 'False'
7372
SHOW_LONG = """
74-
abbrev: False # Accept abbreviated commands
7573
colors: {} # Colorized output (*nix only)
7674
continuation_prompt: > # On 2nd+ line of input
7775
debug: False # Show full error stack on error

0 commit comments

Comments
 (0)