PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/argh/helpers.py

https://bitbucket.org/neithere/argh/
Python | 53 lines | 20 code | 9 blank | 24 comment | 0 complexity | b4fb09773862ccd6638f7a87f6f71058 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2#
 3#  Copyright (c) 2010—2013 Andrey Mikhaylenko and contributors
 4#
 5#  This file is part of Argh.
 6#
 7#  Argh is free software under terms of the GNU Lesser
 8#  General Public License version 3 (LGPLv3) as published by the Free
 9#  Software Foundation. See the file README for copying conditions.
10#
11"""
12Helpers
13~~~~~~~
14"""
15import argparse
16
17from argh.completion import autocomplete
18from argh.assembling import add_commands, set_default_command
19from argh.dispatching import PARSER_FORMATTER, dispatch
20
21
22__all__ = ['ArghParser']
23
24
25class ArghParser(argparse.ArgumentParser):
26    """ A subclass of :class:`ArgumentParser` with a couple of convenience
27    methods.
28
29    There is actually no need to subclass the parser. The methods are but
30    wrappers for stand-alone functions :func:`~argh.assembling.add_commands`,
31    :func:`~argh.completion.autocomplete` and
32    :func:`~argh.dispatching.dispatch`.
33
34    Uses :attr:`~argh.dispatching.PARSER_FORMATTER`.
35    """
36    def __init__(self, *args, **kwargs):
37        kwargs.setdefault('formatter_class', PARSER_FORMATTER)
38        super(ArghParser, self).__init__(*args, **kwargs)
39
40    def set_default_command(self, *args, **kwargs):
41        "Wrapper for :func:`set_default_command`."
42        return set_default_command(self, *args, **kwargs)
43
44    def add_commands(self, *args, **kwargs):
45        "Wrapper for :func:`add_commands`."
46        return add_commands(self, *args, **kwargs)
47
48    def autocomplete(self):
49        return autocomplete(self)
50
51    def dispatch(self, *args, **kwargs):
52        "Wrapper for :func:`dispatch`."
53        return dispatch(self, *args, **kwargs)