I feel subprocess might be dummy, looking for better approche.
My current code is
def load_azd_env_values(env_name=None):
command = ["azd", "env", "get-values"]
if env_name:
command.extend(["--environment", env_name])
try:
result = subprocess.run(command, capture_output=True, text=True, check=True)
# Print the result to debug
# print("Command output:", result.stdout)
if not result.stdout.strip():
raise ValueError("The command returned no output.")
env_values = {}
for line in result.stdout.strip().split('n'):
if '=' in line:
key, value = line.split('=', 1)
env_values[key] = value.strip('"')
else:
raise ValueError(f"Invalid line in output: {line}")
for key, value in env_values.items():
os.environ[key] = value
return env_values