This is a template intended for use as the starting point of simple
command-line Python scripts. It wraps the main
function, passing on
the arguments the script was called with and using the function's
return value as the exit code. If an invalid number of arguments are
provided, it generates and displays a usage string from the function's
argument list and docstring.
Here are some examples that should demonstrate exactly how this works.
def main():
pass
$ ./hello.py too many arguments
usage: ./hello.py
With an argument:
def main(directory):
pass
$ ./something.py too many arguments
usage: ./something.py directory
With a default argument:
def main(name, age=None):
pass
$ ./add_member.py # no arguments
usage: ./add_member.py name [age]
With only default arguments:
def main(subject="all", verbosity=0):
pass
$ ./help.py # no arguments
usage: ./help.py [subject [verbosity]]
With a docstring and capturing extra arguments:
def main(no, more, contrived=None, *examples):
"""I promise."""
pass
$ ./example.py yes
usage: ./example.py no more [contrived [examples...]]
I promise.