Page 1 of 1

Command Helpers

Posted: Wed Apr 22, 2015 8:57 pm
by necavi
I'm considering creating a library of command helpers, some of which would include things I've already done here as well as something similar to Flask's variable routing rules. I felt the need for this when I realized that I wanted to add commands to add/remove/edit groups and players as part of my auth provider, but in order to do that in a simple and reasonable fashion it would require some rather convoluted and pointlessly repeated code. My current idea is to have something like this:

Syntax: Select all

@Command("auth group <group> add <permission>")
def auth_group_add(source, group, permission):
pass


but it could just as easily be used for other commands, imagine:

Syntax: Select all

@Command("sp_ignite <PlayerFilter :p layer> [int:time]")
def sp_ignite(source, player, time=0)
pass


Any thoughts on this, or ways to improve it? If not, I'll likely begin working on this once SourcePerms is in an appropriate state.

Sidenote: It is really quite easy to do this with a simple regex

Edit: Forgot to mention an important part: Similar to how Flask's rules work, I would have it so that it tried to match to the function with the most valid params, so if you used "sp auth groups" if wouldn't match it to the above function, it would match it to @Command("sp auth groups") and provide help (with the option for that to be autogenerated, likely) or what have you.

Posted: Fri Apr 24, 2015 7:23 am
by Ayuto
Rather than creating regular expressions you could simply pass the commands and required arguments seperately.

I would think about something like this. That seems to be more pythonic and allows more flexibility.

Syntax: Select all

@Command('sp_ignite',
Argument('player', validator=player_filter_validator),
Argument('duration', validator=float, optional=True))
def sp_ignite(source, players, duration=0):
pass