aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-26 20:05:59 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-26 20:05:59 -0500
commit22e4e494b0baeb1983057f0b89dd03f97dfcdfc0 (patch)
tree73f6408111f6449471c1e4fc8b30a357c0bfd524 /src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
parent2c7a7268a748fac3b676a31e99964f9f0979f0f5 (diff)
downloadslskd-22e4e494b0baeb1983057f0b89dd03f97dfcdfc0.tar.gz
add support for MultiValuedArguments
Diffstat (limited to 'src/slskd/Common/Configuration/CommandLineConfigurationSource.cs')
-rw-r--r--src/slskd/Common/Configuration/CommandLineConfigurationSource.cs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
index 115a5be3..b49b2232 100644
--- a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
+++ b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
@@ -33,9 +33,10 @@ namespace slskd.Configuration
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to which to add.</param>
/// <param name="targetType">The type from which to map properties.</param>
+ /// <param name="multiValuedArguments">An array of argument names which can be specified with multiple values.</param>
/// <param name="commandLine">The command line string from which to parse arguments.</param>
/// <returns>The updated <see cref="IConfigurationBuilder"/>.</returns>
- public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, Type targetType, string commandLine = null)
+ public static IConfigurationBuilder AddCommandLine(this IConfigurationBuilder builder, Type targetType, string[] multiValuedArguments = null, string commandLine = null)
{
if (builder == null)
{
@@ -51,6 +52,7 @@ namespace slskd.Configuration
{
s.TargetType = targetType;
s.CommandLine = commandLine ?? Environment.CommandLine;
+ s.MultiValuedArguments = multiValuedArguments;
});
}
@@ -78,11 +80,13 @@ namespace slskd.Configuration
TargetType = source.TargetType;
Namespace = TargetType.Namespace.Split('.').First();
CommandLine = source.CommandLine;
+ MultiValuedArguments = source.MultiValuedArguments;
}
private string CommandLine { get; set; }
private string Namespace { get; set; }
private Type TargetType { get; set; }
+ private string[] MultiValuedArguments { get; set; }
/// <summary>
/// Parses command line arguments from the specified string and maps them to the corresponding keys.
@@ -90,7 +94,7 @@ namespace slskd.Configuration
public override void Load()
{
Console.WriteLine(CommandLine);
- var dictionary = Arguments.Parse(CommandLine, TargetType).ArgumentDictionary;
+ var dictionary = Arguments.Parse(CommandLine, options => options.CombinableArguments = MultiValuedArguments).ArgumentDictionary;
Console.WriteLine(dictionary.ToJson());
void Map(Type type, string path)
@@ -150,6 +154,11 @@ namespace slskd.Configuration
public Type TargetType { get; set; }
/// <summary>
+ /// Gets or sets an array of argument names which can be specified with multiple values.
+ /// </summary>
+ public string[] MultiValuedArguments { get; set; } = Array.Empty<string>();
+
+ /// <summary>
/// Builds the <see cref="CommandLineConfigurationProvider"/> for this source.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>