Andy Mikhailenko avatar Andy Mikhailenko committed a808ddc

Removed the previously deprecated argument "intercept" in the dispatch() helper. Replaced a "magic number" with a constant in the wrap_errors() decorator.

Comments (0)

Files changed (1)

 ]
 def add_commands(parser, functions, namespace=None, title=None,
                  description=None, help=None):
-    """Adds given functions as commands to given parser.
+     decorator"""Adds given functions as commands to given parser.
 
     :param parser:
 
         command_parser.set_defaults(function=func)
 
 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`
+    decorator.
     """
-    # TODO: can be safely removed at version ~= 0.14
-    if intercept: # PRAGMA: NOCOVER
-        import warnings
-        warnings.warn('dispatch(intercept=True) is deprecated, use '
-                      'dispatch(output_file=None).', DeprecationWarning)
-        output_file = None
-
     if completion:
         autocomplete(parser)
 
     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.
     """
     def wrapper(func):
-        func.argh_wrap_errors = exceptions
+        setattr(func, ATTR_WRAPPED_EXCEPTIONS, exceptions)
         return func
     return wrapper
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.