aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-27 08:53:18 -0500
committerGitHub <noreply@github.com>2021-07-27 08:53:18 -0500
commit69d29c1eaa03992cf786d1d9b1ec1935dd85ef42 (patch)
tree5253fcd096de96c3bf8c1cd3a9af0f303f4cb41f /src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
parent58bc401dab5d7eb3bc6cb07a22e0ee9c97ddf4bd (diff)
parentc5a23135f01697e5fb234988a314be57c9e245d5 (diff)
downloadslskd-69d29c1eaa03992cf786d1d9b1ec1935dd85ef42.tar.gz
Merge pull request #130 from slskd/lists
Accept option lists via command line and environment variables
Diffstat (limited to 'src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs')
-rw-r--r--src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
index 9a09d4e1..6d2896c2 100644
--- a/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
+++ b/src/slskd/Common/Configuration/EnvironmentVariableConfigurationSource.cs
@@ -100,15 +100,32 @@ namespace slskd.Configuration
if (attribute != default)
{
+ // retrieve the envar name from the attribute
var name = (string)attribute.ConstructorArguments[0].Value;
if (!string.IsNullOrEmpty(name))
{
+ // retrieve the corresponding value from environment variables
var value = Environment.GetEnvironmentVariable(Prefix + name);
if (value != null)
{
- Data[key] = value.ToString();
+ // if the type of the backing property is an array,
+ // split the retrieved value by semicolon and add the parts to
+ // config as zero-based children of the prop
+ if (property.PropertyType.IsArray)
+ {
+ var elements = value.Split(';');
+
+ for (int i = 0; i < elements.Length; i++)
+ {
+ Data[ConfigurationPath.Combine(key, i.ToString())] = elements[i];
+ }
+ }
+ else
+ {
+ Data[key] = value.ToString();
+ }
}
}
}