NewPerms branch has been merged
Posted: Sat May 21, 2016 10:21 am
We have finally merged the NewPerms branch into the master! The main purpose of this branch was to updated the permission system, but we have also developed a new feature called typed commands.
In our Wiki you can find information on how to use the new permission system as a server owner and as a developer.
Tutorials for typed server commands are still missing, so I will just drop a few examples here:
Example #1:
Output:
Example #2:
Output:
Example #3:
Output:
We have also updated the "sp" command to use the new typed commands.
Summarized, the typed commands (also available for say and client commands) will take care of an abitrary number of sub-commands, the number of arguments, their types (if provided) and default arguments. Btw. you can also define variadic arguments (unlimited arguments) by using *args. You can also print custom error messages if a a type conversion failed or provide your own types like our filter_str type to easily iterate over players. More on that will be added to the Wiki later.
Edit:
Documentation for typed commands is now online!
http://builds.sourcepython.com/job/Sour ... mands.html
In our Wiki you can find information on how to use the new permission system as a server owner and as a developer.
Tutorials for typed server commands are still missing, so I will just drop a few examples here:
Example #1:
Syntax: Select all
from commands.typed import TypedServerCommand
@TypedServerCommand('multiply')
def on_test(command_info, x:int, y:int):
"""Multiply x and y and print the result."""
print('Result:', x * y)
Output:
Code: Select all
multiply
Not enough arguments:
multiply <x:int> <y:int>
multiply 10 5
Result: 50
multiply 10 5 3
Too many arguments:
multiply <x:int> <y:int>
multiply 10 a
'a' is an invalid value for 'y:int'.
sp help multiply
multiply <x:int> <y:int>
Multiply x and y and print the result.
Example #2:
Syntax: Select all
from commands.typed import TypedServerCommand
@TypedServerCommand('add')
def on_test(command_info, x:int, y:int=10):
"""Add x and y and print the result."""
print('Result:', x + y)
Output:
Code: Select all
add
Not enough arguments:
add <x:int> [y:int=10]
add 5
Result: 15
add 5 3
Result: 8
Example #3:
Syntax: Select all
from commands.typed import TypedServerCommand
@TypedServerCommand(['test', 'a'])
def on_test(command_info, x):
print('a', x)
@TypedServerCommand(['test', 'b'])
def on_test(command_info, x, y):
print('b', (x, y))
Output:
Code: Select all
test
A sub-command is required:
test a <x>
test b <x> <y>
test a
Not enough arguments:
test a <x>
test b "Hello, world!"
Not enough arguments:
test b <x> <y>
test b "Hello, world!" bla
b ('Hello, world!', 'bla')
We have also updated the "sp" command to use the new typed commands.
Code: Select all
sp
A sub-command is required:
sp auth <sub-command> Authorization specific commands.
sp credits List all credits for Source.Python.
sp delay <delay:float> <command> [*args] Execute a command after a given delay.
sp docs <sub-command> Documentation specific commands.
sp dump <sub-command> Dump various data to files.
sp help [command=None] [*sub_commands] Print all sp sub-commands or help for a
specific command.
sp list List all currently loaded plugins.
sp load <plugin> Load a plugin.
sp reload <plugin> Reload a plugin.
sp unload <plugin> Unload a plugin.
sp version Display Source.Python version
information.
Summarized, the typed commands (also available for say and client commands) will take care of an abitrary number of sub-commands, the number of arguments, their types (if provided) and default arguments. Btw. you can also define variadic arguments (unlimited arguments) by using *args. You can also print custom error messages if a a type conversion failed or provide your own types like our filter_str type to easily iterate over players. More on that will be added to the Wiki later.
Edit:
Documentation for typed commands is now online!
http://builds.sourcepython.com/job/Sour ... mands.html