commandlineapp – Command line application builder

Base class for building command line applications.

CommandLineApp makes creating command line applications as simple as defining callbacks to handle options when they appear in sys.argv.

Application Base Class

class commandlineapp.CommandLineApp(command_line_options=None)

Base class for building command line applications.

Define a docstring for the class to explain what the program does.

Include descriptions of the command arguments in the docstring for main().

When the EXAMPLES_DESCRIPTION class attribute is not empty, it will be printed last in the help message when the user asks for help.

__init__(command_line_options=None)

Initialize CommandLineApp.

before_options_hook()

Hook to initialize the app before the options are processed.

Overriding __init__() requires special handling to make sure the arguments are still passed to the base class. Override this method instead to create local attributes or do other initialization before the command line options are processed.

after_options_hook()

Hook to initialize the app after the options are processed.

Overriding __init__() requires special handling to make sure the arguments are still passed to the base class. Override this method instead to create local attributes or do other initialization after the command line options are processed.

main(*args)

Main body of your application.

This is the main portion of the app, and is run after all of the arguments are processed. Override this method to implment the primary processing section of your application.

status_message(msg='', verbose_level=1, error=False, newline=True)

Print a status message to output.

msg
The status message string to be printed.
verbose_level
The verbose level to use. The message will only be printed if the current verbose level is >= this number.
error
If true, the message is considered an error and printed as such.
newline
If true, print a newline after the message.
error_message(msg='')

Print a message as an error.

option_handler_debug()

Set debug mode to see tracebacks.

option_handler_h()

Displays abbreviated help message.

option_handler_help()

Displays verbose help message.

option_handler_quiet()

Turn on quiet mode.

option_handler_v()

Increment the verbose level.

Higher levels are more verbose. The default is 1.

run()

Entry point.

Process options and execute callback functions as needed. This method should not need to be overridden, if the main() method is defined.

Table Of Contents

Previous topic

CommandLineApp

Next topic

Command line programs are classes, too!

This Page