@@ -53,7 +53,7 @@ parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
53
53
...
54
54
```
55
55
56
- * rich-argparse* defines equivalents to argparse's [ built-in formatters] (
56
+ * rich-argparse* defines equivalents to all argparse's [ built-in formatters] (
57
57
https://docs.python.org/3/library/argparse.html#formatter-class ):
58
58
59
59
| ` rich_argparse ` formatter | equivalent in ` argparse ` |
@@ -128,8 +128,8 @@ parser = argparse.ArgumentParser(..., formatter_class=RichHelpFormatter)
128
128
### Colors in the ` usage `
129
129
130
130
The usage ** generated by the formatter** is colored using the ` argparse.args ` and ` argparse.metavar `
131
- styles. If you use a custom ` usage ` message in the parser, it will treated as "plain text" and will
132
- ** not** be colored by default. You can enable colors in user defined usage message through
131
+ styles. If you use a custom ` usage ` message in the parser, it will be treated as "plain text" and
132
+ will ** not** be colored by default. You can enable colors in user defined usage message through
133
133
[ console markup] ( https://rich.readthedocs.io/en/stable/markup.html ) by setting
134
134
` RichHelpFormatter.usage_markup = True ` . If you enable this option, make sure to [ escape] (
135
135
https://rich.readthedocs.io/en/stable/markup.html#escaping ) any square brackets in the usage text.
@@ -151,7 +151,7 @@ and epilog.
151
151
152
152
You can use any rich renderable in the descriptions and epilog. This includes all built-in rich
153
153
renderables like ` Table ` and ` Markdown ` and any custom renderables defined using the
154
- [ Console Protcol ] ( https://rich.readthedocs.io/en/stable/protocol.html#console-protocol ) .
154
+ [ Console Protocol ] ( https://rich.readthedocs.io/en/stable/protocol.html#console-protocol ) .
155
155
156
156
``` python
157
157
import argparse
@@ -182,9 +182,6 @@ Certain features are **disabled** for arbitrary renderables other than strings,
182
182
* Styling with the ` "argparse.text" ` style defined in ` RichHelpFormatter.styles `
183
183
* Replacement of ` %(prog)s ` with the program name
184
184
185
- Arbitrary renderables are displayed "as is" except for long runs of empty lines that get truncated
186
- to two empty lines following the behavior of argparse.
187
-
188
185
## Working with subparsers
189
186
190
187
Subparsers do not inherit the formatter class from the parent parser by default. You have to pass
@@ -231,11 +228,10 @@ COLUMNS=120 python my_cli.py --generate-help-preview # force the width of the o
231
228
232
229
## Working with third party formatters
233
230
234
- * rich-argparse* can be used with other formatters that ** do not rely on the private internals**
235
- of ` argparse.HelpFormatter ` . A popular example is [ django] ( https://pypi.org/project/django ) that
236
- defines a custom help formatter that is used with its built in commands as well as with extension
237
- libraries and user defined commands. To use * rich-argparse* in your django project, change your
238
- ` manage.py ` file as follows:
231
+ * rich-argparse* can be used with other custom formatters through multiple inheritance. For example,
232
+ [ django] ( https://pypi.org/project/django ) defines a custom help formatter for its built in commands
233
+ as well as extension libraries and user defined commands. To use * rich-argparse* in your django
234
+ project, change your ` manage.py ` file as follows:
239
235
240
236
``` diff
241
237
diff --git a/my_project/manage.py b/my_project/manage.py
@@ -283,8 +279,7 @@ index 7fb6855..5e5d48a 100755
283
279
main()
284
280
```
285
281
286
- Now try out some command like ` python manage.py runserver --help ` and notice how the special
287
- ordering of the arguments applied by django is respected by the new help formatter.
282
+ Now the output of all ` python manage.py <COMMAND> --help ` will be colored.
288
283
289
284
## Optparse support
290
285
@@ -301,7 +296,7 @@ parser = optparse.OptionParser(formatter=IndentedRichHelpFormatter())
301
296
...
302
297
```
303
298
304
- You can also generated a more helpful usage message by passing ` usage=GENERATE_USAGE ` to the
299
+ You can also generate a more helpful usage message by passing ` usage=GENERATE_USAGE ` to the
305
300
parser. This is similar to the default behavior of ` argparse ` .
306
301
307
302
``` python
@@ -322,12 +317,10 @@ Syntax highlighting works the same as with `argparse`.
322
317
323
318
Colors in the ` usage ` are only supported when using ` GENERATE_USAGE ` .
324
319
325
- Customizing the group name format is not supported. optparse uses Title Case format by default.
326
-
327
320
## Legacy Windows support
328
321
329
- If your application still runs on legacy Windows versions (older than Windows 10), you'll need to
330
- enable ANSI escape sequences by calling ` colorama.init() ` otherwise colors will be disabled :
322
+ When used on legacy Windows versions like * Windows 7 * , colors are disabled unless
323
+ [ colorama] ( https://pypi.org/project/colorama/ ) is used :
331
324
332
325
``` python
333
326
import argparse
@@ -338,4 +331,3 @@ colorama.init()
338
331
parser = argparse.ArgumentParser(... , formatter_class = RichHelpFormatter)
339
332
...
340
333
```
341
- This is ** not** required on Windows 10 and newer or on other operating systems.
0 commit comments