def dispatch(parser, argv=None, add_help_command=True,<EOL>completion=True, pre_call=None,<EOL>output_file=sys.stdout, errors_file=sys.stderr,<EOL>raw_output=False, namespace=None,<EOL>skip_unknown_args=False):
if completion:<EOL><INDENT>autocomplete(parser)<EOL><DEDENT>if argv is None:<EOL><INDENT>argv = sys.argv[<NUM_LIT:1>:]<EOL><DEDENT>if add_help_command:<EOL><INDENT>if argv and argv[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>argv.pop(<NUM_LIT:0>)<EOL>argv.append('<STR_LIT>')<EOL><DEDENT><DEDENT>if skip_unknown_args:<EOL><INDENT>parse_args = parser.parse_known_args<EOL><DEDENT>else:<EOL><INDENT>parse_args = parser.parse_args<EOL><DEDENT>if not namespace:<EOL><INDENT>namespace = ArghNamespace()<EOL><DEDENT>namespace_obj = parse_args(argv, namespace=namespace)<EOL>function = _get_function_from_namespace_obj(namespace_obj)<EOL>if function:<EOL><INDENT>lines = _execute_command(function, namespace_obj, errors_file,<EOL>pre_call=pre_call)<EOL><DEDENT>else:<EOL><INDENT>lines = [parser.format_usage()]<EOL><DEDENT>if output_file is None:<EOL><INDENT>if sys.version_info < (<NUM_LIT:3>,<NUM_LIT:0>):<EOL><INDENT>f = compat.BytesIO()<EOL><DEDENT>else:<EOL><INDENT>f = compat.StringIO()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>f = output_file<EOL><DEDENT>for line in lines:<EOL><INDENT>io.dump(line, f)<EOL>if not raw_output:<EOL><INDENT>io.dump('<STR_LIT:\n>', f)<EOL><DEDENT><DEDENT>if output_file is None:<EOL><INDENT>f.seek(<NUM_LIT:0>)<EOL>return f.read()<EOL><DEDENT>
Parses given list of arguments using given parser, calls the relevant
function and prints the result.

The target function should expect one positional argument: the
:class:`argparse.Namespace` object. However, if the function is decorated with
:func:`~argh.decorators.plain_signature`, the positional and named
arguments from the namespace object are passed to the function instead
of the object itself.

:param parser:

    the ArgumentParser instance.

:param argv:

    a list of strings representing the arguments. If `None`, ``sys.argv``
    is used instead. Default is `None`.

:param add_help_command:

    if `True`, converts first positional argument "help" to a keyword
    argument so that ``help foo`` becomes ``foo --help`` and displays usage
    information for "foo". Default is `True`.

:param output_file:

    A file-like object for output. If `None`, the resulting lines are
    collected and returned as a string. Default is ``sys.stdout``.

:param errors_file:

    Same as `output_file` but for ``sys.stderr``.

:param raw_output:

    If `True`, results are written to the output file raw, without adding
    whitespaces or newlines between yielded strings. Default is `False`.

:param completion:

    If `True`, shell tab completion is enabled. Default is `True`. (You
    will also need to install it.)  See :mod:`argh.completion`.

:param skip_unknown_args:

    If `True`, unknown arguments do not cause an error
    (`ArgumentParser.parse_known_args` is used).

:param namespace:

    An `argparse.Namespace`-like object.  By default an
    :class:`ArghNamespace` object is used.  Please note that support for
    combined default and nested functions may be broken if a different
    type of object is forced.

By default the exceptions are not wrapped and will propagate. The only
exception that is always wrapped is :class:`~argh.exceptions.CommandError`
which is interpreted as an expected event so the traceback is hidden.
You can also mark arbitrary exceptions as "wrappable" by using the
:func:`~argh.decorators.wrap_errors` decorator.