From 4ab9af6e47cd8ddf1f94c678e7afefea65b00331 Mon Sep 17 00:00:00 2001 From: FeedClogger Date: Tue, 20 Jan 2026 10:18:42 +0100 Subject: [PATCH] Added .env variable override through --config param --- strix/config/config.py | 8 ++++++++ strix/interface/main.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/strix/config/config.py b/strix/config/config.py index 4c67e4a..08057cd 100644 --- a/strix/config/config.py +++ b/strix/config/config.py @@ -163,6 +163,14 @@ class Config: return cls.save({"env": merged}) + @classmethod + def override(cls, key: str, value: str) -> None: + """Override a configuration variable dynamically.""" + if hasattr(cls, key): + setattr(cls, key, value) + else: + os.environ[key] = value + def apply_saved_config() -> dict[str, str]: return Config.apply_saved() diff --git a/strix/interface/main.py b/strix/interface/main.py index e2c89b8..3b36e59 100644 --- a/strix/interface/main.py +++ b/strix/interface/main.py @@ -5,6 +5,7 @@ Strix Agent Interface import argparse import asyncio +import json import logging import shutil import sys @@ -356,6 +357,12 @@ Examples: ), ) + parser.add_argument( + "--config", + type=str, + help="Path to the configuration file (.json)", + ) + args = parser.parse_args() if args.instruction and args.instruction_file: @@ -500,12 +507,30 @@ def pull_docker_image() -> None: console.print() +def load_config_file(config_path: str): + if config_path.endswith(".json"): + try: + with open(config_path, "r", encoding="utf-8") as f: + config_data = json.load(f) + for key, value in config_data.items(): + Config.override(key, str(value)) # Use Config class to override variables + except (json.JSONDecodeError, OSError) as e: + print(f"Error loading JSON config file: {e}") + sys.exit(1) + else: + print("Unsupported config file format. Use .json.") + sys.exit(1) + + def main() -> None: if sys.platform == "win32": asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) args = parse_arguments() + if args.config: + load_config_file(args.config) + check_docker_installed() pull_docker_image()