Skip to content

Commit

Permalink
Initialize CLI source on demand. (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
kschwab authored Jun 8, 2024
1 parent 39d5e81 commit 813ac94
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions pydantic_settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,6 @@ def _settings_build_values(

# Configure built-in sources
init_settings = InitSettingsSource(self.__class__, init_kwargs=init_kwargs)
cli_settings = (
CliSettingsSource(
self.__class__,
cli_prog_name=cli_prog_name,
cli_parse_args=cli_parse_args,
cli_parse_none_str=cli_parse_none_str,
cli_hide_none_type=cli_hide_none_type,
cli_avoid_json=cli_avoid_json,
cli_enforce_required=cli_enforce_required,
cli_use_class_docs_for_groups=cli_use_class_docs_for_groups,
cli_prefix=cli_prefix,
case_sensitive=case_sensitive,
)
if cli_settings_source is None
else cli_settings_source
)
env_settings = EnvSettingsSource(
self.__class__,
case_sensitive=case_sensitive,
Expand Down Expand Up @@ -305,7 +289,23 @@ def _settings_build_values(
file_secret_settings=file_secret_settings,
)
if not any([source for source in sources if isinstance(source, CliSettingsSource)]):
if cli_parse_args or cli_settings_source:
if cli_parse_args is not None or cli_settings_source is not None:
cli_settings = (
CliSettingsSource(
self.__class__,
cli_prog_name=cli_prog_name,
cli_parse_args=cli_parse_args,
cli_parse_none_str=cli_parse_none_str,
cli_hide_none_type=cli_hide_none_type,
cli_avoid_json=cli_avoid_json,
cli_enforce_required=cli_enforce_required,
cli_use_class_docs_for_groups=cli_use_class_docs_for_groups,
cli_prefix=cli_prefix,
case_sensitive=case_sensitive,
)
if cli_settings_source is None
else cli_settings_source
)
sources = (cli_settings,) + sources
if sources:
return deep_update(*reversed([source() for source in sources]))
Expand Down

0 comments on commit 813ac94

Please sign in to comment.