File: argparseformatter.py

package info (click to toggle)
drgn 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,852 kB
  • sloc: python: 74,992; ansic: 54,589; awk: 423; makefile: 351; sh: 99
file content (34 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later

import argparse
from typing import List


class MultilineHelpFormatter(argparse.HelpFormatter):
    """
    argparse help formatter that supports multiple paragraphs/line blocks and
    doesn't collapse consecutive whitespace.

    '''
    This is a paragraph, which will
    be wrapped.

    |This is a line block.
    |It will not be wrapped.
    '''

    See :func:`_drgn_util.multilinewrap.multiline_wrap()` for details.
    """

    def _split_lines(self, text: str, width: int) -> List[str]:
        # argparse makes a point of not importing textwrap unless necessary, so
        # we do the same.
        from _drgn_util.multilinewrap import multiline_wrap

        return multiline_wrap(text, width, indent="")

    def _fill_text(self, text: str, width: int, indent: str) -> str:
        from _drgn_util.multilinewrap import multiline_fill

        return multiline_fill(text, width, indent=indent)