def __call__(self, *args, **kwargs):
error_handler    = self.error_handler<EOL>compile          = self.compile<EOL>compiler_factory = self.compiler_factory<EOL>_locals = locals()<EOL>for k in [k for k in kwargs.keys()]:<EOL><INDENT>if hasattr(self, '<STR_LIT>'+k):<EOL><INDENT>setattr(self, '<STR_LIT>'+k, kwargs.pop(k))<EOL><DEDENT>elif hasattr(self, k):<EOL><INDENT>if k in _locals:<EOL><INDENT>_locals[k] = kwargs.pop(k)<EOL><DEDENT><DEDENT><DEDENT>argv=None<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>argv = kwargs.pop('<STR_LIT>')<EOL><DEDENT>self.command.update(**kwargs)<EOL>def _exit(result=<NUM_LIT:0>, message=None):<EOL><INDENT>raise ArgParseExit(result, message)<EOL><DEDENT>self.command.update(exit=_exit)<EOL>if len(args) == <NUM_LIT:1> and isfunction(args[<NUM_LIT:0>]):<EOL><INDENT>self.main_function = args[<NUM_LIT:0>]<EOL>return args[<NUM_LIT:0>]<EOL><DEDENT>for a in args:<EOL><INDENT>if isinstance(a, arg):<EOL><INDENT>self.command.add_argument(a)<EOL><DEDENT>else:<EOL><INDENT>if argv is None:<EOL><INDENT>argv = []<EOL><DEDENT>argv.append(a)<EOL><DEDENT><DEDENT>if argv is not None and self.main_function is None and not self.command.has_action():<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if argv is None and self.main_function is None and not self.command.has_action():<EOL><INDENT>return self<EOL><DEDENT>self.exception = None<EOL>self.init_managed_args()<EOL>try:<EOL><INDENT>return error_handler(self.command.execute(argv, compile=compile, preprocessor=self.store_args, compiler_factory=compiler_factory))<EOL><DEDENT>except an_exception as e:<EOL><INDENT>logger = logging.getLogger()<EOL>logger.debug("<STR_LIT>", self.debug, exc_info=<NUM_LIT:1>)<EOL>if self.verbosity:<EOL><INDENT>import traceback<EOL>traceback.print_exc()<EOL><DEDENT>elif not self.quiet:<EOL><INDENT>if PY3:<EOL><INDENT>sys.stderr.write("<STR_LIT>" % e)<EOL><DEDENT>else:<EOL><INDENT>sys.stderr.write((u"<STR_LIT>" % e).encode('<STR_LIT:utf-8>'))<EOL><DEDENT><DEDENT>self.exception = e<EOL>if hasattr(e, '<STR_LIT>'):<EOL><INDENT>return error_handler(e.error_code)<EOL><DEDENT>else:<EOL><INDENT>return error_handler(self.error_code)<EOL><DEDENT><DEDENT>
You can call :py:class:`~argdeco.main.Main` instance in various ways.  As function or
as decorator.   As long you did not have decorated a function with this
:py:class:`~argdeco.main.Main` instance, you can invoke it as function for confiugration.

As soon there is defined some action, invoking the instance, will execute
the actions.

Configure some global arguments::

    main(
        arg('--global', '-g', help="a global argument"),
    )

Decorate a function to be called as main function::

    @main
    def my_main():
        return 0

    if __name__ == "__main__":
        main()

Decorate a function to be main function and define arguments of it::

    @main(
        arg('--first', '-f', help="first argument"),
        arg('--second', '-s', help="second argument"),
    )
    def main(first, second):
        return 0   # successful

    if __name__ == "__main__":
        main(debug=True)

:param \*args:
    All arguments of type :py:class:`~argdeco.command_decorator.arg` are filtered out and added
    as global argument to underlying
    :py:class:`~argdeco.command_decorator.CommandDecorator` instance.

    All other arguments are collected -- if any to be `argv`.  If
    there are any other parameters, this function switches into regular
    `main` mode and will execute the main function passing `argv`.  If
    there are no arguments defined, :py:attr:`sys.argv` is used as
    default.

:param \*\*kwargs:
    You can pass various keyword arguments to tweak behaviour of the
    main function.

    :argv:
        You can set explicitly the ``argv`` vector.  This becomes handy,
        if you want to pass an empty ``argv`` list and do not want to
        use the default sys.argv.

    :debug:
        Turn on debug argument, see :py:class:`~argdeco.main.Main` for more info.

    :verbosity:
        Turn on verbose argument, see :py:class:`~argdeco.main.Main` for more info.

    :quiet:
        Turn on quiet argument, see :py:class:`~argdeco.main.Main` for more info.

    :error_handler:
        Tweak the error handler.  This will be only local to this call.

    :compile:
        Set compile for this call.

    :compiler_factory:
        Set compiler_factory for this call.

:return:
    :Decorator mode:
        Returns the instance itself, to be invoked as decorator.
    :Run mode:
        Returns whatever error_handler returns, when getting the return
        value of the invoked action function