Skip to content

Commit e70273a

Browse files
authored
docs: Enhance help formatter to preserve epilog formatting and add usage links in argument parser (#2682)
1 parent 5c25e38 commit e70273a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/datamodel_code_generator/arguments.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import json
1111
import locale
12-
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction, HelpFormatter, Namespace
12+
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction, Namespace, RawDescriptionHelpFormatter
1313
from operator import attrgetter
1414
from pathlib import Path
1515
from typing import TYPE_CHECKING, cast
@@ -62,8 +62,8 @@ def _dataclass_arguments(value: str) -> DataclassArguments:
6262
return cast("DataclassArguments", result)
6363

6464

65-
class SortingHelpFormatter(HelpFormatter):
66-
"""Help formatter that sorts arguments and adds color to section headers."""
65+
class SortingHelpFormatter(RawDescriptionHelpFormatter):
66+
"""Help formatter that sorts arguments, adds color to section headers, and preserves epilog formatting."""
6767

6868
def _bold_cyan(self, text: str) -> str: # noqa: PLR6301
6969
"""Wrap text in ANSI bold cyan escape codes."""
@@ -81,7 +81,10 @@ def start_section(self, heading: str | None) -> None:
8181

8282
arg_parser = ArgumentParser(
8383
usage="\n datamodel-codegen [options]",
84-
description="Generate Python data models from schema definitions or structured data",
84+
description="Generate Python data models from schema definitions or structured data\n\n"
85+
"For detailed usage, see: https://koxudaxi.github.io/datamodel-code-generator",
86+
epilog="Documentation: https://koxudaxi.github.io/datamodel-code-generator\n"
87+
"GitHub: https://github.com/koxudaxi/datamodel-code-generator",
8588
formatter_class=SortingHelpFormatter,
8689
add_help=False,
8790
)

0 commit comments

Comments
 (0)