aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-26 22:58:41 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-26 22:58:41 -0500
commita0842636429bcecf87a2302ca8ebb685c77f8514 (patch)
tree7e570bf09f96794c85cb13e441d6f1cbb36f30d8 /src
parentc5804abb31bd74f26101ad28acdd5c12273d2a8f (diff)
downloadslskd-a0842636429bcecf87a2302ca8ebb685c77f8514.tar.gz
handle multiple values
Diffstat (limited to 'src')
-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;
+ }
}
}
}