summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-15 21:35:15 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-15 21:35:15 -0400
commit42243c520332aba1877051f06048814ad5daafd7 (patch)
tree3fd32fe3ec210c282630501bcdd87f4f24d59318 /cmd2.py
parent9139a9bc93369d96f57931bf276b8915f91f2345 (diff)
downloadcmd2-git-42243c520332aba1877051f06048814ad5daafd7.tar.gz
Optimizing
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py16
1 files changed, 3 insertions, 13 deletions
diff --git a/cmd2.py b/cmd2.py
index 6932d556..fd450585 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1024,7 +1024,7 @@ class Cmd(cmd.Cmd):
prefixParser = pyparsing.Empty()
redirector = '>' # for sending output to file
shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
- aliases = {}
+ aliases = dict()
terminators = [';'] # make sure your terminators are not in legalChars!
# Attributes which are NOT dynamically settable at runtime
@@ -1534,12 +1534,7 @@ class Cmd(cmd.Cmd):
# Handle aliases
for cur_alias in self.aliases:
- alias_len = len(cur_alias)
-
- # If the line starts with this alias and it is the only thing on
- # it or is followed by a space, then expand it
- if line.startswith(cur_alias) and ((len(line) == alias_len) or line[alias_len] == ' '):
- # Expand the alias
+ if line == cur_alias or line.startswith(cur_alias + ' '):
line = line.replace(cur_alias, self.aliases[cur_alias], 1)
break
@@ -2890,12 +2885,7 @@ class ParserManager:
# Handle aliases
for cur_alias in self.aliases:
- alias_len = len(cur_alias)
-
- # If the line starts with this alias and it is the only thing on
- # it or is followed by a space, then expand it
- if s.startswith(cur_alias) and ((len(s) == alias_len) or s[alias_len] == ' '):
- # Expand the alias
+ if s == cur_alias or s.startswith(cur_alias + ' '):
s = s.replace(cur_alias, self.aliases[cur_alias], 1)
break