Opster is a command line parser, intended to make writing command line applications easy and painless. It uses built-in Python types (lists, dictionaries, etc) to define options, which makes configuration clear and concise. Additionally, Opster supports parsing arguments for an application that uses subcommands (i.e. hg commit or svn update).
Here’s an example of a program that defines a single option:
import sys from opster import command @command() def main(message, no_newline=('n', False, "don't print a newline")): '''Simple echo program''' sys.stdout.write(message) if not no_newline: sys.stdout.write('\n') if __name__ == '__main__': main.command()
Running the program above will print the help message::
> ./echo.py echo.py: invalid arguments echo.py [OPTIONS] MESSAGE Simple echo program options: -n --no-newline don't print a newline -h --help display help
As you can see, here we have defined an option to not print newlines: the keyword argument is used as the long name for the option and its default value is a 3-tuple, containing short name for an option (can be empty), default value (whose type determines what conversion is applied - see description) and a help string for the option.
Any underscores in the keyword argument name are converted into dashes in the long option name.
When a command is called using the long name for an option, the option need not be fully entered. In the case above this could look like ./echo.py --no-new. This is also true for subcommands: read about them and everything else you’d like to know further on in the documentation.
Read more in Overview.