Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ExistForAll.SimpleSettings;
using ExistForAll.SimpleSettings.Binders;

namespace ExistAll.SimpleConfig.Binders
namespace ExistsForAll.SimpleSettings.Binders
{
public class CommandLineConfigBinder : ISectionBinder
public class CommandLineSettingsBinder : ISectionBinder
{
private readonly CommandLineConfigBinderOptions _options;
private readonly CommandLineSettingsBinderOptions _options;
private readonly Dictionary<string, string> _argumentStore;

public CommandLineConfigBinder(string[] args, CommandLineConfigBinderOptions options)
public CommandLineSettingsBinder(string[] args, CommandLineSettingsBinderOptions options)
{
if (args == null) throw new ArgumentNullException(nameof(args));
_options = options ?? throw new ArgumentNullException(nameof(options));
Expand All @@ -22,7 +24,7 @@ public CommandLineConfigBinder(string[] args, CommandLineConfigBinderOptions opt
Parse(args);
}

public void BindPropertyConfig(BindingContext context)
public void BindPropertySettings(BindingContext context)
{
var key = _options.NameFormatter != null ? _options.NameFormatter(context.Section, context.Key) : context.Key;

Expand Down Expand Up @@ -51,7 +53,7 @@ private void Parse(string[] args)
}
}

private static Tuple<string, string> SplitByDelimiter(string str, CommandLineConfigBinderOptions options)
private static Tuple<string, string> SplitByDelimiter(string str, CommandLineSettingsBinderOptions options)
{
if (str == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using ExistAll.SimpleConfig.Binder;
using ExistForAll.SimpleSettings.Binder;

namespace ExistAll.SimpleConfig.Binders
namespace ExistForAll.SimpleSettings.Binders
{
public class CommandLineConfigBinderOptions
public class CommandLineSettingsBinderOptions
{
private readonly List<char> _argumentPrefixes = new List<char>(new[] {'-', '/'});
private readonly List<string> _delimiters = new List<string>(new[] {":", "="});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using ExistForAll.SimpleSettings.Binder;

namespace ExistForAll.SimpleSettings.Binders
{
public static class CommandLineSettingsBinderOptionsExtensions
{
public static CommandLineSettingsBinderOptions AddPrefix(this CommandLineSettingsBinderOptions options, char prefix)
{
options.AddArgumentPrefix(prefix);

return options;
}

public static CommandLineSettingsBinderOptions AddNewDelimiter(this CommandLineSettingsBinderOptions options,
string delimiter)
{
options.AddDelimiter(delimiter);

return options;
}

public static CommandLineSettingsBinderOptions SetCaseSensitivity(this CommandLineSettingsBinderOptions options,
bool isCaseSensitive)
{
options.IsCaseSensitive = isCaseSensitive;

return options;
}

public static CommandLineSettingsBinderOptions SetNameFormatter(this CommandLineSettingsBinderOptions options,
NameFormatter nameFormatter)
{
options.NameFormatter = nameFormatter;

return options;
}

public static CommandLineSettingsBinderOptions ClearAllPrefixes(this CommandLineSettingsBinderOptions options,
NameFormatter nameFormatter)
{
options.ClearArgumentPrefixes();

return options;
}

public static CommandLineSettingsBinderOptions ClearAllDelimiters(this CommandLineSettingsBinderOptions options)
{
options.ClearDelimiters();

return options;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration;

namespace ExistAll.SimpleConfig.Binders
namespace ExistForAll.SimpleSettings.Binders
{
public class ConfigurationBinder : ISectionBinder
{
Expand All @@ -22,7 +22,7 @@ private string GetSection(BindingContext context)
return $"{RootSection}:{context.Section}";
}

public void BindPropertyConfig(BindingContext context)
public void BindPropertySettings(BindingContext context)
{
var configurationSection = _configuration.GetSection(GetSection(context));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections;
using System.Text;

namespace ExistAll.SimpleConfig.Binders
namespace ExistForAll.SimpleSettings.Binders
{
public class EnvironmentVariableBinder : ISectionBinder
{
Expand All @@ -22,7 +22,7 @@ public EnvironmentVariableBinder()
_environmentVariables = Environment.GetEnvironmentVariables();
}

public void BindPropertyConfig(BindingContext context)
public void BindPropertySettings(BindingContext context)
{
var sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace ExistAll.SimpleConfig.Binders
namespace ExistForAll.SimpleSettings.Binders
{
public class EnvironmentVariableBinderOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

<PropertyGroup>
<OutputTypeEx>library</OutputTypeEx>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>ExistsForAll.SimpleSettings.Binders</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExistAll.SimpleConfig\ExistAll.SimpleConfig.csproj" />
<ProjectReference Include="..\ExistForAll.SimpleSettings\ExistForAll.SimpleSettings.csproj" />
</ItemGroup>

<Import Project="../../version.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using System;
using ExistsForAll.SimpleSettings.Binders;
using Microsoft.Extensions.Configuration;

namespace ExistAll.SimpleConfig.Binders
namespace ExistForAll.SimpleSettings.Binders
{
public static class ConfigBuilderFactoryExtensions
public static class SettingsBuilderFactoryExtensions
{
public static T AddConfiguration<T>(this T target, IConfiguration configuration) where T : IConfigBuilderFactory
public static T AddConfiguration<T>(this T target, IConfiguration configuration) where T : ISettingsBuilderFactory
{

target.AddSectionBinder(new ConfigurationBinder(configuration));

return target;
}

public static T AddEnvironmentVariable<T>(this T target) where T : IConfigBuilderFactory
public static T AddEnvironmentVariable<T>(this T target) where T : ISettingsBuilderFactory
{
target.AddSectionBinder(new EnvironmentVariableBinder());

return target;
}

public static T AddEnvironmentVariable<T>(this T target,
Action<EnvironmentVariableBinderOptions> action) where T : IConfigBuilderFactory
Action<EnvironmentVariableBinderOptions> action) where T : ISettingsBuilderFactory
{
var options = new EnvironmentVariableBinderOptions();
action(options);
Expand All @@ -38,7 +40,7 @@ public static T AddEnvironmentVariable<T>(this T target,
}

public static T AddCommandLine<T>(this T target,
Action<CommandLineConfigBinderOptions> action = null) where T : IConfigBuilderFactory
Action<CommandLineSettingsBinderOptions> action = null) where T : ISettingsBuilderFactory
{
var args = Environment.CommandLine.Trim().Split(' ');

Expand All @@ -49,12 +51,12 @@ public static T AddCommandLine<T>(this T target,

public static T AddArguments<T>(this T target,
string[] args
, Action<CommandLineConfigBinderOptions> action = null) where T : IConfigBuilderFactory
, Action<CommandLineSettingsBinderOptions> action = null) where T : ISettingsBuilderFactory
{
var options = new CommandLineConfigBinderOptions();
var options = new CommandLineSettingsBinderOptions();
action?.Invoke(options);

target.AddSectionBinder(new CommandLineConfigBinder(args, options));
target.AddSectionBinder(new CommandLineSettingsBinder(args, options));

return target;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading