Unverified Commit 63f2b9ab authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Print defaults when using --help for scripts (#12930)

parent 3ec851dc
...@@ -16,7 +16,7 @@ import dataclasses ...@@ -16,7 +16,7 @@ import dataclasses
import json import json
import re import re
import sys import sys
from argparse import ArgumentParser, ArgumentTypeError from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from typing import Any, Iterable, List, NewType, Optional, Tuple, Union from typing import Any, Iterable, List, NewType, Optional, Tuple, Union
...@@ -59,6 +59,9 @@ class HfArgumentParser(ArgumentParser): ...@@ -59,6 +59,9 @@ class HfArgumentParser(ArgumentParser):
kwargs: kwargs:
(Optional) Passed to `argparse.ArgumentParser()` in the regular way. (Optional) Passed to `argparse.ArgumentParser()` in the regular way.
""" """
# To make the default appear when using --help
if "formatter_class" not in kwargs:
kwargs["formatter_class"] = ArgumentDefaultsHelpFormatter
super().__init__(**kwargs) super().__init__(**kwargs)
if dataclasses.is_dataclass(dataclass_types): if dataclasses.is_dataclass(dataclass_types):
dataclass_types = [dataclass_types] dataclass_types = [dataclass_types]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment