|
8 | 8 | from rich_argparse import HelpPreviewAction, RichHelpFormatter
|
9 | 9 |
|
10 | 10 | if __name__ == "__main__":
|
11 |
| - RichHelpFormatter.highlights.append(r"(?:^|\s)-{1,2}[\w]+[\w-]* (?P<metavar>METAVAR)\b") |
12 | 11 | parser = argparse.ArgumentParser(
|
13 | 12 | prog="python -m rich_argparse",
|
14 | 13 | formatter_class=RichHelpFormatter,
|
|
17 | 16 | "[link https://docs.python.org/3/library/argparse.html#formatter-class]"
|
18 | 17 | "argparse's help output[/].\n\n"
|
19 | 18 | "It enables you to use the powers of rich like markup and highlights in your CLI help. "
|
20 |
| - "Read below for a glance at available features." |
21 | 19 | ),
|
22 | 20 | epilog=":link: Read more at https://github.com/hamdanal/rich-argparse#usage.",
|
23 | 21 | )
|
24 | 22 | parser.add_argument(
|
25 | 23 | "formatter-class",
|
26 | 24 | help=(
|
27 |
| - "All you need to make your argparse.ArgumentParser output colorful text like this is to " |
28 |
| - "pass it `formatter_class=RichHelpFormatter` or any of the available variants." |
| 25 | + "Simply pass `formatter_class=RichHelpFormatter` to the argument parser to get a " |
| 26 | + "colorful help like this." |
29 | 27 | ),
|
30 | 28 | )
|
31 | 29 | parser.add_argument(
|
32 | 30 | "styles",
|
33 |
| - help=( |
34 |
| - "All the styles used by this formatter are defined in `RichHelpFormatter.styles`. " |
35 |
| - "Modify this dictionary with any rich style to change the look of your CLI's help text." |
36 |
| - ), |
| 31 | + help="Customize your CLI's help with the `RichHelpFormatter.styles` dictionary.", |
37 | 32 | )
|
38 | 33 | parser.add_argument(
|
39 | 34 | "--highlights",
|
|
53 | 48 | ),
|
54 | 49 | )
|
55 | 50 | parser.add_argument(
|
56 |
| - "-s", |
57 |
| - "--long-option", |
| 51 | + "-o", |
| 52 | + "--option", |
58 | 53 | metavar="METAVAR",
|
59 |
| - help=( |
60 |
| - "Words that look like --command-line-options are highlighted using the `argparse.args` " |
61 |
| - "style. In addition, this example, adds a highlighter regex for the word 'METAVAR' " |
62 |
| - "following an option for the sake of demonstrating custom highlights.\n" |
63 |
| - "Notice also that if an option takes a value and has short and long options, it is " |
64 |
| - "printed as -s, --long-option METAVAR instead of -s METAVAR, --long-option METAVAR." |
65 |
| - ), |
| 54 | + help="Text that looks like an --option is highlighted using the `argparse.args` style.", |
66 | 55 | )
|
67 | 56 | group = parser.add_argument_group(
|
68 | 57 | "more arguments",
|
|
0 commit comments