OpenQuizz
Une application de gestion des contenus pédagogiques
Parameter Class Reference
Inheritance diagram for Parameter:
Collaboration diagram for Parameter:

Public Member Functions

def __init__ (self, param_decls=None, type=None, required=False, default=None, callback=None, nargs=None, metavar=None, expose_value=True, is_eager=False, envvar=None, autocompletion=None)
 
def __repr__ (self)
 
def human_readable_name (self)
 
def make_metavar (self)
 
def get_default (self, ctx)
 
def add_to_parser (self, parser, ctx)
 
def consume_value (self, ctx, opts)
 
def type_cast_value (self, ctx, value)
 
def process_value (self, ctx, value)
 
def value_is_missing (self, value)
 
def full_process_value (self, ctx, value)
 
def resolve_envvar_value (self, ctx)
 
def value_from_envvar (self, ctx)
 
def handle_parse_result (self, ctx, opts, args)
 
def get_help_record (self, ctx)
 
def get_usage_pieces (self, ctx)
 
def get_error_hint (self, ctx)
 

Data Fields

 secondary_opts
 
 type
 
 required
 
 callback
 
 nargs
 
 multiple
 
 expose_value
 
 default
 
 is_eager
 
 metavar
 
 envvar
 
 autocompletion
 

Static Public Attributes

string param_type_name = "parameter"
 

Detailed Description

A parameter to a command comes in two versions: they are either
:class:`Option`\s or :class:`Argument`\s.  Other subclasses are currently
not supported by design as some of the internals for parsing are
intentionally not finalized.

Some settings are supported by both options and arguments.

:param param_decls: the parameter declarations for this option or
                    argument.  This is a list of flags or argument
                    names.
:param type: the type that should be used.  Either a :class:`ParamType`
             or a Python type.  The later is converted into the former
             automatically if supported.
:param required: controls if this is optional or not.
:param default: the default value if omitted.  This can also be a callable,
                in which case it's invoked when the default is needed
                without any arguments.
:param callback: a callback that should be executed after the parameter
                 was matched.  This is called as ``fn(ctx, param,
                 value)`` and needs to return the value.
:param nargs: the number of arguments to match.  If not ``1`` the return
              value is a tuple instead of single value.  The default for
              nargs is ``1`` (except if the type is a tuple, then it's
              the arity of the tuple).
:param metavar: how the value is represented in the help page.
:param expose_value: if this is `True` then the value is passed onwards
                     to the command callback and stored on the context,
                     otherwise it's skipped.
:param is_eager: eager values are processed before non eager ones.  This
                 should not be set for arguments or it will inverse the
                 order of processing.
:param envvar: a string or list of strings that are environment variables
               that should be checked.

.. versionchanged:: 7.1
    Empty environment variables are ignored rather than taking the
    empty string value. This makes it possible for scripts to clear
    variables if they can't unset them.

.. versionchanged:: 2.0
    Changed signature for parameter callback to also be passed the
    parameter. The old callback format will still work, but it will
    raise a warning to give you a chance to migrate the code easier.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  param_decls = None,
  type = None,
  required = False,
  default = None,
  callback = None,
  nargs = None,
  metavar = None,
  expose_value = True,
  is_eager = False,
  envvar = None,
  autocompletion = None 
)

Member Function Documentation

◆ __repr__()

def __repr__ (   self)

◆ add_to_parser()

def add_to_parser (   self,
  parser,
  ctx 
)

Reimplemented in Argument, and Option.

◆ consume_value()

def consume_value (   self,
  ctx,
  opts 
)

◆ full_process_value()

def full_process_value (   self,
  ctx,
  value 
)

Reimplemented in Option.

◆ get_default()

def get_default (   self,
  ctx 
)
Given a context variable this calculates the default value.

Reimplemented in Option.

◆ get_error_hint()

def get_error_hint (   self,
  ctx 
)
Get a stringified version of the param for use in error messages to
indicate which param caused the error.

Reimplemented in Argument.

◆ get_help_record()

def get_help_record (   self,
  ctx 
)

Reimplemented in Option.

◆ get_usage_pieces()

def get_usage_pieces (   self,
  ctx 
)

Reimplemented in Argument.

◆ handle_parse_result()

def handle_parse_result (   self,
  ctx,
  opts,
  args 
)

◆ human_readable_name()

def human_readable_name (   self)
Returns the human readable name of this parameter.  This is the
same as the name for options, but the metavar for arguments.

Reimplemented in Argument.

◆ make_metavar()

def make_metavar (   self)

Reimplemented in Argument.

◆ process_value()

def process_value (   self,
  ctx,
  value 
)
Given a value and context this runs the logic to convert the
value as necessary.

◆ resolve_envvar_value()

def resolve_envvar_value (   self,
  ctx 
)

Reimplemented in Option.

◆ type_cast_value()

def type_cast_value (   self,
  ctx,
  value 
)
Given a value this runs it properly through the type system.
This automatically handles things like `nargs` and `multiple` as
well as composite types.

◆ value_from_envvar()

def value_from_envvar (   self,
  ctx 
)

Reimplemented in Option.

◆ value_is_missing()

def value_is_missing (   self,
  value 
)

Field Documentation

◆ autocompletion

autocompletion

◆ callback

callback

◆ default

default

◆ envvar

envvar

◆ expose_value

expose_value

◆ is_eager

is_eager

◆ metavar

metavar

◆ multiple

multiple

◆ nargs

nargs

◆ param_type_name

string param_type_name = "parameter"
static

◆ required

required

◆ secondary_opts

secondary_opts

◆ type

type

The documentation for this class was generated from the following file: