Added ability to abort the command chain by returning a true value from cmd.at_pre_cmd().

This commit is contained in:
Griatch 2014-08-26 09:09:55 +02:00
parent 58f6c05964
commit 545804dffe
2 changed files with 7 additions and 2 deletions

View file

@ -401,7 +401,10 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
setattr(cmd, key, val) setattr(cmd, key, val)
# pre-command hook # pre-command hook
yield cmd.at_pre_cmd() abort = yield cmd.at_pre_cmd()
if abort:
# abort sequence
returnValue(abort)
# Parse and execute # Parse and execute
yield cmd.parse() yield cmd.parse()

View file

@ -255,7 +255,9 @@ class Command(object):
def at_pre_cmd(self): def at_pre_cmd(self):
""" """
This hook is called before self.parse() on all commands This hook is called before self.parse() on all commands.
If this hook returns anything but False/None, the command
sequence is aborted.
""" """
pass pass