Skip to content

Commit

Permalink
ConsoleTools improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Jan 3, 2024
1 parent 7d3fd2e commit c6c5918
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/BitzArt.ConsoleTools/BitzArt.ConsoleTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
<PackageId>BitzArt.ConsoleTools</PackageId>
<Authors>BitzArt</Authors>
<Description>A library to help implement Console Tools</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/BitzArt/Miscellaneous</RepositoryUrl>
<PackageProjectUrl>https://github.com/BitzArt/Miscellaneous</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="True" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>
Expand All @@ -22,5 +28,4 @@
<_Parameter1>BitzArt.ConsoleTools.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions src/BitzArt.ConsoleTools/Extensions/RunConsoleToolExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Extensions.DependencyInjection;

namespace BitzArt.ConsoleTools;

public static class RunConsoleToolExtension
{
public static void RunConsoleTool<TConsoleTool>(this IServiceProvider serviceProvider)
where TConsoleTool : IConsoleTool
{
var tool = serviceProvider.GetRequiredService<TConsoleTool>();

tool.Run();
}

public static void RunConsoleTool(this IServiceProvider serviceProvider, Type type)
{
if (!type.IsAssignableTo(typeof(IConsoleTool))) throw new ArgumentException($"Type must implement {nameof(IConsoleTool)} interface", nameof(type));

var tool = (IConsoleTool)serviceProvider.GetRequiredService(type);

tool.Run();
}
}
2 changes: 2 additions & 0 deletions src/BitzArt.ConsoleTools/Models/ConsoleRecurrentToolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public override void RunTool()
{
while (true)
{
Console.Clear();

ConsoleEx.WriteMenu(FullMenu);

var key = Console.ReadKey(true).Key;
Expand Down
6 changes: 6 additions & 0 deletions src/BitzArt.ConsoleTools/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# BitzArt.ConsoleTools

[![NuGet](https://img.shields.io/nuget/v/BitzArt.ConsoleTools.svg)](https://www.nuget.org/packages/BitzArt.ConsoleTools/)
[![NuGet](https://img.shields.io/nuget/dt/BitzArt.ConsoleTools.svg)](https://www.nuget.org/packages/BitzArt.ConsoleTools/)

Handy tools for .NET Core console applications.

0 comments on commit c6c5918

Please sign in to comment.