From e9108aa3e747cd5798a4768e7cf9c5aa65d53395 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 23 Jan 2021 13:40:07 -0600 Subject: move Configuration --- .../CommandLineArgumentConfigurationSource.cs | 93 ---------------------- 1 file changed, 93 deletions(-) delete mode 100644 src/slskd/Common/CommandLineArgumentConfigurationSource.cs (limited to 'src/slskd/Common/CommandLineArgumentConfigurationSource.cs') diff --git a/src/slskd/Common/CommandLineArgumentConfigurationSource.cs b/src/slskd/Common/CommandLineArgumentConfigurationSource.cs deleted file mode 100644 index 1762228d..00000000 --- a/src/slskd/Common/CommandLineArgumentConfigurationSource.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace slskd -{ - using Microsoft.Extensions.Configuration; - using System; - using System.Collections.Generic; - using System.Linq; - using Utility.CommandLine; - - public class Argument - { - public string Description { get; set; } - public char ShortName { get; set; } - public string LongName { get; set; } - public string Key { get; set; } - } - - public static class CommandLineArgumentExtensions - { - public static IConfigurationBuilder MapCommandLineArguments(this IConfigurationBuilder builder, IEnumerable map, string commandLine) - { - if (builder == null) - { - throw new ArgumentNullException(nameof(builder)); - } - - return builder.MapCommandLineArguments(s => - { - s.Map = map; - s.CommandLine = commandLine; - }); - } - - public static IConfigurationBuilder MapCommandLineArguments(this IConfigurationBuilder builder, Action configureSource) - => builder.Add(configureSource); - } - - public class CommandLineArgumentConfigurationSource : IConfigurationSource - { - public IEnumerable Map { get; set; } - public string CommandLine { get; set; } - - public IConfigurationProvider Build(IConfigurationBuilder builder) - { - return new CommandLineArgumentConfigurationProvider(this); - } - } - - public class CommandLineArgumentConfigurationProvider : ConfigurationProvider - { - public CommandLineArgumentConfigurationSource Source { get; set; } - - /// - /// Initializes a new instance with the specified source. - /// - /// The source settings. - public CommandLineArgumentConfigurationProvider(CommandLineArgumentConfigurationSource source) - { - Source = source; - } - - public override void Load() - { - var dictionary = Arguments.Parse(Source.CommandLine).ArgumentDictionary; - - foreach (var item in Source.Map) - { - Console.WriteLine($"Item: {item.Key}"); - - if (string.IsNullOrEmpty(item.Key)) - { - continue; - } - - var arguments = new[] { item.ShortName.ToString(), item.LongName }.Where(i => !string.IsNullOrEmpty(i)); - - foreach (var argument in arguments) - { - if (dictionary.ContainsKey(argument)) - { - var value = dictionary[argument].ToString(); - - if (string.IsNullOrEmpty(value)) - { - value = "true"; - } - - Data[item.Key] = value; - } - } - } - } - } -} -- cgit v1.2.3