// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System; using System.Threading; namespace Progmasoft.Tazel.Dsl.Environment; /// /// The values of tazel_envs.txt, beside the MODULE.csx of the module the project file belongs to. A value is not /// an environment variable: it reaches no shell, no program Tazel runs and not Tazel itself; only this class reads it. /// public static class GetEnvironment { /// The value named , or null when tazel_envs.txt has no such name. public static string? From(string name) { ArgumentNullException.ThrowIfNull(name); return EnvironmentValues.Current?.Get(name); } } /// Where the values of the running project file come from; Tazel sets it while the file runs. internal interface IEnvironmentValues { string? Get(string name); } /// The values of the project file that is running. internal static class EnvironmentValues { private static readonly AsyncLocal CurrentValues = new(); public static IEnvironmentValues? Current => CurrentValues.Value; /// Makes those of the running file until the result is disposed. public static IDisposable Enter(IEnvironmentValues? values) { var previous = CurrentValues.Value; CurrentValues.Value = values; return new Restore(() => CurrentValues.Value = previous); } private sealed class Restore(Action undo) : IDisposable { public void Dispose() => undo(); } }