Cement core argument module.

class cement.core.arg.CementArgumentHandler(*args, **kw)

Bases: cement.core.handler.CementBaseHandler

Base class that all Argument Handlers should sub-class from.

class Meta

Bases: object

Handler meta-data (can be passed as keyword arguments to the parent class).


The interface that this class implements.

alias of IArgument

label = None

The string identifier of the handler implementation.

class cement.core.arg.IArgument

Bases: cement.core.interface.Interface

This class defines the Argument Handler Interface. Classes that implement this handler must provide the methods and attributes defined below. Implementations do not subclass from interfaces.


from cement.core import interface, arg

class MyArgumentHandler(arg.CementArgumentHandler):
    class Meta:
        interface = arg.IArgument
        label = 'my_argument_handler'
class IMeta

Bases: object

Interface meta-data options.

label = 'argument'

The string identifier of the interface.

validator(klass, obj)

Interface validator function.


The _setup function is called during application initialization and must ‘setup’ the handler object making it ready for the framework or the application to make further calls to it.

Parameters:app_obj – The application object
IArgument.add_argument(*args, **kw)

Add arguments for parsing. This should be -o/–option or positional. Note that the interface defines the following parameters so that at the very least, external extensions can guarantee that they can properly add command line arguments when necessary. The implementation itself should, and will provide and support many more options than those listed here. That said, the implementation must support the following:

  • args – List of option arguments. Generally something like [‘-h’, ‘–help’].
  • dest – The destination name (var). Default: arg[0]’s string.
  • help – The help text for –help output (for that argument).
  • action – Must support: [‘store’, ‘store_true’, ‘store_false’, ‘store_const’]
  • choices – A list of valid values that can be passed to an option whose action is store.
  • const – The value stored if action == ‘store_const’.
  • default – The default value.



Parse the argument list (i.e. sys.argv). Can return any object as long as it’s members contain those of the added arguments. For example, if adding a ‘-v/–version’ option that stores to the dest of ‘version’, then the member must be callable as ‘Object().version’.

Parameters:arg_list – A list of command line arguments.
Returns:Callable object
cement.core.arg.argument_validator(klass, obj)

Validates a handler implementation against the IArgument interface.