diff options
author | vnugent <public@vaughnnugent.com> | 2024-05-07 17:01:22 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-05-07 17:01:22 -0400 |
commit | 79d824cfb0e0cc9ff4fab0e0c546a83c0edaae1c (patch) | |
tree | d69e962a15493b2e36882810a2cc43d5a0de1a0b /src/Model/TaskfileVars.cs | |
parent | b3015399591bd81b8519f0efa2ec177163f7d04a (diff) |
initial commit
Diffstat (limited to 'src/Model/TaskfileVars.cs')
-rw-r--r-- | src/Model/TaskfileVars.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Model/TaskfileVars.cs b/src/Model/TaskfileVars.cs new file mode 100644 index 0000000..c0e6cdc --- /dev/null +++ b/src/Model/TaskfileVars.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; + +namespace VNLib.Tools.Build.Executor.Model +{ + /// <summary> + /// Represents a collection of taskfile "environment" variables + /// </summary> + public sealed class TaskfileVars + { + private readonly Dictionary<string, string> vars; + + public TaskfileVars() + { + vars = new(StringComparer.OrdinalIgnoreCase); + } + + private TaskfileVars(IEnumerable<KeyValuePair<string, string>> values) + { + vars = new(values, StringComparer.OrdinalIgnoreCase); + } + + /// <summary> + /// Gets all variables as a readonly dictionary + /// </summary> + /// <returns>The collection of environment variables</returns> + public IReadOnlyDictionary<string, string> GetVariables() => vars; + + /// <summary> + /// Sets a taskfile environment variable + /// </summary> + /// <param name="key">The variable name</param> + /// <param name="value">The optional variable value</param> + public void Set(string key, string? value) => vars[key] = value ?? string.Empty; + + /// <summary> + /// Removes a taskfile environment variable + /// </summary> + /// <param name="key">The name of the variable to remove</param> + public void Remove(string key) => vars.Remove(key); + + /// <summary> + /// Clones the current taskfile variables into an independent instance + /// </summary> + /// <returns>The new <see cref="TaskfileVars"/> instance</returns> + public TaskfileVars Clone() => new (vars); + } +}
\ No newline at end of file |