Command Helpers
Posted: Wed Apr 22, 2015 8:57 pm
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:
but it could just as easily be used for other commands, imagine:
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.
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.