Making plugin system more robust

This commit is contained in:
2024-06-30 13:59:40 +02:00
parent f329b00687
commit c220c214d2
10 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
namespace MycroForge.Plugin.Template;
public static class Constants
{
public const string MainCommandName = "mj";
}

View File

@@ -0,0 +1,25 @@
using System.CommandLine;
using MycroForge.Core;
using MycroForge.Core.Contract;
using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.Plugin.Template;
public class HelloWorldCommand : Command, ISubCommandOf<RootCommand>
{
private readonly ProjectContext _context;
public HelloWorldCommand(ProjectContext context) :
base(Constants.MainCommandName, "Custom command for My Jewellery specific stuff")
{
_context = context;
this.SetHandler(ExecuteAsync);
}
private async Task ExecuteAsync()
{
await _context.CreateFile("hello_world.txt",
"My Jewellery command plugin is working!"
);
}
}

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using MycroForge.Core.Contract;
using RootCommand = MycroForge.Core.RootCommand;
namespace MycroForge.Plugin.Template;
public class HelloWorldCommandPlugin : ICommandPlugin
{
public string Name => "MycroForge.Plugin.Template";
public string Command => Constants.MainCommandName;
public void RegisterServices(IServiceCollection services)
{
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MycroForge.Core" Version="1.0.0" />
</ItemGroup>
</Project>