From 22e4e494b0baeb1983057f0b89dd03f97dfcdfc0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 Jul 2021 20:05:59 -0500 Subject: add support for MultiValuedArguments --- .../Common/Configuration/CommandLineConfigurationSource.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') 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 /// /// The to which to add. /// The type from which to map properties. + /// An array of argument names which can be specified with multiple values. /// The command line string from which to parse arguments. /// The updated . - 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; } /// /// 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) @@ -149,6 +153,11 @@ namespace slskd.Configuration /// public Type TargetType { get; set; } + /// + /// Gets or sets an array of argument names which can be specified with multiple values. + /// + public string[] MultiValuedArguments { get; set; } = Array.Empty(); + /// /// Builds the for this source. /// -- cgit v1.2.3