Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pydantic_settings/sources/providers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ def _resolve_parsed_args(self, parsed_args: dict[str, list[str] | str]) -> list[
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':
if isinstance(val, bool):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making it specific to bool, can you update to exclude above on str. e.g.

elif self.cli_kebab_case == 'all' and isinstance(val, str):

All of the logic in this case assumes val is str. Thanks for the catch 👍🏾

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change is indeed better. When I wrote the bug fix, I didn't pay much attention to possible types of val and took the easy way out.

continue
snake_val = val.replace('-', '_')
cli_arg = self._parser_map.get(field_name, {}).get(None)
if (
Expand Down
16 changes: 16 additions & 0 deletions tests/test_source_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,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]
Expand Down