summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 09fec115..62c188b4 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2009,11 +2009,8 @@ class Cmd(cmd.Cmd):
:param arg: command to look up method name which implements it
:return: method name which implements the given command
"""
- result = None
target = 'do_' + arg
- if target in dir(self):
- result = target
- return result
+ return target if callable(getattr(self, target, None)) else ''
def onecmd(self, statement: Union[Statement, str]) -> bool:
""" This executes the actual do_* method for a command.
@@ -2033,21 +2030,17 @@ class Cmd(cmd.Cmd):
stop = self._run_macro(statement)
else:
funcname = self._func_named(statement.command)
- if not funcname:
- self.default(statement)
- return False
+ if funcname:
+ func = getattr(self, funcname)
+ stop = func(statement)
- # Since we have a valid command store it in the history
- if statement.command not in self.exclude_from_history:
- self.history.append(statement.raw)
+ # Since we have a valid command store it in the history
+ if statement.command not in self.exclude_from_history:
+ self.history.append(statement.raw)
- try:
- func = getattr(self, funcname)
- except AttributeError:
+ else:
self.default(statement)
- return False
-
- stop = func(statement)
+ stop = False
return stop