Skip to content

Commit

Permalink
Disable abbreviations on internal parser. (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
kschwab authored Nov 12, 2024
1 parent b4ece52 commit e8a15b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ def __init__(
description=None if settings_cls.__doc__ is None else dedent(settings_cls.__doc__),
formatter_class=formatter_class,
prefix_chars=self.cli_flag_prefix_char,
allow_abbrev=False,
)
if root_parser is None
else root_parser
Expand Down
14 changes: 14 additions & 0 deletions tests/test_source_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,3 +2223,17 @@ class SettingsInvalidReqCircleReqField(BaseModel):

with pytest.raises(ValueError, match='mutually exclusive arguments must be optional'):
CliApp.run(SettingsInvalidReqCircleReqField)


def test_cli_invalid_abbrev():
class MySettings(BaseSettings):
bacon: str = ''
badger: str = ''

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

0 comments on commit e8a15b0

Please sign in to comment.