Skip to content

How do you use an enum value in --help instead of the member name? #685

@Digity101

Description

@Digity101

So I use an enum for some configuration and some enums have a _ in the member field like example_a which shows up in the --help message. I want to display the enum value example-a instead. Is there a way to do this?
I tried use_enum_values=True and to define a __str__ in the enum class, but that doesnt work.

Minimum code to reproduce:

from enum import StrEnum

from pydantic_settings import BaseSettings, SettingsConfigDict


class Example(StrEnum):
    example_a = "example-a"
    example_b = "example-b"


class Settings(BaseSettings):
    example: Example

    model_config = SettingsConfigDict(cli_parse_args=True)


if __name__ == "__main__":
    settings = Settings()

Current output

python main.py --help
usage: main.py [-h] [--example {example_a,example_b}]

options:
  -h, --help            show this help message and exit
  --example {example_a,example_b}
                        (required)

Desired output

python main.py --help
usage: main.py [-h] [--example {example_a,example_b}]

options:
  -h, --help            show this help message and exit
  --example {example-a,example-b}
                        (required)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions