Thank you so much for implementing #519!
However, i've pulled down the changes for testing, and did notice that there doesn't seem to be a way to have a command accept an arbitrary number of positional arguments that can be empty.
# File: example.py
from pydantic_settings import BaseSettings, CliPositionalArg, SettingsConfigDict
class Main(BaseSettings):
model_config = SettingsConfigDict(
cli_parse_args=True,
cli_enforce_required=True,
)
values: CliPositionalArg[list[str]]
parsed = Main()
print(parsed)
Output when running as python example.py:
usage: that.py [-h] VALUES
example.py: error: the following arguments are required: VALUES
So, to work around this I've tried using both values: CliPositionalArg[list[str]] = [] and values: CliPositionalArg[list[str] | None] = None instead, but both result in pydantic_settings.sources.SettingsError: positional argument Main.values has a default value.
My use case is similar to a command like docker compose up, where when no positional arguments are passed there's different behavior.
docker compose up # Run all services.
docker compose up my-app postgres # Run specific services.
Thank you so much for implementing #519!
However, i've pulled down the changes for testing, and did notice that there doesn't seem to be a way to have a command accept an arbitrary number of positional arguments that can be empty.
Output when running as
python example.py:So, to work around this I've tried using both
values: CliPositionalArg[list[str]] = []andvalues: CliPositionalArg[list[str] | None] = Noneinstead, but both result inpydantic_settings.sources.SettingsError: positional argument Main.values has a default value.My use case is similar to a command like
docker compose up, where when no positional arguments are passed there's different behavior.