From 545804dffeeb6244af2af58ad2c2a93f679a3219 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 26 Aug 2014 09:09:55 +0200 Subject: [PATCH] Added ability to abort the command chain by returning a true value from cmd.at_pre_cmd(). --- src/commands/cmdhandler.py | 5 ++++- src/commands/command.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index ff6ec584bb..11c53b3243 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -401,7 +401,10 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess setattr(cmd, key, val) # pre-command hook - yield cmd.at_pre_cmd() + abort = yield cmd.at_pre_cmd() + if abort: + # abort sequence + returnValue(abort) # Parse and execute yield cmd.parse() diff --git a/src/commands/command.py b/src/commands/command.py index c37eb0bd5d..43cf87a4a2 100644 --- a/src/commands/command.py +++ b/src/commands/command.py @@ -255,7 +255,9 @@ class Command(object): 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