forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg.py
36 lines (30 loc) · 1.32 KB
/
arg.py
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
35
36
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""Argument parsing related helper classes and functions."""
import argparse
import textwrap
class RawDescriptionDefaultHelpFormatter(
argparse.RawDescriptionHelpFormatter,
argparse.ArgumentDefaultsHelpFormatter
):
"""
Adds default values to argument help and retains any formatting in
descriptions.
"""
def _split_lines(self, text, width):
""" Split the lines.
If the text parameter starts with 'R|' it will keep whitespaces and
it will wrapp the content. Otherwise it will call the parent function
of RawDescriptionHelpFormatter.
"""
if text.startswith('R|'):
lines = [textwrap.wrap(line, width, replace_whitespace=False)
for line in text[2:].lstrip().splitlines()]
return [line for sublines in lines for line in sublines]
return argparse.RawDescriptionHelpFormatter._split_lines(self, text,
width)