commandeer Package

commandeer Package

Use this module to add a simple way to add nice command line interaction to your program.

Usage: in your main python script, arrange for all functions that should be reachable from the command line to have a name ending in _command. All arguments to your function are parsed as arguments in a smart way. At the end of your script, simply add a call to commandeer.cli() and you’re good to go. A simple example script could look like this:

"This script echo's your input."
def echo_command(input, timestamp=False, indent=0):
    "Outputs the input, with an optional timestamp and some indenting."
    echo_str = input
    if timestamp:
        echo_str = "[date]" + echo_str
    echo_str = " " * indent + echo_str

if __name__ == '__main__':

Calling this script without any arguments (or with only “help”) will show a short help screen:

$ python help
This script echo's your input.
Usage: command [options]

Command can be one of the following:
  echo   Outputs the input, with an optional timestamp and some indenting.

Calling the script with “help commandname” will print more information from the docstring as well as the available arguments.

For a more detailed explanation refer to the documentation.

commandeer.cli(with_help=True, default_command='help', config_file_name=None)[source]

Create a really nice command line from the callers local space, then parse the program arguments and act accordingly.

If you set the with_help parameter to True, commandeer will add the help command by itself and also execute that command when no other commands are passed to the program. If you set it to False, no help will be added and only your commands will be available.

commandeer.gone(prefix, prefix_length, text, max_length)[source]

Wrap the given text so that it is max_length columns wide at most, adding prefix and indentation at the start.