diff --git a/pydantic_settings/sources/providers/cli.py b/pydantic_settings/sources/providers/cli.py index 7f05ce43..39c0e91e 100644 --- a/pydantic_settings/sources/providers/cli.py +++ b/pydantic_settings/sources/providers/cli.py @@ -546,7 +546,7 @@ def _resolve_parsed_args(self, parsed_args: dict[str, list[str] | str]) -> list[ parsed_args[field_name] = self._merge_parsed_list(val, field_name) elif field_name.endswith(':subcommand') and val is not None: selected_subcommands.append(self._parser_map[field_name][val].dest) - elif self.cli_kebab_case == 'all': + elif self.cli_kebab_case == 'all' and isinstance(val, str): snake_val = val.replace('-', '_') cli_arg = self._parser_map.get(field_name, {}).get(None) if ( diff --git a/tests/test_source_cli.py b/tests/test_source_cli.py index 65c9a672..42518ec8 100644 --- a/tests/test_source_cli.py +++ b/tests/test_source_cli.py @@ -2703,6 +2703,22 @@ class SettingsAll(BaseSettings): CliApp.run(SettingsAll, cli_args=['--example', 'example_a', '--mybool=true']) +def test_cli_kebab_case_all_with_implicit_flag(): + class Settings(BaseSettings): + model_config = SettingsConfigDict(cli_kebab_case='all') + test_bool_flag: CliImplicitFlag[bool] + + assert CliApp.run( + Settings, + cli_args=['--test-bool-flag'], + ).model_dump() == {'test_bool_flag': True} + + assert CliApp.run( + Settings, + cli_args=['--no-test-bool-flag'], + ).model_dump() == {'test_bool_flag': False} + + def test_cli_with_unbalanced_brackets_in_json_string(): class StrToStrDictOptions(BaseSettings): nested: dict[str, str]