Arguments
Introduction to the Argument Interface
Cement defines an Argument Interface, as well as the default ArgParseArgumentHandler that implements the interface. This handler is built on top of the ArgParse module which is included in the Python standard library.
Cement often includes multiple handler implementations of an interface that may or may not have additional features or functionality than the interface requires. The documentation below only references usage based on the interface and default handler (not the full capabilities of an implementation).
Cement Extensions That Provide Argument Handlers:
API References:
Configuration
Application Meta Options
The following options under App.Meta
modify configuration handling:
Option | Description |
arg_handler | The handler that implements the argument interface. |
Adding Arguments
The argument interface is loosely based on Argparse, but only defines a minimal set of params that must be honored as to ensure that the framework and extensions can add arguments regardless of what the argument handler implementation is. That said, Cement has never intended to use anything other than Argparse to handle arguments and for that reason there may be some assumptions inherently builtin that assume the underlying argument handler is 100% argparse compliant. For that reason, adding and working with arguments will be completely familiar for anyone who has ever used Argparse.
Accessing Parsed Arguments
During app.run()
, command line arguments are parsed by the argument handler, and the results are stored by the application. Arguments are then accessible by App.pargs
(parsed args).
Creating an Argument Handler
All interfaces in Cement can be overridden with your own implementation. This can be done either by sub-classing ArgumentHandler itself, or by sub-classing an existing extension's handlers in order to alter their functionality.
Last updated