Added ability to abort the command chain by returning a true value from cmd.at_pre_cmd().
This commit is contained in:
parent
58f6c05964
commit
545804dffe
2 changed files with 7 additions and 2 deletions
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue