Skip to content

Commit e8a15b0

Browse files
authored
Disable abbreviations on internal parser. (#477)
1 parent b4ece52 commit e8a15b0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pydantic_settings/sources.py

+1
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ def __init__(
11651165
description=None if settings_cls.__doc__ is None else dedent(settings_cls.__doc__),
11661166
formatter_class=formatter_class,
11671167
prefix_chars=self.cli_flag_prefix_char,
1168+
allow_abbrev=False,
11681169
)
11691170
if root_parser is None
11701171
else root_parser

tests/test_source_cli.py

+14
Original file line numberDiff line numberDiff line change
@@ -2223,3 +2223,17 @@ class SettingsInvalidReqCircleReqField(BaseModel):
22232223

22242224
with pytest.raises(ValueError, match='mutually exclusive arguments must be optional'):
22252225
CliApp.run(SettingsInvalidReqCircleReqField)
2226+
2227+
2228+
def test_cli_invalid_abbrev():
2229+
class MySettings(BaseSettings):
2230+
bacon: str = ''
2231+
badger: str = ''
2232+
2233+
with pytest.raises(
2234+
SettingsError,
2235+
match='error parsing CLI: unrecognized arguments: --bac cli abbrev are invalid for internal parser',
2236+
):
2237+
CliApp.run(
2238+
MySettings, cli_args=['--bac', 'cli abbrev are invalid for internal parser'], cli_exit_on_error=False
2239+
)

0 commit comments

Comments
 (0)