I was looking to do something like this, but for a Django management command: Python argparse: How to insert newline in the help text?
From the documentation
You can customize the instance by overriding this method and calling super() with kwargs of ArgumentParser parameters.
By overriding create_parser
method
you can set the formatter_class
of the ArgumentParser
:
from argparse import RawTextHelpFormatter
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def create_parser(self, *args, **kwargs):
parser = super(Command, self).create_parser(*args, **kwargs)
parser.formatter_class = RawTextHelpFormatter
return parser