Skip to content

Commit 16e6fa8

Browse files
authored
Merge branch 'main' into feat/lazy-load-support
2 parents e20fd55 + 11c6db2 commit 16e6fa8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pydantic_settings/sources/providers/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def _resolve_parsed_args(self, parsed_args: dict[str, list[str] | str]) -> list[
548548
parsed_args[field_name] = self._merge_parsed_list(val, field_name)
549549
elif field_name.endswith(':subcommand') and val is not None:
550550
selected_subcommands.append(self._parser_map[field_name][val].dest)
551-
elif self.cli_kebab_case == 'all':
551+
elif self.cli_kebab_case == 'all' and isinstance(val, str):
552552
snake_val = val.replace('-', '_')
553553
cli_arg = self._parser_map.get(field_name, {}).get(None)
554554
if (

tests/test_source_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,22 @@ class SettingsAll(BaseSettings):
27052705
CliApp.run(SettingsAll, cli_args=['--example', 'example_a', '--mybool=true'])
27062706

27072707

2708+
def test_cli_kebab_case_all_with_implicit_flag():
2709+
class Settings(BaseSettings):
2710+
model_config = SettingsConfigDict(cli_kebab_case='all')
2711+
test_bool_flag: CliImplicitFlag[bool]
2712+
2713+
assert CliApp.run(
2714+
Settings,
2715+
cli_args=['--test-bool-flag'],
2716+
).model_dump() == {'test_bool_flag': True}
2717+
2718+
assert CliApp.run(
2719+
Settings,
2720+
cli_args=['--no-test-bool-flag'],
2721+
).model_dump() == {'test_bool_flag': False}
2722+
2723+
27082724
def test_cli_with_unbalanced_brackets_in_json_string():
27092725
class StrToStrDictOptions(BaseSettings):
27102726
nested: dict[str, str]

0 commit comments

Comments
 (0)