'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.'

def main(self, args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra):

    if (not PY2):
        _verify_python3_env()
    else:
        _check_for_unicode_literals()
    if (args is None):
        args = get_os_args()
    else:
        args = list(args)
    if (prog_name is None):
        prog_name = make_str(os.path.basename(((sys.argv and sys.argv[0]) or __file__)))
    _bashcomplete(self, prog_name, complete_var)
    try:
        try:
            with self.make_context(prog_name, args, **extra) as ctx:
                rv = self.invoke(ctx)
                if (not standalone_mode):
                    return rv
                ctx.exit()
        except (EOFError, KeyboardInterrupt):
            echo(file=sys.stderr)
            raise Abort()
        except ClickException as e:
            if (not standalone_mode):
                raise
            e.show()
            sys.exit(e.exit_code)
        except IOError as e:
            if (e.errno == errno.EPIPE):
                sys.exit(1)
            else:
                raise
    except Abort:
        if (not standalone_mode):
            raise
        echo('Aborted!', file=sys.stderr)
        sys.exit(1)
