From 9ff8a3a02b7f25846658e49e3cb5e5ce61c5fab5 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 12 Jan 2016 16:49:51 +0100 Subject: [PATCH] [grep] raise an IMException if pattern not found --- modules/grep.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/grep.py b/modules/grep.py index 59d84e3..a9a4adc 100644 --- a/modules/grep.py +++ b/modules/grep.py @@ -76,8 +76,13 @@ def cmd_grep(msg): only = "only" in msg.kwargs - return [m for m in grep(msg.args[0] if msg.args[0][0] == "^" else ".*?(" + msg.args[0] + ").*?", - msg.args[1][1:] if msg.args[1][0] == "!" else msg.args[1], - msg.args[2:], - msg, - only=only)] + l = [m for m in grep(msg.args[0] if msg.args[0][0] == "^" else ".*?(" + msg.args[0] + ").*?", + msg.args[1][1:] if msg.args[1][0] == "!" else msg.args[1], + msg.args[2:], + msg, + only=only) if m is not None] + + if len(l) <= 0: + raise IMException("Pattern not found in output") + + return l