Skip to content

Feature request: better support for argumentless CLI boolean flags #361

@keysmashes

Description

@keysmashes

Currently, you can declare a model like this:

class Settings(BaseSettings):
    dry_run: bool = False
    model_config = SettingsConfigDict(
        cli_parse_args=True,
        alias_generator=AliasGenerator(
            validation_alias=lambda s: AliasChoices(s, to_snake(s).replace("_", "-"))
        ),
    )

and end up with an application you can run in dry-run mode by running myapp --dry-run=true. But this is not exactly what is usually expected of CLI applications; usually, boolean flags are argumentless (--dry-run, --force, etc.) and their presence implies the associated value is true. Sometimes they have an inverse like --no-dry-run which implies the opposite.

I don't think pydantic-settings currently supports arguments like this. It would be very useful if it did :)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions