=========== Using Bases =========== While the :class:`~clap.command.Command` is what wraps the main logic of your program, Bases are responsible for parsing options, providing help, and actually running the commands. .. currentmodule:: clap.base Single-Command Base =================== If your program does not need multiple subcommands, you can just use a :class:`SingleBase`. It does not require as much configuration as a :class:`MultiBase`, as it gets most of its information from its :class:`~clap.command.Command`. .. autoclass:: SingleBase :members: Often, using a :class:`SingleBase` to run your command is as simple as:: if __name__ == '__main__': base = SingleBase(CommandClass) base.run() Multi-Command Base ================== On the other hand, multiple-subcommand programs along the lines of hg or svn need the :class:`MultiBase`. .. autoclass:: MultiBase :members: However, it is often better to create your own subclass of :class:`MultiBase` to use in your application. For example, the "todo.py" demo application uses this code for its base:: class TodoBase(MultiBase): long_desc = """This is a simple to-do list manager. It uses a simple \ text file, and you can mark tasks as high, normal, or low priority.""" global_options = ( Option('f', 'file', argument=True, desc="The to-do list file " "(defaults to ~/.todolist"), Option('v', 'verbose', desc="Print more output than normal") ) global_defaults = dict( file=os.path.expanduser('~/.todolist'), verbose=False ) The Base Class ============== Both :class:`SingleBase` and :class:`MultiBase` are derived from a single class, :class:`Base`. If you want to write a command-line application working on completely different principles, you can subclass from this to gain some useful utilities. .. autoclass:: Base :members: