Added .env variable override through --config param
This commit is contained in:
@@ -163,6 +163,14 @@ class Config:
|
|||||||
|
|
||||||
return cls.save({"env": merged})
|
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]:
|
def apply_saved_config() -> dict[str, str]:
|
||||||
return Config.apply_saved()
|
return Config.apply_saved()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Strix Agent Interface
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
@@ -356,6 +357,12 @@ Examples:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--config",
|
||||||
|
type=str,
|
||||||
|
help="Path to the configuration file (.json)",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.instruction and args.instruction_file:
|
if args.instruction and args.instruction_file:
|
||||||
@@ -500,12 +507,30 @@ def pull_docker_image() -> None:
|
|||||||
console.print()
|
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:
|
def main() -> None:
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
|
|
||||||
args = parse_arguments()
|
args = parse_arguments()
|
||||||
|
|
||||||
|
if args.config:
|
||||||
|
load_config_file(args.config)
|
||||||
|
|
||||||
check_docker_installed()
|
check_docker_installed()
|
||||||
pull_docker_image()
|
pull_docker_image()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user