-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Labels
Description
Currently, it appears there's no way to take an arbitrary number of positional arguments when parsing settings from the command line. This is a blocker for me, migrating over from typer.
The closest you can get it by doing the following:
# test.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.values)However, this requires you to run it like python test.py a,b,c or python test.py '["a", "b", "c"]' rather than simply python test.py a b c, which usually makes more sense if the command only takes in a single list of values.
It would be nice to have something like a CliPositionalArgs type to support this:
# test.py
from pydantic_settings import BaseSettings, CliPositionalArgs, SettingsConfigDict
class Main(BaseSettings):
model_config = SettingsConfigDict(
cli_parse_args=True,
cli_enforce_required=True,
)
values: CliPositionalArgs[list[str]]
parsed = Main()
print(parsed.values)