Did I find the right examples for you? yes no

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)
Returns the :class:`argparse._SubParsersAction` instance for given
:class:`ArgumentParser` instance as would have been returned by
:meth:`ArgumentParser.add_subparsers`. The problem with the latter is that
it only works once and raises an exception on the second attempt, and the
public API seems to lack a method to get *existing* subparsers.

:param create:
    If `True`, creates the subparser if it does not exist. Default if
    `False`.

        def get_subparsers(parser, create=False):
    """Returns the :class:`argparse._SubParsersAction` instance for given
    :class:`ArgumentParser` instance as would have been returned by
    :meth:`ArgumentParser.add_subparsers`. The problem with the latter is that
    it only works once and raises an exception on the second attempt, and the
    public API seems to lack a method to get *existing* subparsers.

    :param create:
        If `True`, creates the subparser if it does not exist. Default if
        `False`.

    """
    # note that ArgumentParser._subparsers is *not* what is returned by
    # ArgumentParser.add_subparsers().
    if parser._subparsers:
        actions = [a for a in parser._actions
                   if isinstance(a, argparse._SubParsersAction)]
        assert len(actions) == 1
        return actions[0]
    else:
        if create:
            return parser.add_subparsers()
        


src/a/r/argh-0.24.1/argh/assembling.py   argh(Download)
                            ATTR_EXPECTS_NAMESPACE_OBJECT,
                            PARSER_FORMATTER)
from argh.utils import get_subparsers, get_arg_spec
from argh.exceptions import AssemblingError
 
        raise RuntimeError('Cannot add commands to a single-command parser')
 
    subparsers = get_subparsers(parser, create=True)
 
    if namespace:

src/a/r/argh-HEAD/argh/assembling.py   argh(Download)
                            ATTR_EXPECTS_NAMESPACE_OBJECT,
                            PARSER_FORMATTER)
from argh.utils import get_subparsers, get_arg_spec
from argh.exceptions import AssemblingError
 
        raise RuntimeError('Cannot add commands to a single-command parser')
 
    subparsers = get_subparsers(parser, create=True)
 
    if namespace: