Description
openedon Sep 26, 2018
Enough modules define a structured set of subcommands and positional arguments that it might make the code a bit more streamlined to support giving plugins a parsed version of the command args. (Think admin.py
and its set
command, the .blocks
suite, and so on.)
This is in concept phase for now, but I wanted to follow up my tangential reference to this idea at #1385 with a bit more detail. I reserve the right to bump it further into the future from its starting point as part of Sopel 7, or even drop the idea entirely if it proves to be impractical.
The reasoning is, Sopel's built-in capture groups only handle up to four space-separated arguments (trigger.group(3)
through trigger.group(6)
). For modules to handle more than that, or to handle arguments containing spaces, they have to jump through some annoying hoops with split()
—especially to handle arguments that can contain whitespace. Sopel's implementation doesn't even allow specifying "this and all following tokens", which would make the whitespace case more bearable at least.
I propose that trigger
gain a new property (name TBD, but probably argv
or something similar) containing a tokenized version of the command's arguments, the "arguments" being trigger.group(2)
. Something like shlex
would be helpful for that, as it handles Shell-like syntax automatically (including quoted strings and such).
To reduce the performance impact, this could be introduced with a decorator (say, @sopel.module.parse_args
) and left empty otherwise.
As yet, I'm not sure if full-on argparse
functionality would be useful (or practical to implement in Sopel's module API), but it's a possibility.