def add_commands(parser, functions, namespace=None, title=None,
- """Adds given functions as commands to given parser.
+ """Adds given functions as commands to given parser.
def dispatch(parser, argv=None, add_help_command=True, encoding=None,
- intercept=False, completion=True, pre_call=None,
- output_file=sys.stdout, raw_output=False, namespace=None):
+ completion=True, pre_call=None, output_file=sys.stdout,
+ raw_output=False, namespace=None):
"""Parses given list of arguments using given parser, calls the relevant
function and prints the result.
If `True`, shell tab completion is enabled. Default is `True`. (You
will also need to install it.)
- Exceptions are not wrapped and will propagate. The only exception among the
- exceptions is :class:`CommandError` which is interpreted as an expected
- event so the traceback is hidden. See also :func:`wrap_errors`.
+ By default the exceptions are not wrapped and will propagate. The only
+ exception that is always wrapped is :class:`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:`wrap_errors`
- # TODO: can be safely removed at version ~= 0.14
- if intercept: # PRAGMA: NOCOVER
- warnings.warn('dispatch(intercept=True) is deprecated, use '
- 'dispatch(output_file=None).', DeprecationWarning)
approaches to calling the function (with an `argparse.Namespace` object or
with ordinary signature). Yields the results line by line. If CommandError
is raised, its message is appended to the results (i.e. yielded by the
- generator as a string). All other exceptions propagate.
+ generator as a string). All other exceptions propagate unless marked as
+ wrappable by :func:`wrap_errors`.
assert hasattr(args, 'function') and hasattr(args.function, '__call__')
stack hidden. This helps to avoid boilerplate code.
func.argh_wrap_errors = exceptions