Skip to content

Commit 8343156

Browse files
committed
update to Net5
1 parent 882773f commit 8343156

File tree

8 files changed

+94
-7
lines changed

8 files changed

+94
-7
lines changed

AutofacCommandLine/AutofacCommandLine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<AssemblyName>J4JSoftware.CommandLine.Autofac</AssemblyName>
77
<RootNamespace>J4JSoftware.CommandLine</RootNamespace>

FancyConsole/FancyConsole.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<AssemblyName>J4JSoftware.CommandLine.FancyConsole</AssemblyName>
77
<RootNamespace>J4JSoftware.CommandLine</RootNamespace>

J4JCommandLine.Tests/J4JCommandLine.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<IsPackable>false</IsPackable>
77
<Version>0.1.0.0</Version>

J4JCommandLine/J4JCommandLine.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<AssemblyName>J4JSoftware.CommandLine</AssemblyName>
77
<RootNamespace>J4JSoftware.CommandLine</RootNamespace>
@@ -28,6 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
3132
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.5" />
3233
</ItemGroup>
3334

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Configuration;
7+
8+
namespace J4JSoftware.CommandLine
9+
{
10+
public static class ConfigurationExtensions
11+
{
12+
public static J4JConfigurationSource AddMapping(
13+
this J4JConfigurationSource src,
14+
string optionKey,
15+
string configKey )
16+
{
17+
var option = src.BindingTarget
18+
.Options
19+
.FirstOrDefault( x => x.Keys.Any(
20+
k => k.Equals( optionKey, StringComparison.OrdinalIgnoreCase ) ) );
21+
22+
if( option == null )
23+
return src;
24+
25+
if( src.ConfigurationMap.ContainsKey( optionKey ) )
26+
src.ConfigurationMap[ optionKey ] = configKey;
27+
else src.ConfigurationMap.Add( optionKey, configKey );
28+
29+
return src;
30+
}
31+
32+
public static J4JConfigurationSource UsingArguments( this J4JConfigurationSource src, string[] args )
33+
{
34+
src.Arguments = args;
35+
36+
return src;
37+
}
38+
39+
public class J4JConfigurationSource : IConfigurationSource
40+
{
41+
private string[]? _args;
42+
43+
public J4JConfigurationSource( IBindingTarget bindingTgt )
44+
{
45+
BindingTarget = bindingTgt;
46+
}
47+
48+
public IBindingTarget BindingTarget { get; }
49+
internal Dictionary<string, string> ConfigurationMap { get; } = new Dictionary<string, string>();
50+
51+
public string[] Arguments
52+
{
53+
get => _args ?? Environment.GetCommandLineArgs();
54+
internal set => _args = value;
55+
}
56+
57+
public IConfigurationProvider Build( IConfigurationBuilder builder )
58+
{
59+
return new J4JConfigurationProvider( this );
60+
}
61+
}
62+
63+
public class J4JConfigurationProvider : ConfigurationProvider
64+
{
65+
public J4JConfigurationProvider( J4JConfigurationSource source )
66+
{
67+
Source = source;
68+
}
69+
70+
public J4JConfigurationSource Source { get; }
71+
72+
public override void Load()
73+
{
74+
var allocations = Source.BindingTarget.AllocateCommandLineArguments( Source.Arguments );
75+
76+
foreach( var option in Source.BindingTarget.Options )
77+
{
78+
foreach( var key in option.Keys )
79+
{
80+
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}

examples/AutoBindExample/AutoBindExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<RootNamespace>J4JSoftware.CommandLine.Examples</RootNamespace>
88
<Version>0.1.0.0</Version>

examples/InstancePropertyExample/InstancePropertyExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<RootNamespace>J4JSoftware.CommandLine.Examples</RootNamespace>
77
<Version>0.1.0.0</Version>

examples/StaticPropertyExample/StaticPropertyExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<RootNamespace>J4JSoftware.CommandLine.Examples</RootNamespace>
88
<Version>0.1.0.0</Version>

0 commit comments

Comments
 (0)