[grep] Add @nocase option, --ignore-case like
This commit is contained in:
parent
9ff8a3a02b
commit
d705d351c0
@ -14,7 +14,7 @@ from more import Response
|
|||||||
|
|
||||||
# MODULE CORE #########################################################
|
# MODULE CORE #########################################################
|
||||||
|
|
||||||
def grep(fltr, cmd, args, msg, only=False):
|
def grep(fltr, cmd, args, msg, icase=False, only=False):
|
||||||
"""Perform a grep like on known nemubot structures
|
"""Perform a grep like on known nemubot structures
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -22,10 +22,11 @@ def grep(fltr, cmd, args, msg, only=False):
|
|||||||
cmd -- The subcommand to execute
|
cmd -- The subcommand to execute
|
||||||
args -- subcommand arguments
|
args -- subcommand arguments
|
||||||
msg -- The original message
|
msg -- The original message
|
||||||
|
icase -- like the --ignore-case parameter of grep
|
||||||
only -- like the --only-matching parameter of grep
|
only -- like the --only-matching parameter of grep
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fltr = re.compile(fltr)
|
fltr = re.compile(fltr, re.I if icase else 0)
|
||||||
|
|
||||||
for r in context.subtreat(Command(cmd,
|
for r in context.subtreat(Command(cmd,
|
||||||
args,
|
args,
|
||||||
@ -68,6 +69,7 @@ def grep(fltr, cmd, args, msg, only=False):
|
|||||||
help="Display only lines from a subcommand matching the given pattern",
|
help="Display only lines from a subcommand matching the given pattern",
|
||||||
help_usage={"PTRN !SUBCMD": "Filter SUBCMD command using the pattern PTRN"},
|
help_usage={"PTRN !SUBCMD": "Filter SUBCMD command using the pattern PTRN"},
|
||||||
keywords={
|
keywords={
|
||||||
|
"nocase": "Perform case-insensitive matching",
|
||||||
"only": "Print only the matched parts of a matching line",
|
"only": "Print only the matched parts of a matching line",
|
||||||
})
|
})
|
||||||
def cmd_grep(msg):
|
def cmd_grep(msg):
|
||||||
@ -80,6 +82,7 @@ def cmd_grep(msg):
|
|||||||
msg.args[1][1:] if msg.args[1][0] == "!" else msg.args[1],
|
msg.args[1][1:] if msg.args[1][0] == "!" else msg.args[1],
|
||||||
msg.args[2:],
|
msg.args[2:],
|
||||||
msg,
|
msg,
|
||||||
|
icase="nocase" in msg.kwargs,
|
||||||
only=only) if m is not None]
|
only=only) if m is not None]
|
||||||
|
|
||||||
if len(l) <= 0:
|
if len(l) <= 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user