Skip to content

Commit 11c6db2

Browse files
Digity101hramezani
andauthored
Bugfix for cli_kebab_case="all" and CliImplicitFlag[bool] (#702)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
1 parent 41f3413 commit 11c6db2

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
@@ -546,7 +546,7 @@ def _resolve_parsed_args(self, parsed_args: dict[str, list[str] | str]) -> list[
546546
parsed_args[field_name] = self._merge_parsed_list(val, field_name)
547547
elif field_name.endswith(':subcommand') and val is not None:
548548
selected_subcommands.append(self._parser_map[field_name][val].dest)
549-
elif self.cli_kebab_case == 'all':
549+
elif self.cli_kebab_case == 'all' and isinstance(val, str):
550550
snake_val = val.replace('-', '_')
551551
cli_arg = self._parser_map.get(field_name, {}).get(None)
552552
if (

tests/test_source_cli.py

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

27052705

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

0 commit comments

Comments
 (0)