Command Helpers

Discuss API design here.
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Command Helpers

Postby necavi » 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:

Syntax: Select all

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

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)

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.
User avatar
Project Leader
Posts: 1545
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Apr 24, 2015 7:23 am

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

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

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 1 guest