Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pydantic_settings/sources/providers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ def _add_parser_args(
help=subcommand_help,
formatter_class=self._formatter_class,
description=None if model.__doc__ is None else dedent(model.__doc__),
allow_abbrev=False,
),
model=model,
added_args=[],
Expand Down
19 changes: 19 additions & 0 deletions tests/test_source_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,25 @@ class MySettings(BaseSettings):
)


def test_cli_subcommand_invalid_abbrev():
class Child(BaseModel):
bacon: str = ''
badger: str = ''

class MySettings(BaseSettings):
child: CliSubCommand[Child]

with pytest.raises(
SettingsError,
match='error parsing CLI: unrecognized arguments: --bac cli abbrev are invalid for internal parser',
):
CliApp.run(
MySettings,
cli_args=['child', '--bac', 'cli abbrev are invalid for internal parser'],
cli_exit_on_error=False,
)


def test_cli_submodels_strip_annotated():
class PolyA(BaseModel):
a: int = 1
Expand Down
Loading