Skip to content

Commit 3a2b7b4

Browse files
mrochhramezani
andauthored
turn off allow_abbrev on subparsers (#658)
Co-authored-by: Hasan Ramezani <[email protected]>
1 parent 284f88e commit 3a2b7b4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pydantic_settings/sources/providers/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ def _add_parser_args(
747747
help=subcommand_help,
748748
formatter_class=self._formatter_class,
749749
description=None if model.__doc__ is None else dedent(model.__doc__),
750+
allow_abbrev=False,
750751
),
751752
model=model,
752753
added_args=[],

tests/test_source_cli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,25 @@ class MySettings(BaseSettings):
23782378
)
23792379

23802380

2381+
def test_cli_subcommand_invalid_abbrev():
2382+
class Child(BaseModel):
2383+
bacon: str = ''
2384+
badger: str = ''
2385+
2386+
class MySettings(BaseSettings):
2387+
child: CliSubCommand[Child]
2388+
2389+
with pytest.raises(
2390+
SettingsError,
2391+
match='error parsing CLI: unrecognized arguments: --bac cli abbrev are invalid for internal parser',
2392+
):
2393+
CliApp.run(
2394+
MySettings,
2395+
cli_args=['child', '--bac', 'cli abbrev are invalid for internal parser'],
2396+
cli_exit_on_error=False,
2397+
)
2398+
2399+
23812400
def test_cli_submodels_strip_annotated():
23822401
class PolyA(BaseModel):
23832402
a: int = 1

0 commit comments

Comments
 (0)