aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-27 06:38:39 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-27 06:38:39 -0500
commit742c8c8a77d28eccda886f0e6ca15d4a05a3cf4d (patch)
tree0b7cb4d34aa4a5b9809e503f221062bfa5c95bbb /src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
parent48d569da0e86f1ec0144713c25cad3a5e767c4d2 (diff)
parent2e04802345be5d887e53351dafc13830f38a9cd7 (diff)
downloadslskd-742c8c8a77d28eccda886f0e6ca15d4a05a3cf4d.tar.gz
Merge branch 'lists' of https://github.com/slskd/slskd into lists
Diffstat (limited to 'src/slskd/Common/Configuration/CommandLineConfigurationSource.cs')
-rw-r--r--src/slskd/Common/Configuration/CommandLineConfigurationSource.cs38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
index b49b2232..d338eef6 100644
--- a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
+++ b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
@@ -18,6 +18,7 @@
namespace slskd.Configuration
{
using System;
+ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Configuration;
@@ -116,14 +117,41 @@ namespace slskd.Configuration
{
if (dictionary.ContainsKey(argument))
{
- var value = dictionary[argument].ToString();
-
- if (property.PropertyType == typeof(bool) && string.IsNullOrEmpty(value))
+ // if the backing type is an array, it supports multiple values.
+ if (property.PropertyType.IsArray)
{
- value = "true";
+ var value = dictionary[argument];
+
+ // Parse() will stuff multiple values into a List<T> if the argument name is
+ // in the list of those supporting multiple values, and more than one value was supplied.
+ // detect this, and add the values to the target.
+ if (value.GetType().IsGenericType)
+ {
+ var elements = (List<object>)dictionary[argument];
+
+ for (int i = 0; i < elements.Count; i++)
+ {
+ Data[ConfigurationPath.Combine(key, i.ToString())] = elements[i].ToString();
+ }
+ }
+ else
+ {
+ // there may have only been one value supplied, in which case the value is just a
+ // string. stick it in index 0 of the target.
+ Data[ConfigurationPath.Combine(key, "0")] = value.ToString();
+ }
}
+ else
+ {
+ var value = dictionary[argument].ToString();
- Data[key] = value;
+ if (property.PropertyType == typeof(bool) && string.IsNullOrEmpty(value))
+ {
+ value = "true";
+ }
+
+ Data[key] = value;
+ }
}
}
}