Update some docs, update contrib README.
This commit is contained in:
parent
248f20e8e5
commit
dc859eae57
2 changed files with 21 additions and 11 deletions
|
|
@ -30,6 +30,8 @@ things you want from here into your game folder and change them there.
|
||||||
multiple descriptions for time and season as well as details.
|
multiple descriptions for time and season as well as details.
|
||||||
* GenderSub (Griatch 2015) - Simple example (only) of storing gender
|
* GenderSub (Griatch 2015) - Simple example (only) of storing gender
|
||||||
on a character and access it in an emote with a custom marker.
|
on a character and access it in an emote with a custom marker.
|
||||||
|
* In-game Python (Vincent Le Geoff 2017) - Allow trusted builders to script
|
||||||
|
objects and events using Python from in-game.
|
||||||
* Mail (grungies1138 2016) - An in-game mail system for communication.
|
* Mail (grungies1138 2016) - An in-game mail system for communication.
|
||||||
* Menu login (Griatch 2011) - A login system using menus asking
|
* Menu login (Griatch 2011) - A login system using menus asking
|
||||||
for name/password rather than giving them as one command
|
for name/password rather than giving them as one command
|
||||||
|
|
@ -51,6 +53,7 @@ things you want from here into your game folder and change them there.
|
||||||
as a start to build from. Has attack/disengage and turn timeouts.
|
as a start to build from. Has attack/disengage and turn timeouts.
|
||||||
* Wilderness (titeuf87 2017) - Make infinitely large wilderness areas
|
* Wilderness (titeuf87 2017) - Make infinitely large wilderness areas
|
||||||
with dynamically created locations.
|
with dynamically created locations.
|
||||||
|
* UnixCommand (Vincent Le Geoff 2017) - Add commands with UNIX-style syntax.
|
||||||
|
|
||||||
## Contrib packages
|
## Contrib packages
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,20 @@
|
||||||
"""
|
"""
|
||||||
Module containing the UnixCommand class.
|
Unix-like Command style parent
|
||||||
|
|
||||||
This command allows to use unix-like options in game commands. It is
|
Evennia contribution, Vincent Le Geoff 2017
|
||||||
not the best parser for players, but can be really useful for builders
|
|
||||||
when they need to have a single command to do many things with many
|
|
||||||
options.
|
|
||||||
|
|
||||||
The UnixCommand can be ovverridden to have your commands parsed.
|
This module contains a command class that allows for unix-style command syntax in-game, using
|
||||||
You will need to override two methods:
|
--options, positional arguments and stuff like -n 10 etc similarly to a unix command. It might not
|
||||||
- The `init_parser` method, which adds options to the parser.
|
the best syntax for the average player but can be really useful for builders when they need to have
|
||||||
- The `func` method, called to execute the command once parsed.
|
a single command do many things with many options. It uses the ArgumentParser from Python's standard
|
||||||
|
library under the hood.
|
||||||
|
|
||||||
|
To use, inherit `UnixCommand` from this module from your own commands. You need
|
||||||
|
to override two methods:
|
||||||
|
|
||||||
|
- The `init_parser` method, which adds options to the parser. Note that you should normally
|
||||||
|
*not* override the normal `parse` method when inheriting from `UnixCommand`.
|
||||||
|
- The `func` method, called to execute the command once parsed (like any Command).
|
||||||
|
|
||||||
Here's a short example:
|
Here's a short example:
|
||||||
|
|
||||||
|
|
@ -19,7 +24,7 @@ class CmdPlant(UnixCommand):
|
||||||
'''
|
'''
|
||||||
Plant a tree or plant.
|
Plant a tree or plant.
|
||||||
|
|
||||||
This command is used to plant a tree or plant in the room you are in.
|
This command is used to plant something in the room you are in.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
plant orange -a 8
|
plant orange -a 8
|
||||||
|
|
@ -62,6 +67,7 @@ from textwrap import dedent
|
||||||
from evennia import Command, InterruptCommand
|
from evennia import Command, InterruptCommand
|
||||||
from evennia.utils.ansi import raw
|
from evennia.utils.ansi import raw
|
||||||
|
|
||||||
|
|
||||||
class ParseError(Exception):
|
class ParseError(Exception):
|
||||||
|
|
||||||
"""An error occurred during parsing."""
|
"""An error occurred during parsing."""
|
||||||
|
|
@ -109,6 +115,7 @@ class UnixCommandParser(argparse.ArgumentParser):
|
||||||
conflict_handler='resolve', add_help=False, **kwargs)
|
conflict_handler='resolve', add_help=False, **kwargs)
|
||||||
self.command = command
|
self.command = command
|
||||||
self.post_help = epilog
|
self.post_help = epilog
|
||||||
|
|
||||||
def n_exit(code=None, msg=None):
|
def n_exit(code=None, msg=None):
|
||||||
raise ParseError(msg)
|
raise ParseError(msg)
|
||||||
|
|
||||||
|
|
@ -116,7 +123,7 @@ class UnixCommandParser(argparse.ArgumentParser):
|
||||||
|
|
||||||
# Replace the -h/--help
|
# Replace the -h/--help
|
||||||
self.add_argument("-h", "--hel", nargs=0, action=HelpAction,
|
self.add_argument("-h", "--hel", nargs=0, action=HelpAction,
|
||||||
help="display the command help")
|
help="display the command help")
|
||||||
|
|
||||||
def format_usage(self):
|
def format_usage(self):
|
||||||
"""Return the usage line.
|
"""Return the usage line.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue