python类HelpFormatter()的实例源码

shell.py 文件源码 项目:eclcli 作者: nttcom 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, prog, indent_increment=2, max_help_position=32,
                 width=None):
        super(HelpFormatter, self).__init__(prog, indent_increment,
                                            max_help_position, width)
shell.py 文件源码 项目:eclcli 作者: nttcom 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def start_section(self, heading):
        # Title-case the headings
        heading = '%s%s' % (heading[0].upper(), heading[1:])
        super(HelpFormatter, self).start_section(heading)
main.py 文件源码 项目:devpi 作者: devpi 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def error(self, error):
        """raise errors instead of printing and raising SystemExit"""
        raise self.ArgumentError(error)

    #def __init__(self, *args, **kwargs):
    #    kwargs["formatter_class"] = MyHelpFormatter
    #    argparse.ArgumentParser.__init__(self, *args, **kwargs)

#class MyHelpFormatter(argparse.HelpFormatter):
#    pass
test_main.py 文件源码 项目:python-cratonclient 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_get_base_parser(self):
        """Verify how we construct our basic Argument Parser."""
        with mock.patch('argparse.ArgumentParser') as ArgumentParser:
            parser = self.shell.get_base_parser()

        self.assertEqual(ArgumentParser.return_value, parser)
        ArgumentParser.assert_called_once_with(
            prog='craton',
            description=('Main shell for parsing arguments directed toward '
                         'Craton.'),
            epilog='See "craton help COMMAND" for help on a specific command.',
            add_help=False,
            formatter_class=argparse.HelpFormatter,
        )
config.py 文件源码 项目:builds 作者: open-power-host-os 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        if text.startswith(RAW_TEXT_ID):
            return text[len(RAW_TEXT_ID):].splitlines()
        # this is the RawTextHelpFormatter._split_lines
        return argparse.HelpFormatter._split_lines(self, text, width)
signet.py 文件源码 项目:signet-python 作者: signet-org 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        argparse.HelpFormatter.__init__(self, *args, **kwargs)
        self._action_max_length = 18
compute_contigs_compatibility.py 文件源码 项目:matam 作者: bonsai-team 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def parse_arguments():
    """
    Parse the command line, and check if arguments are correct
    """
    # Initiate argument parser
    parser = DefaultHelpParser(description='Program description',
                               # to precisely format help display
                               formatter_class=lambda prog: argparse.HelpFormatter(prog, width=120, max_help_position=80))

    # Main parameters
    group_main = parser.add_argument_group('Main parameters')
    # -i / --input_sam
    group_main.add_argument('-i', '--input_sam',
                            action = 'store',
                            metavar = 'INSAM',
                            type = argparse.FileType('r'),
                            default = '-',
                            help = 'Input sam file, sorted by subject and position')
    # -o / --output_sam
    group_main.add_argument('-o', '--output_sam',
                            action = 'store',
                            metavar = 'OUTSAM',
                            type = argparse.FileType('w'),
                            default = '-',
                            help = 'Output sam file')
    # -v / --verbose
    group_main.add_argument('-v', '--verbose',
                            action = 'store_true',
                            help = 'Increase verbosity')

    # Debug
    group_debug = parser.add_argument_group('Debug parameters')
    # --debug
    group_debug.add_argument('--debug',
                             action = 'store_true',
                             help = 'Output debug infos')

    args = parser.parse_args()

    #
    return args
clitools.py 文件源码 项目:skaff 作者: jhxie 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        if text.startswith('D|'):
            self._add_defaults = True
            text = text[2:]
        elif text.startswith('*|'):
            text = text[2:]
        if text.startswith('R|'):
            return text[2:].splitlines()
        return argparse.HelpFormatter._split_lines(self, text, width)
clitools.py 文件源码 项目:skaff 作者: jhxie 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def _get_help_string(self, action):
        if self._add_defaults is None:
            return argparse.HelpFormatter._get_help_string(self, action)
        help = action.help
        if '%(default)' not in action.help:
            if action.default is not argparse.SUPPRESS:
                defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
                if action.option_strings or action.nargs in defaulting_nargs:
                    help += ' (default: %(default)s)'
        return help
zaqar_demo.py 文件源码 项目:zaqar-demo 作者: openstacker 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def start_section(self, heading):
        # Title-case the headings
        heading = '%s%s' % (heading[0].upper(), heading[1:])
        super(HelpFormatter, self).start_section(heading)
test_argparse.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_parser(self):
        parser = argparse.ArgumentParser(prog='PROG')
        string = (
            "ArgumentParser(prog='PROG', usage=None, description=None, "
            "version=None, formatter_class=%r, conflict_handler='error', "
            "add_help=True)" % argparse.HelpFormatter)
        self.assertStringEqual(parser, string)

# ===============
# Namespace tests
# ===============
geoDL.py 文件源码 项目:geoDL 作者: jduc 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        if text.startswith('R|'):
            return text[2:].splitlines()
        # this is the RawTextHelpFormatter._split_lines
        return argparse.HelpFormatter._split_lines(self, text, width)
test_argparse.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_parser(self):
        parser = argparse.ArgumentParser(prog='PROG')
        string = (
            "ArgumentParser(prog='PROG', usage=None, description=None, "
            "formatter_class=%r, conflict_handler='error', "
            "add_help=True)" % argparse.HelpFormatter)
        self.assertStringEqual(parser, string)

# ===============
# Namespace tests
# ===============
test_argparse.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_parser(self):
        parser = argparse.ArgumentParser(prog='PROG')
        string = (
            "ArgumentParser(prog='PROG', usage=None, description=None, "
            "version=None, formatter_class=%r, conflict_handler='error', "
            "add_help=True)" % argparse.HelpFormatter)
        self.assertStringEqual(parser, string)

# ===============
# Namespace tests
# ===============
smart_formatter.py 文件源码 项目:Protector 作者: trivago 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        # this is the RawTextHelpFormatter._split_lines
        if text.startswith('R|'):
            return text[2:].splitlines()
        return argparse.HelpFormatter._split_lines(self, text, width)
argparse.py 文件源码 项目:teras 作者: chantera 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self,
                 prog=None,
                 usage=None,
                 description=None,
                 epilog=None,
                 parents=[],
                 formatter_class=argparse.HelpFormatter,
                 prefix_chars='-',
                 fromfile_prefix_chars=None,
                 argument_default=None,
                 conflict_handler='error',
                 add_help=True,
                 allow_abbrev=True):
        super(ArgumentParser, self).__init__(
            prog,
            usage,
            description,
            epilog,
            parents,
            formatter_class,
            prefix_chars,
            fromfile_prefix_chars,
            argument_default,
            conflict_handler,
            add_help,
            allow_abbrev)
        self.register('action', 'store_dict', _StoreDictAction)
        self.register('action', 'store_dict_const', _StoreDictConstAction)
argparse.py 文件源码 项目:teras 作者: chantera 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def _init_parser(self, **kwargs):
        _def = self._def
        num_groups = len(_def.groups)
        if num_groups == 0:
            raise RuntimeError("At least one command should be defined.")

        formatter_class = argparse.HelpFormatter
        if 'formatter_class' in kwargs:
            formatter_class = kwargs['formatter_class']
        parser = ArgumentParser(**kwargs)

        for name, value in _def.common_cmd_args.items():
            parser.add_argument(*value.args, **value.kwargs)

        if num_groups == 1:
            """register arguments as common"""
            group = _def.groups[0]
            for name, value in _def.grouped_cmd_args[group].items():
                parser.add_argument(*value.args, **value.kwargs)
        else:
            """register arguments as groups"""
            subparsers = parser.add_subparsers(
                title='commands', help='available commands', dest='command')
            subparsers.required = True
            for group in _def.groups:
                subparser = subparsers.add_parser(
                    group, **_def.group_descriptions[group],
                    formatter_class=formatter_class)
                for name, value in _def.grouped_cmd_args[group].items():
                    subparser.add_argument(*value.args, **value.kwargs)

        return parser
commandline_parser.py 文件源码 项目:combirepo 作者: Samsung 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        text = re.sub(man_format_remove, '', text)
        # this is the RawTextHelpFormatter._split_lines
        if text.startswith('R|'):
            return text[2:].splitlines()
        return argparse.HelpFormatter._split_lines(self, text, width)
commandline_parser.py 文件源码 项目:combirepo 作者: Samsung 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def parser_options(formatter_class=argparse.HelpFormatter):
    """
    Retrieve a customized parser to generate man page
    """
    return CommandlineParser().get_formatted_parser(formatter_class)
build_manpage.py 文件源码 项目:combirepo 作者: Samsung 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _split_lines(self, text, width):
        """
        Allows forcing newlines in lines starting with R|
        """
        if text.startswith('R|'):
            return text[2:].splitlines()
        return argparse.HelpFormatter._split_lines(self, text, width)


问题


面经


文章

微信
公众号

扫码关注公众号