Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default values for CliPositionalArg when parsing from the CLI #517

Open
jploskey opened this issue Jan 8, 2025 · 4 comments · May be fixed by #519
Open

Support default values for CliPositionalArg when parsing from the CLI #517

jploskey opened this issue Jan 8, 2025 · 4 comments · May be fixed by #519
Assignees

Comments

@jploskey
Copy link

jploskey commented Jan 8, 2025

Currently, there doesn't appear to be a way to have an optional positional argument when parsing settings from the CLI. This is a blocker for me, trying to migrate over from typer.

Running the following will result in this error: pydantic_settings.sources.SettingsError: positional argument BaseMainCommand.value has a default value

from pydantic_settings import BaseSettings, CliPositionalArg, SettingsConfigDict


class Main(BaseSettings):
    model_config = SettingsConfigDict(
        cli_parse_args=True,
        cli_enforce_required=True,
    )

    value: CliPositionalArg[int | None] = None


parsed = Main() # Error is raised here.
print(parsed.value)
@hramezani
Copy link
Member

@kschwab can you take a look?

@kschwab kschwab linked a pull request Jan 10, 2025 that will close this issue
@kschwab
Copy link
Contributor

kschwab commented Jan 10, 2025

@jploskey @hramezani opened #519 for resolution 👍🏾

@hramezani
Copy link
Member

Thanks @kschwab for the PR. @jploskey could you confirm the fix?

@jploskey
Copy link
Author

@hramezani @kschwab I can confirm the fix works! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants