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

Public Member Functions

def __init__ (self, name, context_settings=None)
 
def __repr__ (self)
 
def get_usage (self, ctx)
 
def get_help (self, ctx)
 
def make_context (self, info_name, args, parent=None, **extra)
 
def parse_args (self, ctx, args)
 
def invoke (self, ctx)
 
def main (self, args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra)
 
def __call__ (self, *args, **kwargs)
 

Data Fields

 name
 
 context_settings
 

Static Public Attributes

bool allow_extra_args = False
 
bool allow_interspersed_args = True
 
bool ignore_unknown_options = False
 

Detailed Description

The base command implements the minimal API contract of commands.
Most code will never use this as it does not implement a lot of useful
functionality but it can act as the direct subclass of alternative
parsing methods that do not depend on the Click parser.

For instance, this can be used to bridge Click and other systems like
argparse or docopt.

Because base commands do not implement a lot of the API that other
parts of Click take for granted, they are not supported for all
operations.  For instance, they cannot be used with the decorators
usually and they have no built-in callback system.

.. versionchanged:: 2.0
   Added the `context_settings` parameter.

:param name: the name of the command to use unless a group overrides it.
:param context_settings: an optional dictionary with defaults that are
                         passed to the context object.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name,
  context_settings = None 
)

Member Function Documentation

◆ __call__()

def __call__ (   self,
args,
**  kwargs 
)
Alias for :meth:`main`.

◆ __repr__()

def __repr__ (   self)

◆ get_help()

def get_help (   self,
  ctx 
)

Reimplemented in Command.

◆ get_usage()

def get_usage (   self,
  ctx 
)

Reimplemented in Command.

◆ invoke()

def invoke (   self,
  ctx 
)
Given a context, this invokes the command.  The default
implementation is raising a not implemented error.

Reimplemented in MultiCommand, and Command.

◆ main()

def main (   self,
  args = None,
  prog_name = None,
  complete_var = None,
  standalone_mode = True,
**  extra 
)
This is the way to invoke a script with all the bells and
whistles as a command line application.  This will always terminate
the application after a call.  If this is not wanted, ``SystemExit``
needs to be caught.

This method is also available by directly calling the instance of
a :class:`Command`.

.. versionadded:: 3.0
   Added the `standalone_mode` flag to control the standalone mode.

:param args: the arguments that should be used for parsing.  If not
     provided, ``sys.argv[1:]`` is used.
:param prog_name: the program name that should be used.  By default
          the program name is constructed by taking the file
          name from ``sys.argv[0]``.
:param complete_var: the environment variable that controls the
             bash completion support.  The default is
             ``"_<prog_name>_COMPLETE"`` with prog_name in
             uppercase.
:param standalone_mode: the default behavior is to invoke the script
                in standalone mode.  Click will then
                handle exceptions and convert them into
                error messages and the function will never
                return but shut down the interpreter.  If
                this is set to `False` they will be
                propagated to the caller and the return
                value of this function is the return value
                of :meth:`invoke`.
:param extra: extra keyword arguments are forwarded to the context
      constructor.  See :class:`Context` for more information.

◆ make_context()

def make_context (   self,
  info_name,
  args,
  parent = None,
**  extra 
)
This function when given an info name and arguments will kick
off the parsing and create a new :class:`Context`.  It does not
invoke the actual command callback though.

:param info_name: the info name for this invokation.  Generally this
          is the most descriptive name for the script or
          command.  For the toplevel script it's usually
          the name of the script, for commands below it it's
          the name of the script.
:param args: the arguments to parse as list of strings.
:param parent: the parent context if available.
:param extra: extra keyword arguments forwarded to the context
      constructor.

◆ parse_args()

def parse_args (   self,
  ctx,
  args 
)
Given a context and a list of arguments this creates the parser
and parses the arguments, then modifies the context as necessary.
This is automatically invoked by :meth:`make_context`.

Reimplemented in MultiCommand, and Command.

Field Documentation

◆ allow_extra_args

bool allow_extra_args = False
static

◆ allow_interspersed_args

bool allow_interspersed_args = True
static

◆ context_settings

context_settings

◆ ignore_unknown_options

bool ignore_unknown_options = False
static

◆ name

name

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