Skip to content

Commit ff0ce27

Browse files
committed
feat: Extend ConfigManager to support environment and CLI overrides
Adds new functionality which automatically gets, overrides or sets a config value intelligently based on the situation. See function docstring for details. This makes it possible to effortlessly and reliably implement environment variable overrides for settings anywhere in Comfy-CLI.
1 parent 6fa2fa6 commit ff0ce27

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

comfy_cli/config_manager.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ def get(self, key):
4343
"""
4444
return self.config["DEFAULT"].get(key, None) # Returns None if the key does not exist
4545

46+
def get_or_override(self, env_key: str, config_key: str, set_value: Optional[str] = None) -> Optional[str]:
47+
"""
48+
Resolves and conditionally stores a config value.
49+
50+
The selected value and action is determined by the following priority:
51+
52+
1. Use CLI-provided `--set-*` value (if not None), and save it to config via `set()`.
53+
2. Use process environment variable if exists (empty strings are allowed).
54+
3. Otherwise, use the current config value via `get()`.
55+
56+
Returns None if the selected value is an empty string.
57+
"""
58+
59+
if set_value is not None:
60+
self.set(config_key, set_value)
61+
return set_value or None
62+
elif env_key in os.environ:
63+
return os.environ[env_key] or None
64+
else:
65+
return self.get(config_key) or None
66+
4667
def load(self):
4768
config_file_path = self.get_config_file_path()
4869
if os.path.exists(config_file_path):

0 commit comments

Comments
 (0)