Skip to content

Commit

Permalink
AsyncCommandBase & auto syntax & .NET 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviuz committed Jul 28, 2024
1 parent 5e3ad7f commit 956d9b2
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 46 deletions.
16 changes: 13 additions & 3 deletions source/ECF.AutoFac/.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>EasyConsoleFramework.AutoFac</id>
<version>0.2.1</version>
<version>0.2.2</version>
<description>Easy Console Framewok - Framework for building command based IoC console application. This package is using AutoFac library for IoC.</description>
<authors>Aviuz</authors>
<tags>console IoC ecf autofac</tags>
Expand All @@ -18,16 +18,22 @@

<dependencies>
<group targetFramework="net6">
<dependency id="EasyConsoleFramework.Base" version="0.2.0" />
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Autofac" version="6.5.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="6.0.0" />
</group>

<group targetFramework="net7">
<dependency id="EasyConsoleFramework.Base" version="0.2.0" />
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Autofac" version="6.5.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="7.0.0" />
</group>

<group targetFramework="net8">
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Autofac" version="6.5.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="8.0.0" />
</group>
</dependencies>
</metadata>

Expand All @@ -41,5 +47,9 @@
<file src="bin\Release\net7.0\ECF.Autofac.dll" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.Autofac.pdb" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.Autofac.deps.json" target="lib\net7.0" />

<file src="bin\Release\net8.0\ECF.Autofac.dll" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.Autofac.pdb" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.Autofac.deps.json" target="lib\net8.0" />
</files>
</package>
9 changes: 7 additions & 2 deletions source/ECF.AutoFac/ECF.AutoFac.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.2.0</Version>
<Version>0.2.2</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand All @@ -17,6 +17,11 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Autofac" Version="6.5.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ECF\ECF.csproj" />
</ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions source/ECF.Microsoft.DependencyInjection/.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>ECF</id>
<version>0.2.1</version>
<version>0.2.2</version>
<description>Easy Console Framewok - Framework for building command based IoC console application. This package is using Microsoft.Extensions.DependencyInjection library for IoC</description>
<authors>Aviuz</authors>
<tags>console IoC ecf DependencyInjection</tags>
Expand All @@ -18,16 +18,22 @@

<dependencies>
<group targetFramework="net6">
<dependency id="EasyConsoleFramework.Base" version="0.2.0" />
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="6.0.1" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="6.0.0" />
</group>

<group targetFramework="net7">
<dependency id="EasyConsoleFramework.Base" version="0.2.0" />
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="7.0.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="7.0.0" />
</group>

<group targetFramework="net8">
<dependency id="EasyConsoleFramework.Base" version="0.2.2" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="8.0.0" />
<dependency id="Microsoft.Extensions.Configuration.Json" version="8.0.0" />
</group>
</dependencies>
</metadata>

Expand All @@ -41,5 +47,9 @@
<file src="bin\Release\net7.0\ECF.dll" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.pdb" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.deps.json" target="lib\net7.0" />

<file src="bin\Release\net8.0\ECF.dll" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.pdb" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.deps.json" target="lib\net8.0" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.2.0</Version>
<Version>0.2.2</Version>
<AssemblyName>ECF</AssemblyName>
<RootNamespace>ECF</RootNamespace>
</PropertyGroup>
Expand All @@ -18,6 +18,11 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ECF\ECF.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion source/ECF.Templates/ECFTemplates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<Version>0.2.0</Version>
<Version>0.2.2</Version>
<PackageId>ECFTemplates</PackageId>
<Title>ECF Templates</Title>
<Authors>Aviuz</Authors>
Expand Down
4 changes: 2 additions & 2 deletions source/ECF.Templates/templates/ECF.Autofac/NewProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyConsoleFramework.Autofac" Version="0.2.1" />
<PackageReference Include="EasyConsoleFramework.Autofac" Version="0.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions source/ECF.Templates/templates/ECF/NewProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ECF" Version="0.2.1" />
<PackageReference Include="ECF" Version="0.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion source/ECF/.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>EasyConsoleFramework.Base</id>
<version>0.2.0</version>
<version>0.2.2</version>
<description>Easy Console Framewok - Framework for building command based IoC console application. This package is base library without any IoC dependency.</description>
<authors>Aviuz</authors>
<tags>console IoC ecf</tags>
Expand All @@ -24,6 +24,10 @@
<group targetFramework="net7">
<dependency id="Microsoft.Extensions.Configuration.Json" version="7.0.0" />
</group>

<group targetFramework="net8">
<dependency id="Microsoft.Extensions.Configuration.Json" version="8.0.0" />
</group>
</dependencies>
</metadata>

Expand All @@ -37,5 +41,9 @@
<file src="bin\Release\net7.0\ECF.Base.dll" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.Base.pdb" target="lib\net7.0" />
<file src="bin\Release\net7.0\ECF.Base.deps.json" target="lib\net7.0" />

<file src="bin\Release\net8.0\ECF.Base.dll" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.Base.pdb" target="lib\net8.0" />
<file src="bin\Release\net8.0\ECF.Base.deps.json" target="lib\net8.0" />
</files>
</package>
8 changes: 8 additions & 0 deletions source/ECF/AsyncCommandBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ECF;

public abstract class AsyncCommandBase : CommandBase
{
public override sealed void Execute() => ExecuteAsync().Wait();

public abstract Task ExecuteAsync();
}
6 changes: 6 additions & 0 deletions source/ECF/CommandArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ public class CommandArguments
{
public string CommandName { get; set; }
public string[] Arguments { get; set; }

public CommandArguments(string commandName, string[] arguments)
{
CommandName = commandName;
Arguments = arguments;
}
}
}
25 changes: 19 additions & 6 deletions source/ECF/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public virtual void ApplyArguments(CommandArguments args)

public virtual string GetHelp()
{
var commandAttribute = GetType().GetCustomAttributes()
.Select(attr => attr as ICommandAttribute)
.Where(attr => attr != null)
.Cast<ICommandAttribute>()
.First();
ICommandAttribute commandAttribute = GetCommandAttribute();
string usageParameters = GetSyntaxExpression();
string description = GetDescription();
string parametersHelp = GetParametersHelp();
Expand Down Expand Up @@ -130,9 +126,26 @@ public bool IsFlagActive(string key)
return values.BoolValues[key];
}

private ICommandAttribute GetCommandAttribute()
{
return GetType().GetCustomAttributes()
.Select(attr => attr as ICommandAttribute)
.Where(attr => attr != null)
.Cast<ICommandAttribute>()
.First();
}

private string GetSyntaxExpression()
{
return GetType().GetCustomAttribute<CmdSyntaxAttribute>()?.SyntaxExpression ?? string.Empty;
string? customSyntax = GetType().GetCustomAttribute<CmdSyntaxAttribute>()?.SyntaxExpression;
if (customSyntax != null) return customSyntax; // for developer specified syntax

var strParts = parameters
.OrderBy(x => x.GetOrder())
.Select(x => x.GetSyntaxToken())
.Where(x => x != null);

return string.Join(" ", strParts);
}

private string GetDescription()
Expand Down
4 changes: 4 additions & 0 deletions source/ECF/CommandBaseComponents/CommandArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ public void AppendHelp(StringBuilder sb)
}

public string SectionName() => "Arguments";

public int GetOrder() => attribute.Index;

public string GetSyntaxToken() => $"<{attribute.Name}>";
}
}
6 changes: 6 additions & 0 deletions source/ECF/CommandBaseComponents/CommandFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ public void AppendHelp(StringBuilder sb)
}

public string SectionName() => "Flags";

public int GetOrder() => int.MaxValue;

public string GetSyntaxToken() => !string.IsNullOrWhiteSpace(attribute.LongName)
? "--" + attribute.LongName
: "-" + attribute.ShortName;
}
}
12 changes: 12 additions & 0 deletions source/ECF/CommandBaseComponents/CommandParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,17 @@ public void AppendHelp(StringBuilder sb)
}

public string SectionName() => "Parameters";

public int GetOrder() => int.MaxValue - 1;

public string? GetSyntaxToken()
{
if(!string.IsNullOrEmpty(attribute.LongName))
return $"--{attribute.LongName} <value>";
else if(string.IsNullOrEmpty(attribute.ShortName))
return $"-{attribute.ShortName} <value>";
else
return null;
}
}
}
5 changes: 5 additions & 0 deletions source/ECF/CommandBaseComponents/ICommandBaseParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ namespace ECF.CommandBaseComponents
{
internal interface ICommandBaseParameter
{
// command execution
bool TryMatch(ArgumentIterator visitor);
void Apply(ArgumentIterator visitor, ValueDictionary valueDictionary);

// help generation
void AppendHelp(StringBuilder sb);
string SectionName();
int GetOrder();
string? GetSyntaxToken();
}
}
12 changes: 8 additions & 4 deletions source/ECF/CommandBaseComponents/PropertyArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace ECF.CommandBaseComponents
{
internal class PropertyArgument : ICommandBaseParameter
{
private readonly CommandBase command;
private readonly object parent;
private readonly PropertyInfo propertyInfo;
private readonly ArgumentAttribute attribute;

public PropertyArgument(CommandBase command, PropertyInfo propertyInfo, ArgumentAttribute attribute)
public PropertyArgument(object parent, PropertyInfo propertyInfo, ArgumentAttribute attribute)
{
this.command = command;
this.parent = parent;
this.propertyInfo = propertyInfo;
this.attribute = attribute;
}
Expand All @@ -32,7 +32,7 @@ public bool TryMatch(ArgumentIterator visitor)

public void Apply(ArgumentIterator visitor, ValueDictionary valueDictionary)
{
propertyInfo.SetValue(command, Convert.ChangeType(visitor.Take(false), propertyInfo.PropertyType));
propertyInfo.SetValue(parent, Convert.ChangeType(visitor.Take(false), propertyInfo.PropertyType));
}

public void AppendHelp(StringBuilder sb)
Expand All @@ -49,5 +49,9 @@ public void AppendHelp(StringBuilder sb)
}

public string SectionName() => "Arguments";

public int GetOrder() => attribute.Index;

public string GetSyntaxToken() => $"<{attribute.Name}>";
}
}
Loading

0 comments on commit 956d9b2

Please sign in to comment.