Skip to content

Commit b8bb58e

Browse files
committed
fix cli_kebab_case=all with implicit flags
1 parent 5008c69 commit b8bb58e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pydantic_settings/sources/providers/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ def _resolve_parsed_args(self, parsed_args: dict[str, list[str] | str]) -> list[
549549
elif field_name.endswith(':subcommand') and val is not None:
550550
selected_subcommands.append(self._parser_map[field_name][val].dest)
551551
elif self.cli_kebab_case == 'all':
552+
if isinstance(val, bool):
553+
continue
552554
snake_val = val.replace('-', '_')
553555
cli_arg = self._parser_map.get(field_name, {}).get(None)
554556
if (

tests/test_source_cli.py

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

26242624

2625+
def test_cli_kebab_case_all_with_implicit_flag():
2626+
class Settings(BaseSettings):
2627+
model_config = SettingsConfigDict(cli_kebab_case='all')
2628+
test_bool_flag: CliImplicitFlag[bool]
2629+
2630+
assert CliApp.run(
2631+
Settings,
2632+
cli_args=['--test-bool-flag'],
2633+
).model_dump() == {'test_bool_flag': True}
2634+
2635+
assert CliApp.run(
2636+
Settings,
2637+
cli_args=['--no-test-bool-flag'],
2638+
).model_dump() == {'test_bool_flag': False}
2639+
2640+
26252641
def test_cli_with_unbalanced_brackets_in_json_string():
26262642
class StrToStrDictOptions(BaseSettings):
26272643
nested: dict[str, str]

0 commit comments

Comments
 (0)